All threads / What's the best way to track file downloads (stats)?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

What's the best way to track file downloads (stats)?

Anthony M Pizzurro asked in General

Thanks to the videos here, I've implemented file upload with Shrine in my app. They are audio files, stored on s3, and made available to the public.

I'd like to track the downloads and provide my users with some basic statistics. I don't see any out of the box solutions/gems that can get me close.

I've considred:

  • Parsing s3 bucket logs and creating a record in my app's DB
  • Setting up a url redirect, grabbing the request data, and creating a record in my app's DB

Is one of these methods better than the other? Is there a better option?

Thanks!
-Anthony

  • I think parsing the S3 bucket logs could work but it may be hard for you to tell who did what if you want to track who did what.
  • I have done the redirect version of this before for http://feedforward.io/ and it works pretty well. You link to /whatever/1/download and then record the download and then redirect the user to the actual download url. Works pretty well.
  • Another thing you could do is use a JS tracker like Ahoy or Mixpanel, etc where you track it with an AJAX request when the user clicks the download link. This means you don't have to have anything special going on in your app and you can use third party analytics tools like Mixpanel really easily.

I'd probably go with one of the latter options for simplicity.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.