How to track pageviews in a view

Is there a plugin for this or a gem that I can use. I thought just writing it to the table when a view is called in the controller. Is this the best way? I see that stackoverflow has this functionality, how do they do it?

+7
ruby ruby-on-rails
source share
3 answers

Google Analytics - let Google or some other third-party analytics provider do this for you for free. I don’t think you want to record files every time you load a page - potentially expensive. Another option is to store information in memory and periodically write to the database, and not on every page load.

[EDIT] This is an interesting question. I asked for help on this issue , which is more efficient - writes db vs file write - there are good reviews there.

+9
source share

If you just wanted to get something there, you could use a real-time analytics tool, such as a W3 counter

It gives you real-time data (unlike Google Analytics) and is relatively easy to deploy (a few lines in your global template), but it may not give you the granularity you want. I think it depends on whether you want to display / use this information programmatically in the application or for statistical purposes.

+2
source share

Obviously, there are third-party statistics services (Google Analytics, Mint, etc.), but if you have to do it yourself, then recording every time someone lands on the page will seriously affect your database.

I would write individual hits of the intermediate file in the file system or memcached, and then run a task every 10-15 minutes, which will analyze this data and insert it into the database.

+1
source share

All Articles