Do you want actionable Internet Marketing advice delivered right to your inbox?
Sign up for our Newsletter
Daily    Weekly
Please select captcha
The TechWyse ‘Rise To The Top’ Blog!

Experts from TechWyse and around the world offer how-to's, strategy advice, interviews, infographics and insights to help your SEO and internet marketing campaigns Rise To The Top!

Tricks For Advanced IP Filtering With Google Analytics

Website Analytics April 9th, 2009


image Clean data is what we analytics guys strive for.  In order to keep Google Analytics reporting as clean as possible it is vitally important to filter out visitor data that is not true customer traffic. If you don’t, visitor patterning is severely affected, generally with poorer quality metrics and higher CPA/CPC data.

The types of visit we need to exclude from profiles include site designers, administrators, and regular staff visitors from various locations. The way to do this is to setup IP address filters for visits from these locations. To undertand the basics on IP filtering  I recommend you visit our previous post Setting Up Filters and Profiles in Google Analytics.

In this article I wanted to explain the following:

  • Help you understand more complex IP filtering for those that need to block ranges of IP addresses

  • I also describe how to setup a PHP test page and Google Analytics profile that will help report on any IP address you might have missed so that you can perfect the filter.

Filtering Dynamic IP Address Ranges

Filtering basic IP address is described in the previous article.  If you have multiple locations, however, or if your ISP regularly changes your IP address filters things can be a little more tricky. For a dynamic address you need to contact your ISP to get the range of addresses they use for your account. Then use Google’s range expression creator tool to create the expression you need to filter for. Example: For a range of and single static address of the filter would be:


Here is more information on how to create filter expressions.

Testing the Filter Works in Analytics

In order to see whether your filter is correct for your staff locations, we can send the IP address of visits to an an analytics profile. Here’s how: Please note: This should be used only for  a non-public profile and recording your staff visits, since recording external visitors personal information is against Google’s terms of service.

1) Create a new profile with a separate tracking ID in analytics just to carry out this test. Don’t add the filter yet and just to be clear, leave your live profiles alone until the very end!

2) Create a test.php page on your live site, out of normal public reach. On this page include the analytics code for the test profile but add the line in red. Place it below the call to the tracker. This pulls the IP address of the visitor into the setVar variable so it can be viewed in analytics.

<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-xxxxxxx-x"); pageTracker._trackPageview(); pageTracker._setVar("<?php echo $_SERVER['REMOTE_ADDR']; ?>"); } catch(err) {}</script>

You can also echo the IP address to the page, if you wish, using something similar to the below:

<h1>Thank You!</h1><br /><strong>Your IP Address is <?php echo $_SERVER['REMOTE_ADDR']; ?></strong></br>Your address will be registered in analytics if we have not blocked your visit correctly!

clip_image0013) Now test the page by visiting the test.php page and wait for analytics to report the visit with the IP address.Look in Visits – User Defined. This generally takes a couple of hours.

4) Once you have confirmed that the test.php page is sending missed IP addresses into the user defined field then apply your filter to the NEW profile.

5) Send an e-mail to all locations asking for people to visit the test.php page. Make it clear that they should only visit from the locations you wish to filter for.

6) Wait for the result to come in and then check the profile report. You can see exactly which addresses your filter missed.

7) Modify your filter and and retest.

8. Finally, apply the complete filter to your live profiles safe in the knowledge that your visitor data is not being tainted! This post should help identify any errors to your IP Filters and assist with providing as clean a data set as possible to make evaluations of web site performance.

Final note: It is useful to save the test page to retest periodically to catch any dynamic IP changes that you might not have captured.

Post By Jon Dyer (18 Posts)

Jon is the VP of Operations at TechWyse and analyzes everything. This includes your analytics accounts and the difference between Coke and Pepsi. He often shares with us his advanced level knowledge of campaign analysis and Google Analytics.

Website: →


Jon is the VP of Operations at TechWyse and analyzes everything. This includes your analytics accounts and the difference between Coke and Pepsi. He often shares with us his advanced level knowledge of campaign analysis and Google Analytics.
Post a Comment
Send me SEO tips!



Daily    Weekly

Like us on Facebook

TechWyse Internet Marketing

Tricks For Advanced IP Filtering With Google Analytics

Read time: 3 min