Search code examples
jqueryruby-on-railsamazon-s3amazon-cloudfront

How do I track file download count?


I'm trying to track when a user downloads a .zip file from my Rails site. The file is hosted by S3/Cloudfront. If the HTML is something like:

<a href="http://something.cloudfront.net/path/to/file.zip">Download File</a>

I could attach a JQuery event that will send a GET request to my server that will increment the downloads column in my database. However, if the user goes to the URL directly, the download will occur but it will not be tracked.

Is there a solution?


Solution

  • Yudong's answer is the only one which would work by just providing a download link, but Amazon states that they log on a "best effort" basis and it's by no means accurate accounting. I think the simplest way would do a redirect and count the redirects and the most accurate would be to stream the zip file yourself through your server (would not really make a huge difference if hosted on Amazon as well unless you have a lot of traffic and huge files). Another way would be to use a CDN which gives you accurate access logs. Your Jquery idea is as good as the redirect.