Improving ShortStat

Tonight I played with Shaun Inman's nice stats generator named ShortStat. I immediately loved the way it looks but concluded that I couldn't use it because Pivot doesn't allow you to include external PHP code in all pages. But I wanted ShortStat!
Nice, but what do we do if we either cannot include PHP or if the page is a HTML page instead of a php page?
Tackling the problem
Let's take a look.
First of all you can download my version of shortstat 0.36b HERE
I eliminated the need for a PHP include by creating a dummy script that outputs a 1x1 pixel GIF file. It would be called with something like:
It seemed nice at first. However this posed a new problem: Gone was the referrer information. In order to get it back I decided to feed the fake-gif-presenting PHP file the info it needs. Now all that was left to do was call it properly. Since javascript can pass both the referer and the originating page I achieved my goal. Shortstat can now be used on any page, it can run from a completely different webserver and therefore even do stats for sites that don't have PHP installed at all.
How to use my version of ShortStat
Step 1 is simple: install it and follow Shaun's instructions. except for including the PHP stuff in your templates. There's no need for this anymore. Instead, edit the following two files:
- stat.php
- stat.js
Step 2 is to add the following to your templates, html pages, asp scripts or whatever else you want to track:
Of course the path should be reflecting your situation once again.
You're done now! You've got Shaun Inman's ShortStat without the need for PHP includes.
Look mommy, No spam!
As an added bonus this version of ShortStat is virtually spam-proof too. In order to invoke stat tracking some javascript needs to execute. Spam bots usually just perform a simple GET operation on one or more of your pages which won't execute the javascript. Therefore: referrer spam attempts will fail!
I hope this is useful to some. It is to me!
Filed under: web development
Number of comments:
Number of trackbacks:
Tagged with: 







At 06 April '05 - 10:55 Simon wrote:
At 06 April '05 - 11:00 Marco wrote:
At 06 April '05 - 13:19 Simon wrote:
At 06 April '05 - 19:09 Wim wrote:
At 06 April '05 - 19:11 Wim wrote:
At 06 April '05 - 20:05 Marco wrote:
I realize you’ll lose a couple of visitors but in total your stats are much more accurate this way since both referrer spammers and visits by bots that can falsely inflate your stats are ignored. I personally rather have this small loss instead of all the meaningless hits in my stats! :)
At 07 April '05 - 17:38 Bram wrote:
It seems the script doesn’t know when a day actually ends and I’m not the only one with the problem
At 07 April '05 - 19:48 Marco wrote: