Created
October 21, 2014 18:01
-
-
Save dummied/d7c2badb5566eda5bc78 to your computer and use it in GitHub Desktop.
Example controller action to ping Google Analytics on a direct file download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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