# Page hit counter?

**URL:** <https://www.ruby-forum.com/t/page-hit-counter/94806>\
**Category:** Rails\
**Created:** [May 15, 2006, 10:37am UTC](https://www.ruby-forum.com/t/page-hit-counter/94806 "2006-05-15T10:37:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [May 15, 2006, 10:37am UTC](https://www.ruby-forum.com/t/page-hit-counter/94806/1 "2006-05-15T10:37:40Z")

</div>

Hello all,

Yet another “don’t reinvent the wheel” n00b question:

Is there an ‘official’ page hit counter plugin/code snippet/whatever? I  
would need something like this:

- It is possibility to set a constant timespan (say 5 hours).
- On every page hit, save away @request.remote\_ip and Time.new
- The counter gets incremented only if the same IP was here longer ago  
than the constant

Of course this is trivial to do, but just in case there is something  
like this, LMK (i have been googling for it but did not find anything  
relevant - how should i look for such stuff in the future?)

TIA,  
Peter

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [May 15, 2006, 1:32pm UTC](https://www.ruby-forum.com/t/page-hit-counter/94806/2 "2006-05-15T13:32:30Z")

</div>

Peter S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Hello all,
> 
> Yet another “don’t reinvent the wheel” n00b question:
> 
> Is there an ‘official’ page hit counter plugin/code snippet/whatever?

I don’t think so.

But there are many commercial as well as free ones out there. I will  
recommend  
Statcounter [www.statcounter.com](http://www.statcounter.com) (google if link fails).

Put the code in you layout files.

> 

## HTH.

Surendra S.  
[http://ssinghi.kreeti.com](http://ssinghi.kreeti.com), [http://www.kreeti.com](http://www.kreeti.com)  
Read my blog at: [http://cuttingtheredtape.blogspot.com/](http://cuttingtheredtape.blogspot.com/)  
,----  
| Great wits are sure to madness near allied,  
| And thin partitions do their bounds divide.  
|  
| (John Dryden, Absalom and Achitophel, 1681)  
`----

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [May 15, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/page-hit-counter/94806/3 "2006-05-15T19:04:47Z")

</div>

On 15 May 2006, at 13:26, Surendra S. wrote:

> But there are many commercial as well as free ones out there. I  
> will recommend  
> Statcounter [www.statcounter.com](http://www.statcounter.com) (google if link fails).
> 
> Put the code in you layout files.

Or if you want to manage it yourself, use a before\_filter that adds  
it to the database. Plain and simple.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [May 16, 2006, 12:13am UTC](https://www.ruby-forum.com/t/page-hit-counter/94806/4 "2006-05-16T00:13:09Z")

</div>

Apply for a Google Analytics account. It’s way better than anything you  
can build for yourself.

I tried to home-rolled approach, and let me tell you, its  
disappointingly complex. Plus, you need to store thousands of records,  
which will slow your app down.
