Skip to content

Instantly share code, notes, and snippets.

@dummied
Created October 21, 2014 18:01
Show Gist options
  • Select an option

  • Save dummied/d7c2badb5566eda5bc78 to your computer and use it in GitHub Desktop.

Select an option

Save dummied/d7c2badb5566eda5bc78 to your computer and use it in GitHub Desktop.
Example controller action to ping Google Analytics on a direct file download
require "uri"
require "net/http"
def download
tracking_params =
{
v: 1,
t: 'event',
ec: 'testing',
el: 'direct',
ea: 'download',
tid: GA_TRACKING_ID,
uip: request.fullpath,
dr: request.headers["HTTP_REFERER"],
cid: request.uuid,
dl: request.original_url,
ua: request.headers["User-Agent"]
}
x = Net::HTTP.post_form(URI.parse('http://www.google-analytics.com/collect'), tracking_params)
send_file PATH_TO_FILE
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment