Reducing Analytics Inaccuracy as a Result of Website Development

April 29th, 2010 - Posted by Steve Marks to Javascript / jQuery, SEO, Web Development.

If you’re anything like me and work on a multitude of various websites you’ll have different versions of sites all functioning at the same time; maybe a copy running on your localhost for development, a staging version and the live production site visible to the public.

With an analytics package running on these sites, continuous page hits through testing will most definitely skew the statistics data and give false feedback when analytics reports are generated. This can be especially critical when a client sees 1,000 pageviews a day on their site when, little do they know 990 of them are you developing a new section.

There are two methods I use to prevent this inaccuracy:

Method 1 – IP Address Filtering

Most analytics packages provide the ability to exclude hits from predefined IP addresses. Google Analytics for example has what they call a ‘Filter Manager’. In here we can choose to exclude our localhost IP address ( and our public IP address which can be obtained from a site such as

Google Analytics Filter Manager

Cons: This will only work if you have a static IP address. Also, if you develop from various locations or have multiple developers working on a site you will have to ensure each of these unique IP addresses are included in the filter.

Method 2 – Specifying Domain

The other alternative is to only show the analytics code on the live domain. A simple example of this can be seen below where, by using PHP, I only show the Google Analytics tracking code on the live domain:

<?php if ($_SERVER['HTTP_HOST']=="") { ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-1234567-8");
} catch(err) {}</script>
<?php } ?>

In above example I am only checking against the one domain variant. In order for this to be more efficient you would also want to check against other ways people may access the same site; maybe via IP address or without the ‘www.’.

Cons: As this tracks all visits to the live site it would still count your/the developer’s testing and general browsing hits.

In my opinion I would say the first method is generally preferred, especially if it is only you and/or your team developing a website. As with everything however you should judge each case on it’s merits and find a method that suits you best to reduce inconsistencies in your anaytics data.

This entry was posted on Thursday, April 29th, 2010 at 10:29 pm by +Steve Marks and is filed under Javascript / jQuery, SEO, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments (0)
Comments are closed.