Moving Average Hit Counter

(a tipjar net toy)

dev log

October 12, 2012:
Now displaying (instead of just endlessly refreshing) for browsers that do not accept the cookie, which, since it gets set in an iframe, doesn't pop up a cookie acceptance dialog in at least one cookie filtering system I was shown yesterday. What this cookie is for, is, it prevents multiple hits within five minutes of each other, from the same browser, from getting counted. Only one hit allowed per browser per page per five minutes. That makes TJMAHC a superior hit counter! Tell your friends.

February 2009:
After a somewhat rough migration to a new web server, took weeks to figure out why the daily script wasn't working, thus creating a "day" with over five hundred hours in it. It will take a while for this big bump in the data to even out, in the meanwhile everyone gets to appear as if they had a lot of traffic.

4 Aug 2008:
Now using a simple lock to keep the two counters on this page from both updating from the same fetch

18 July 2008:
Now displaying how far through "Today" we are, in hours.tenths (so sue me -- sprintf doesn't have a letter for ancient Sumerian)

29 June 2008:
now tracking user-agent strings as well as hits. Aggregate info available here per-page data will be made available on request.

3 September 2007:
wrote script to facilitate merging two counters while transitioning
to explicit page markers -- contact me directly if you need your counters merged

15 February 2007:
link multiple pages with ?page= attribute (view source for example)

31 January 2007:
normalized away "www." at beginning of domain names

2 January 2007:
removed off-by-one in moving average
unified counter and vcounter scripts
fixed rounding to hundredths
more robust duplicate-hit removal
normalized out final slashes

18 December 2006:
fixed the moving average code so it actually works (sorry)


The TJMAHC is a hit counter suitable for placement in an iframe that does moving average calculations instead of simply counting raw hits eternally towards infinity, which is what most hit counters do, and which this one does too. The moving averages are updated daily.

Columns in the table include T for today's hits so far, Y for yesterdays hits, and 7, 30, 90 and 360 day moving averages. "days" is how many days hits are included in the averages, sort of like "uptime" for a web page, and "total" is the sum of the raw hits, not counting today's.

Please feel free to install the TJMAHC in your web page by following the example available from viewing the source code of this page.

in short, paste this into your web page:

<iframe  align="middle" height="90" width="250"

Alternately, a vertical version is available:

<iframe  align="middle" height="200" width="100"
the counter program identifies your page by using the HTTP_REFERER CGI variable, or add ?page=(URL of your page) to the source of the iframe to link together counters on several pages or on a page that has multiple ways to view it. (for instance if the same page appears in multiple places on your site, with different URLs, you can choose one.)

a cookie is set to the current time, to eliminate multiple recordings of hits from one web browser: Continuously reloading a TJMAHC-displaying web page with a cookie-enabled web browser will only log an additional hit every five minutes.

This remotelyhosted hit counter is registered with the CGI Resource Index.

Rate this Script @ The CGI Resource Index!
Script Rating:

copyright 2006,2007 tipjar LLC all rights reserved