Filtering my own visits from Shortstat
I’ve made a few amendments to the standard installation of Shaun Inman’s Shortstat site tracking system.
One of the problems I had with the basic version was that I didn’t know how many of the hits shown were coming from myself, so I added in functionality to allow IP addresses to be filtered from the list of results.
(This functionality replaces that suggested by Andrew in the original Shortstat’s comments on March 13th, as that prevented any of your own visits from getting into the database at all).
You can see the results on The Watchmaker Project Shortstat page – the form at the top allows you to either filter out my visits, your visits, or both at once.
With Shaun’s blessing, I’ve put all the changes together into a .zip file – download it here. It’s fairly straightforward, just follow the instructions in the READ_ME.txt file to implement the filters on your own implementation of Shortstat.
Aside from adding the form to the index.php page, the core change was to add an extra two lines to each MySQL query in the functions.php page. The first line checked to see if the site owner’s IP address(es) should be excluded; the second did the same for the current viewer’s IP address. If you don’t allow anyone else to access your site stats, you can edit out the second line (or leave it in in case you ever access the page from an internet cafe or similar).
To keep the code simple, I used separate functions for each filter – you can view the PHP code here if you’re interested in how it was done. Each stat-building function checks whether a filter is to be applied, then calls the new functions to add the extra ‘WHERE’ clause(s).
When I have the time, I plan to add some more functionality to this update – a search-engine spider filter would be pretty handy, a crapflooder filter will probably be a must for popular sites, and a way to specify an IP range so those on non-fixed IP addresses can also make use of the filter.
Currently the filters don’t make any difference to the search terms listed as they are stored in a different table from everything else – hopefully this won’t make a great deal of difference, unless you habitually need Google’s help to find your own site!
I hope this is of some use to users of Shaun’s great visitor tracking system – please let me know if any additional functionality would be useful (or if you find any mistakes).
Filed under: Internet, Design.
Bookmark this article with del.icio.us
Previously: Cross-browser testing
Next: Link of the day
Comments
- Matthew Pennell
- 1499 days ago
- That will be up to Shaun when he releases an update to Shortstat.
From some of his comments I would guess that he may be working on updates similar to mine and Janne’s independently, so you may find that his version will incorporate our functionality, if not our actual code. - #3
- Janne Kalliola
- 1498 days ago
- I fixed certain typos in the languages.php for ShortStats. Grab a copy at http://www.nomadig.com/journal/index.php?p=35
- #4
- Stuart
- 1493 days ago
- Thanks for a nice little “add-on” Matthew. I’ve installed it without problem and everything is working just fine but I did spot that you have not included a styles.css mod. in the download. To be frank I came over and copy/pasted the additional styles from your own CSS file but there are those out there who may not think of this or even know how.
- #5
- Matthew Pennell
- 1492 days ago
- Stuart: thanks for spotting that mistake – I’ve now added styles.css to the .zip file.
- #6
- Chris Fenison
- 1433 days ago
- Are you all able to get this to work with the newer update to Shortstat (version .34b)? I am having trouble creating the filter table. When I ran _filter.php it told me there was a problem creating the table. I ignored it and finished the rest of the instructions. Everything seems to work, but no CSS style is applied. I downloaded your newer CSS and uploaded it, but no style is applied.
- #8
- Matthew Pennell
- 1351 days ago
- Hans: it only really works if your IP is fixed. You could hack the code to match a range of IP addresses (assuming yours is always in a certain range, e.g. 10.2.10.xxx), although that would also filter out anyone else on the same line.
- #10
- Nathan Logan
- 1295 days ago
- Hey Matthew,
Thanks for the mod – it’s great! I actually changed it up a bit on my site, such that it automatically removes my added IPs from the stats and doesn’t allow the option to see how many times I’ve loaded my own page (since I’m not ever interested in that statistic).
Anyway, I thought I would point out that if someone wants to keep the add_ip.php functionality, but wants to rename it so that others can’t come and add IPs, the form will break (since it submits to itself). That’s not a huge problem, as most will probably be able to figure it out, but you can also fix it. There are a couple ways to remedy this situation, but the best is to replace the form action (line 32) with a call to the server variable PHP_SELF. That way, when people rename the file, its functionality will remain.
Thanks again for the great idea. I’m trying to figure out the best way to add an IP range. If I figure out something neat, I’ll share it with you.
Adios! - #11
If you?re interested, please obtain the patches and installation instructions from www.nomadig.com/journal/index.php?p=33