ShortStat Beta

Update

A new version of ShortStat is now available.

Until recently I’ve been completely satisfied using Reinvigorate’s Data Archiving Services to keep track of referrers and daily hits. DAS was ideal for previous versions of this site (basically one page loading content into an iframe): add a link to an external javascript file to the homepage and almost all traffic coming into the site gets recorded. But with the transition to Moveable Type comes the possibility of readers bypassing the front door and going straight to the content. So DAS no longer cuts it.

Now I’m sure there are hundreds of free, robust PHP/MySQL stats packages out there but what do I do? I decide to roll my own (check out /shortstat/ off of root for a sample)—with all that free time I have. The code is coarse but it gets the job done and covers some bases that even DAS misses:

  • keeps a running total of referrals from individual domains
  • recognizes that all IE 5s are not created equal—and that there never was a Netscape 5
  • records the number of hits individual resources receive
  • mosty importantly, is coded from scratch so I can add more functionality as desired

On the off chance that this meager solution appeals to somebody else, I’ve zipped it up with simple instructions for use and an installer for the single database table required. It is provided strictly on an as is basis. You are soley responsible and liable for any damage you do to your website or server. Okay, it’s really not that scary but I had to say it.

Download ShortStat v0.2b.

Note

Adding ShortStat code to a custom 404 page tracks missing resources but does not make any distinction between a 404 and an existing resource. This can be useful if you watch your resources closely and can recognize potential 404s. Otherwise it just pollutes your numbers. I hope to work out a fix for this soon.

Another Note

It’s been brought to my attention that accessing ShortStat from shortstat.yourdomain.com instead of yourdomain.com/shortstat/ will result in yourdomain.com appearing excessively in your list of referrers. ShortStat should not display your domain at all in either list of referrers. I made the incorrect assumption that $_SERVER["HTTP_HOST"] would contain the main domain minus the subdomain.This will be addressed in the next release. To correct it in the current version just open functions.php and change $_SERVER["HTTP_HOST"] to $_SERVER["SERVER_NAME"] on lines 242 and 266.

Previous
Blue Collar Update
Next
Mad Scientist
Author
Shaun Inman
Posted
March 6th, 2004 at 8:34 am
Categories
PHP
ShortStat
Comments
024 (Now closed)

024 Comments

001

I have installed ShortStat on my server . Works great!

Would be more useful for me if can track the countries or search engine keywords.

Thank you Inman!

Author
sk
Posted
Mar 6th, 2004 5:48 am
002

I’ll have to look into figuring out country info but the search engine keywords is a great idea and should be pretty easy to implement. A future version of ShortStat will probably use a couple of database tables to cut down on redundancy in the main table. Thanks for the feedback SK.

Author
Shaun Inman
Posted
Mar 6th, 2004 6:48 am
003

This is just what I’ve been looking for - particularly one that breaks down browser usage properly. My current site stats just do one big ‘Netscape 5.0’!

Thanks Shaun, I’m off to install this little beauty!

Author
Jon HIcks
Posted
Mar 6th, 2004 9:20 am
004

…Well that was painless! I’m a very happy chap.

Author
Jon Hicks
Posted
Mar 6th, 2004 9:41 am
005

Great script Shaun!

I can’t wait to see what comes of it!

Author
Michael Simmons
Posted
Mar 6th, 2004 9:49 am
006

i second the idea to show search keywords

great job though, painless to install, and it actually looks nice

Author
ak
Posted
Mar 6th, 2004 10:13 am
007

hi shaun, i’ve installed your short stat, its only working when i actually go into the inc.stats file right now -but i’ll figure it out

great job :D

Author
Steven
Posted
Mar 6th, 2004 11:12 am
008

The inc.stat.php (and any files that it is included in) must be included using a relative path (as opposed to the full domain with \"http://\"). Otherwise, your server and not the visitor’s browser is the requesting user agent and referrer. That’s why trackme.php and the installation instructions use $_SERVER[\"DOCUMENT_ROOT\"] to include inc.stats.php.

Could this be causing the problem you described Steven?

Author
Shaun Inman
Posted
Mar 6th, 2004 11:17 am
009

Thank you for this great script!

Could you use $db[\"server\"] instead of $db[server] (and of course all other arrays), because i get a lot of errors, when i don’t change it.

To clean up your code, you can add the following lines to your code: ERROR_REPORTING(E_ALL); ini_set(\"display_errors\",\"1\");

Again, thanks for this great script.

Author
Danilo
Posted
Mar 6th, 2004 11:53 am
010

Oh, btw: preg_match is faster than eregi. :

if (preg_match("/mac/i", $ua)) {
    $browser["platform"] = "Macintosh";
    }
Author
Danilo
Posted
Mar 6th, 2004 11:57 am
011

Thanks Shaun, its working sweetly now…

again you have my praise :D

Author
Steven
Posted
Mar 6th, 2004 12:18 pm
012

Sorry to be the annoying one, but php is not my forte. I have set up a new database, have a working username and password… but the install can’t access my database. I have checked my username, password, and database name a thousand times. They are correct. I can access the database directly through my browser (through PHPMyAdmin). So, I can only assume that my server name is wrong. I have tried “localhost” and also the subdomain I have created “example.jasonsantamaria.com”. No dice. Is anyone else on Dreamhost out there? I guess I am too busy rolling around naked in my piles of graphic designer money with many groupies (what can I say, girls still go wild for the Bauhaus movement) to learn more about this PHP tomfoolery. Regardless, once again Shaun, have some more smoke up your ass, this thing looks slick.

Author
Jason Santa Maria
Posted
Mar 6th, 2004 4:21 pm
013

Wow!! Great piece of program…thankx for the opportunity.

I’m addicted. I’ll make my daily visits here…to enjoy, be educated. :)

Author
Arthur J. Bahadourian
Posted
Mar 6th, 2004 5:11 pm
014

Hi Jason,

I am with dreamhost (though the server I mentioned in my first post is not dreamhost, but I have installed ShortStat on my other dreamhost site), for the server name, it should be your mysql subdomain, (eg, mysql.yourdomain.com). Hope this will help.

By the way, I am addicted monitoring my ShortStat. Cool to see some spider/crawler around my site.

Thanks again, Shaun!

Author
sk
Posted
Mar 6th, 2004 5:25 pm
015

Jason, you can keep the smoke—but how ‘bout sharing the wealth?

If SK’s suggestion doesn’t work and you have access to your phpMyAdmin config.inc.php file look for $cfgServers[1]['host'] (around line 40). Your $db[server] value should have the same value. If neither are successful I don’t know what to try. My PHP/MySQL experience has been rather sheltered. I’ve had all of two hosts who both had the same set-up as far as I can tell. Sorry, I can’t offer more.

Danilo, my associative arrays will be quoted in the next release. SK & AK, keywords are partially done. Which search engines should I accomodate? They all use different query string variable names. So far I’ve added support for Google (all international flavors) and Yahoo. MSN? AOL probably, huh?

Author
Shaun Inman
Posted
Mar 6th, 2004 5:45 pm
016

Wow, just a day old, new features will be added. Great job, Shaun!

Personally, I ‘ll be happy with just Google and Yahoo. But the more the merrier, can track what other search engines used by other folks.

Author
sk
Posted
Mar 7th, 2004 6:04 am
017

The addition of new features is easy enough as is a brand new installer. The difficulty lies in creating an updater for people who currently have v0.2b installed. I’ve worked out the country tracking code but it requires an additional 1.7MB ip-to-country lookup table that can be a real pain to install depending on your host’s set-up so I’m going to make it an optional feature.

Author
Shaun Inman
Posted
Mar 7th, 2004 6:46 am
018

Shaun-

This is great! Took me about five minutes to install, and it works beautifully. Love it!

Thanks!

Author
Jeff Croft
Posted
Mar 7th, 2004 2:13 pm
019

Hey SK, would you have time to email me and hold my hand for a moment with this? Since you are on Dreamhost as well…

frustrated@jasonsantamaria.com

Author
Jason Santa Maria
Posted
Mar 7th, 2004 2:50 pm
020

Not to be picky, but I was just thinking it would be nice to see the hits from the past five days or so.

I’ve also been watching the progress on your site and it looks sweet!

Author
Michael Simmons
Posted
Mar 7th, 2004 6:41 pm
021

That’s not being picky, I want something like that too. I was thinking about breaking out each days stats individually but I haven’t figured out a MySQL query that does it elegantly enough yet. Expect that in a future version.

Author
Shaun Inman
Posted
Mar 8th, 2004 9:35 am
022

I released ShortStat Beta 3 this morning which incorporates many of the early requests made in this thread (sorry Michael - no daily breakdowns yet).

Author
Shaun Inman
Posted
Mar 10th, 2004 4:17 am
023

I’m known as quite lazy. I’d always been planning on making my own stats program (a much more simple one), but never got around to doing it. Thanks Shaun, I’ll install this as soon as some problems on my server are fixed…

Author
Hans
Posted
Jun 21st, 2004 7:25 am
024

I can’t seem to get my shortstat to install. The database is not created when I call the _install.php file from my browser. I’ve looked through the comments, but I can’t seem to find a reference to this problem. Has this problem already been addressed?

Author
Kirk
Posted
Feb 24th, 2005 2:59 am