Count Me Out!
July 11, 2006 by Justin CutroniTo keep your Google Analytics data pure you should remove all traffic generated by yourself or others that may not be real visitors. For example, if your company has a large call center you should remove the traffic they generate because it will skew your analytics data.
To remove this data we usually use an exclude filter based on IP address, host name or geographic location. While this is effective the results can be a bit ‘broad’. What I mean is you may not want to remove ALL of the traffic from an IP address, host name or geographic location.
Here’s another example. I have a blog (obviously) that I track with Google Analytics and I want to remove all of the traffic I generate. I don’t want to use an exclude filter based on IP address or geographic location because I want to see traffic generated by others in my company and city/state. I only want to exclude the traffic from the computer I am working on.
This technique can also be used if you have a dynamic IP address.
The solution is to create an exclude filter based on another piece of data, more specifically a custom segment. This method isn’t as broad as an exclude filter based on IP, hostname or geographic location. The filter is based on a cookie, which is specific to a computer. Using this method I can eliminate all of the traffic from an individual computer without affecting data created by others.
How to Set it Up
The first step is to set a cookie on your machine that will identify you to Google Analytics. We’re going to use GA’s custom segmentation functionality to do the.
I created a script that will set the GA custom segment cookie on your computer. You can view the source here.
Copy the source and paste it into your favorite editor. Then save the file. For the page to properly display on your website you will need to save it with the correct extension. You should be able to use a .html or .htm extension. It depends on your web server.
Once the file has been saved, upload it to your web server. You may need to use FTP. If you don’t know how to put the file on your web server consult with your web master. You can place the file anywhere on the site.
Then open a browser and type the location of the file in the browser. The page should display as an HTML form. If it displays as text then you probably need to change the file extension.
Enter some text into the text box and click the ‘Create Cookie’ button. The script will set the GA custom segment cookie on your computer and the cookie will have a value of whatever you entered into the text box. Do not use any white spaces or special characters when entering a value for your custom segment. Keep it simple, something like ‘exclude-me’ will work just fine. You should see a confirmation message that the cookie was set correctly.
The next step is to log into your GA account and create an exclude filter based on the value of the custom segment cookie. If you entered ‘exclude_me’ in the form then use ‘exclude_me’ as the value in the filter pattern field. Here are the settings for the exclude filter:

This script works by taking the value you enter in the form and setting it as a custom segment. The great thing about this script is you can place it on your site and then access it from all the computers you work on. Just point a browser to the script, submit the form and all traffic from that machine will be excluded.
Keep in mind that the GA cookies are specific to a domain. So if you want to use this script for multiple websites you need to follow the above process for each domain.
The script is written in JavaScript and has been testing in FireFox 1.5 and IE 6.X.
Subscribe:









48 Responses to “Count Me Out!”
Thank you for that excellent (and simple) tool for excluding internal traffic from GA data. I set up the page early this morning and put the cookie on 2 computers. Several tests have shown the traffic from those computers are being excluded. Previously I used exclusion by IP address, but these are changed by our ISP routinely (but randomly and with no notice), so excluding traffic this way was unreliable and a chore to maintain. I did also place our GA tracking code on this “Count Me Out” page. Thanks again for this solution.
By Steve Plante on Jul 14, 2006
Hey Justin,
Thanks for this tool. It seems that this is a safer and more accurate way to exclude yourself if your on a High-Speed connection with a dynamic IP that will change eventually.
I appreciate it!
eric
By Eric on Aug 2, 2006
Justin,
This is a great script.I wondered how I would maintain my
filter as my ip addy is dynamically assigned.
Thankyou
By mary on Aug 5, 2006
Thanks a million times over. I was trying to block my hits by IP, and of course, mine is one of the magically changing IPs, so my hits would end up in the mix as well every now and again. Thanks for giving us a proper way to handle this problem.
By Amanda on Aug 9, 2006
Thanks for the script — how do you “unset” the segment value? Just delete/expire the cookie?
By LewCipher on Aug 10, 2006
Hey LewCipher,
Correct, to delete or ‘unset’ a segment simply delete or expire the cookie.
Justin
By Justin on Aug 18, 2006
Even though I user tested it with you that day and blogged about it, I still go back to this over and over again when I need to use it (like today) and teach my customers how to use it.
Robbin
By Robbin Steif on Aug 28, 2006
Justin,
Thanks for your help with this. I recently found another way to set the same kind of cookie.
************************************************
Setting the cookie:
Create a new page on your domain, containing the following code:
<body onLoad=”javascript:__utmSetVar(’no_report’)”>
To prevent the page from being included in search indexes, you can also add the following in the head section:
<meta name=”robots” content=”noindex, nofollow”>
Visit this page from all computers that you would like to exclude from your reports, to set the cookie on each machine.
Creating the filter:
You’ll need to create an Exclude filter to remove data from visitors with this cookie. Follow the instructions at
http://www.google.com/support/analytics/bin/answer.py?answer=27207
to create a filter with the following settings:
Filter Type: Custom filter > Exclude
Filter Field: User Defined
Filter Pattern: no_report
Case Sensitive: No
************************************************
This information comes from -
http://groups.google.com/group/analytics-help-tracking/ (on this page, do a search for “Dynamic DNS Filter”)
Mark M
By Mark M on Aug 30, 2006
Hey found this by searching on google! Great idea. This will help me out on both my sites. I really appreciate it.
http://www.scubamazing.com
http://www.terencechad.net
~The Scuba Skipper
By Terence S. on Sep 8, 2006
Hi,
this is an awesome solution. The GA Help Desk only sent me links to the help pages, and couldn’t help at all in solving the problem of dynamically assigned IPs. Thank god Google Search did a better job and pointed me right away to your blog entry.
Well done, keep up the great work,
GolfBot (Webmaster)
Innenarchitektin Constanze Schuchmann
By GolfBot on Oct 28, 2006
So Justin,
If I use this script on my computer and then periodically delete and clean out all cookies then I will then have to re-run the script? Is this correct?
Thanks!!
By Rob on Nov 28, 2006
Hey Rob,
Correct. If you delete your cookies from time to time then you will need to re-run the above process to re-create the cookie.
Justin
By Justin on Nov 28, 2006
Thanks for the code. This will help out a lot in keeping my GA data correct for my site: http://www.tacticalhuntingandcamping.com
By Richard on Feb 4, 2007
Hi Justin,
I have a blogger.com account and am using the google analytics software on it. Unfortunately, there is no way that I know of to push a .html file up through the blogger.com interface and publish a separate private page for the purposes of this cookie creation script. Is there any way this script can be modified so that it can be run from a home users desktop and have the cookie created? Perhaps with an input field on the domain name the cookie should work under?
I’m one of those that has a dynamic DHCP address, but I haven’t been able to use this solution because I can’t get this code to a private page on my blog.
I could of course, add the cookie creation code to the main public page, hit it myself, then remove it right away but obviously this is not a good solution.
Any feedback would be appreciated (please copy me in an email too if possible)
Thanks,
Johnny
By Johnny on Feb 4, 2007
Johnny,
The script can’t use a form field for domain because it will violate the browser privacy policy. Cookies can only be set for the domain that you are currently on.
What you might want to do is manually edit your cookies using notepad or a cookie editor (there are a few plug-ins for FireFox) to change the domain.
Good Luck,
Justin
By Justin on Feb 5, 2007
Thanks for the excellent tip !
K
By Kostis Panayotakis on Feb 11, 2007
Here’s a couple of extra ideas for this.
I’ll be making a couple of assumptions - firstly that you have access to the code the site is written in, secondly that your site uses a footer or template common to all pages.
Many more advanced routers (such as the better ones provided by Netgear) provide dynamic dns facilities:
http://kbserver.netgear.com/kb_web_files/n101279.asp
This, in combination with some server-side scripting, will allow you to not print out the javascript when anyone accesses your site through your router:
_uacct = “UA-111111-1″;
urchinTracker();
Or something like that.
Another idea if you don’t have dynamic dns and use Firefox, is to define an extra useragent string using the about:config page in Firefox. Create a new preference name of something like general.useragent.extra.filter and give it a value of “analytics”.
You can then use php/asp in a similar way to before to filter out your traffic.
By Mike on Apr 5, 2007
Ah, the site has filtered out my code. In php your code will be similar to:
if(($_SERVER[’REMOTE_ADDR’])!=gethostbyname(’example.dyndns.org’)) {
Analytics code goes here!
}
By Mike on Apr 5, 2007
If you only need to set the cookie on a couple of machines, then here’s a way to do it without creating a custom webpage.
Browse to one of the web pages on your site that has your Google Analytics tracking code embedded.
While at that page, copy/paste this code snippet into the browser address bar…
javascript:__utmSetVar(’no_report’)
Hit Enter to execute that line and the cookie will now be set in the browser of that machine.
Hope that saves someone a bit of time.
By technut on Apr 18, 2007
Wow! I’m impressed with all of the different solutions to eliminating Google Analytics local traffic from reports. I have a solution to add as well.
Originally, I considered using a cookie, but wasn’t sure how to implement it. I also considered attempting to use a Greasemonkey User Script to remove tha analytics. Instead, I created a wrapper function around the Google Analytics urchinTracker method. My wrapper checks for a parameter in the url. If the url is found, then the urchinTracker is not activated.
This was especially helpful for eliminating the tracking on downloads, where the onclick event contains an entry with a string passed in as the key for the item.
In addition, if the parameter was found in the url, I also have a function that gets all anchor tags and adds the parameter to each url. So once I disable the tracking, it takes effect on all pages until I remove that parameter from the url.
Finally, if the parameter is found, I insert a notification at the top of my site that notifies me that the tracking is disabled!
I like the cookie idea, as well as the separate page to access to activate the cookie. I may even try it myself, but I definitely had fun implementing my solution.
By James Mortensen on May 19, 2007
hi,
i have a public facing website. i have to exclude all the internal hits generated by the employees from my firm in google analytics and only take those into account which are generated from external users. i have tried using a range of ip addresses in my filter but it doesnt seem to work. i cant use the name of the dns. also, i m not sure if the solution with cookie that you have specified will work. since i ‘ve to exclude the whole of traffic generated by my firm not just one odd pc. Please let me know if you know of a solution. Thanks.
By neha on Jul 23, 2007
Ho Neha,
If your company has a static IP address, then you can use the pre-defined filter in GA to exclude all traffic from an IP. If your org has multiple IP addresses then you’ll need to get cretive with the regular expression you use to define the IP address. This approach should work. Make sure your regular expression is correct.
However, if your company has a dynamic IP address, then you should think about using the method I describe above.
Hope that helps.
Justin
By Justin on Jul 24, 2007
Thanks! What a great tip - this is something I can put on all of my clients’ sites and show them how to use.
By Debbie on Jul 27, 2007
How do I get rid of a hostname that should not be in my list of hostnames?
By JP on Sep 25, 2007
Debbie,
You can add an exclude filter to the profile to exclude any unwanted traffic from a hostname.
Justin
By Justin on Sep 26, 2007
thanks for the GREAT post! Very useful…
By Whatever-ishere on Nov 21, 2007
Hello! thanks for the great tips and tricks. great reading.
question….
I have a members area and I’d like to segment the traffic in GA. That way I can see what members are viewing on the corp site. The cookie way looks like a great ‘tweak’ but i have concerns.
Our login page has heavy traffic (imho). Maybe 6 to 10 logins per second on heavy days/hours.
We keep our login page lite with minimal code as to not create any delays/issues etc for members logging in.
Your idea is to add the ‘create’ cookie code on the successful login page, but our tech department says they CANT add that much code/javascript to the login page. They fear it will cause delays/errors etc.
They say they’ll create any cookies needed, but not using the urchin.js file.
Is there a way to set the __utmSetVar variable without actually calling the “__urchin.gif” from google?
I don’t need any “Members Area” stats, i’m only trying to see what members/non members are viewing on the “Corp” site.
Hopefully that made sense?
thanks for your time.
By trigger on Nov 29, 2007
Hey Trigger,
Trying to manually create the cookie is tough. What I would do is to try and use link tagging to isolate members. That way you’ll only need to change the login page URL (add the link tagging variables utm_campaign, utm_medium and utm_source). The downside of this approach is that if you want to track referral information you won’t be able to.
Hope that helps,
Justin
By Justin Cutroni on Dec 3, 2007
Thanks a lot everyone for the information and help. This has all been very useful and I can definitely use it on our www.meritsolutions.com site. Thank you thank you thank you.
By Josh on Dec 6, 2007
Hi Justin,
I recently bought your e-book. I hoped to find an answer on this problem.
I’m trying to exclude traffic coming from a domain with a hyphen in it: abc-xyz.com. I used a custom exclude filter (hostname) to exclude the traffic form this domain: abc\-xyz
But apparently this isn’t working.
I tried several filters (standard exclude traffic from domain) and several settings like www\.abc\-xyz\.com and abc\-xyz\.com but nothing really works. These sites keep referring visitors in my stats.
Can someone please help me out on this one?
By Vladimir on Dec 10, 2007
Hi Vladimir,
Thanks for buying the book.
Are you trying to eliminate the referrals from a specific domain? In that case you need to filter on a different field. Try the campaign medium.
Or does your tracking code appear on abc-xyz.com and you’re trying to eliminate all traffic that is occurring on that domain? If this is the case the filter you have should work.
Hope that helps,
Justin
By Justin Cutroni on Dec 11, 2007
Hi Justin,
I tried what you proposed (exclude campaign medium) but without results.
The situation is as follows. The first domain www.abc-xyz.com keeps sending people to my site www.xyz.com. The first domain is a site that is used by colleagues. I want to exclude every visitor from www.abc-xyz.com in the stats of www.xyz.com, because it’s sort of internal traffic skewing my stats.
I’ve tried about everything, so I guess I must have missed something. But what?
By Vladimir on Dec 18, 2007
Vladimir,
The name of the referring website is stored in the campaign source filter field, not the campaign medium filter field.
Justin
By Justin Cutroni on Dec 18, 2007
Thank you so much for this! Much better than trying to decipher Google Analytics Help Center’s vague description.
By emile on Jan 9, 2008
Thank you so much for this. You made it super easy :-)
By judy on Jan 19, 2008
Thank you so much, it works at last! I’d been trying for hours to do this and then got it to work with your script. Great job!
By Chris on Mar 12, 2008
Great post, great tool, many thanks!
By Baby Toddler Clothing on Mar 24, 2008