# Track views in Rails app

**URL:** <https://www.ruby-forum.com/t/track-views-in-rails-app/236246>\
**Category:** Rails\
**Created:** [August 17, 2013, 11:06pm UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246 "2013-08-17T23:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 17, 2013, 11:06pm UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246/1 "2013-08-17T23:06:14Z")

</div>

Hi

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](https://github.com/charlotte-ruby/impressionist/issues/94)).

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?

---

<div class="post-metadata">

**Author:** ![cnchan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cnchan](https://www.ruby-forum.com/u/cnchan)\
**Post date:** [August 18, 2013, 2:08am UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246/2 "2013-08-18T02:08:28Z")

</div>

On Saturday, August 17, 2013 2:04:51 PM UTC-7, Linus P. wrote:

> 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.

Phil

---

<div class="post-metadata">

**Author:** ![cnchan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cnchan](https://www.ruby-forum.com/u/cnchan)\
**Post date:** [August 18, 2013, 11:14am UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246/3 "2013-08-18T11:14:04Z")

</div>

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.

Linus

Den sndagen den 18:e augusti 2013 kl. 02:07:07 UTC+2 skrev Phil:

---

<div class="post-metadata">

**Author:** ![cnchan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cnchan](https://www.ruby-forum.com/u/cnchan)\
**Post date:** [August 21, 2013, 8:26am UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246/4 "2013-08-21T08:26:04Z")

</div>

Check out FluentD ([http://fluentd.org](http://fluentd.org)). 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.

---

<div class="post-metadata">

**Author:** ![cnchan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cnchan](https://www.ruby-forum.com/u/cnchan)\
**Post date:** [August 18, 2013, 7:55pm UTC](https://www.ruby-forum.com/t/track-views-in-rails-app/236246/5 "2013-08-18T19:55:09Z")

</div>

On Aug 18, 2013, at 4:12 AM, Linus P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Perhaps I need to build something custom to get this.  
> 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.
> 
> To post to this group, send email to [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/rubyonrails-talk/9ab65baa-61b8-49e1-abb3-2c4fca28b1ef%40googlegroups.com](https://groups.google.com/d/msgid/rubyonrails-talk/9ab65baa-61b8-49e1-abb3-2c4fca28b1ef%40googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

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. [Sumologic.com](http://Sumologic.com) 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](https://www.ruby-toolbox.com/categories/Log_Analysis) to see gems folks  
have built to do this.
