Track views in Rails app


Often when I build sites I need some way to track visits to specific pages. For instance I need to see what Artists are the most popular so I can let my users sort based on popularity.

I have used the gem Impressionist before but recently I ran into major performance issues (see Performance issues · Issue #94 · charlotte-ruby/impressionist · GitHub).

I do use Google Analytics and could pull that data somehow I guess, but isn’t that data pretty “slow” (I want the views to update at least in a few minutes)?

So, what do you use to track views in your apps?

FIrst I would say you need to crack the nut of what “popular” means. Simple URL hits may not be your best metric for that. It could mean how long a user dwells on a page, or how many scroll all the way to the bottom, who’s logged in vs. who’s a casual users or an indexing bot, etc.

Assuming “artists” is a table, you could add a simple counter column (maybe with a related “counter_reset_at” column with a timestamp) and increment it when the appropriate criteria is met.

When I first made a popular T-shirt site (I’ll refrain from saying the name here) we used to have a ‘Like’ feature similar to Facebook. We found users would systematically set up new accounts and like themselves and dislike everybody else to try to falsify their ratings. We came up with some simple ways to weed out the bad data.

Hope this helps.


Thanks for your reply.

I have a “like” system (you can only like, not dislike) as well but I also want to track views as another measure of popularity. It doesn’t have to be super exact but would be great if it filtered out bots of course.

I just thought this was a quite common issue and wanted to know how other people solves it.

The features I would like is:

  1. Filter bots.

  2. Count unique requests based on session hash, ip address or similar.

Perhaps I need to build something custom to get this.


Most of the time what I see it people doing analysis based on the server log for page hits, filtering known bots based on IP address and UserAgent string. does this as a service. AWStats is a FOSS tools that does this as well. Piwik seems popular as a FOSS tool. And then there's the 800 pound gorilla, as usual, Google Analytics. Further, you could look at Category: Log Analysis - The Ruby Toolbox to see gems folks have built to do this.

Check out FluentD ( Super easy to set up on an AWS box. Just ping it with a 1x1 pixel from your pages, and you can output the logs to S3/database/whatever.