page view counter

Hi, Anyone can point me in the right direction... I have a very simple rails app and I want to do a page view counter for it so that I can display how many people have viewed a given page on it since day one and also in the last 24 hours...

I have seen this in some php sites before... I searched a bit but it did not lead me to anything remotely close for a rails app. if anyone has a link to some site where this had been done please share it. I am a newbie btw :frowning:

thanks Señor.

señor tower wrote:

Hi, Anyone can point me in the right direction... I have a very simple rails app and I want to do a page view counter for it so that I can display how many people have viewed a given page on it since day one and also in the last 24 hours...

I have seen this in some php sites before... I searched a bit but it did not lead me to anything remotely close for a rails app. if anyone has a link to some site where this had been done please share it. I am a newbie btw :frowning:

thanks Se�or.

Why not just use Google Analytics?

Best,

umm, I wasn't -still not sure - that google analytics can be used to display public data... But I will see what i find!

I'm relatively new to ruby on rails, but launching the server with -- debug and throwing debugger into an application_controller before_filter, I was able to determine where the URI was stored:

  request.env['REQUEST_URI']

If you could grab this value and throw it into a table and/or increment its counter, you could easily retrieve the count later.

There's probably ActiveRecord magic where you can add it if it is new, otherwise increment the record's count column.

The simplest table to match your listed requirements would be to have URI and date columns as the primary key, then you will have a history of counts on a per day basis including the current day (though no greater granularity for the current day).

Please post if you find a solution.

Mike

señor tower wrote:

umm, I wasn't -still not sure - that google analytics can be used to display public data... But I will see what i find!

You probably shouldn't be displaying your counter anyway...

Best,

Thanks for our unfounded point of view Marnen.

I still would like to know if anyone else has come across anything similar. a simple hit counter... to display some basic metrics. thanks so much.

señor.

Humm... thought I posted something to this thread, but nothing has shown up.

I'm sure you are looking for something more out-of-the-box, but I thought I'd share with you what I just discovered myself should it be useful to you. Disclaimer: I'm a relative newbie to Rails.

After starting the script/server with --debug and calling debugger in an application_controller before_filter, I was able to find the URL within request.env['REQUEST_URI']. If you create a model with URI and date as a unique key, you could create a new URI+date it it doesn't exist and increment a counter each time a page is viewed. It shouldn't take more than an hour to implement (maybe three for me as a newbie :wink:

-- Mike

Hi,

Thanks for our unfounded point of view Marnen.

I still would like to know if anyone else has come across anything similar. a simple hit counter... to display some basic metrics. thanks so much.

We did something on a project I worked on a while back that might be relevant. It was audit functionality but the 'bones' of it were pretty much what you're talking about I think. The basics were to install a before_filter to record the method being invoked. That's close to a page hit counter. You'd probably want to tweak it if you're app includes Ajax renders.

HTH, Bill