To 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.
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.
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
Justin,
This is a great script.I wondered how I would maintain my
filter as my ip addy is dynamically assigned.
Thankyou
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.
Thanks for the script — how do you “unset” the segment value? Just delete/expire the cookie?
Hey LewCipher,
Correct, to delete or ‘unset’ a segment simply delete or expire the cookie.
Justin
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
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
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
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
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!!
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
Thanks for the code. This will help out a lot in keeping my GA data correct for my site: http://www.tacticalhuntingandcamping.com
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
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
Thanks for the excellent tip !
K
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.
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!
}
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.
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.
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.
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
Thanks! What a great tip – this is something I can put on all of my clients’ sites and show them how to use.
How do I get rid of a hostname that should not be in my list of hostnames?
Debbie,
You can add an exclude filter to the profile to exclude any unwanted traffic from a hostname.
Justin
thanks for the GREAT post! Very useful…
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.
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
Thanks a lot everyone for the information and help. This has all been very useful and I can definitely use it on our http://www.meritsolutions.com site. Thank you thank you thank you.
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?
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
Hi Justin,
I tried what you proposed (exclude campaign medium) but without results.
The situation is as follows. The first domain http://www.abc-xyz.com keeps sending people to my site http://www.xyz.com. The first domain is a site that is used by colleagues. I want to exclude every visitor from http://www.abc-xyz.com in the stats of http://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?
Vladimir,
The name of the referring website is stored in the campaign source filter field, not the campaign medium filter field.
Justin
Thank you so much for this! Much better than trying to decipher Google Analytics Help Center’s vague description.
Thank you so much for this. You made it super easy :-)
Johhny,
If you are using blogger…
You can add a new Page Element -> HTML/Javascript.
Put the above code in the element. Add the cookie. You are done. You can remove the page element with ease.
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!
Great post, great tool, many thanks!
Great post. My ISP assigns addresses via DHCP, and removing myself from Analytics’ stats will be very helpful.
Hey this was great! Now I can exclude all the right people just by giving them a few instructions over the phone. Cheers! Anja
Thanks for the tip!!!! very clear and easy to follow instructions
Hi Justin,
Thanks for your help! I implemented a simple exclude filter with a cookie, but I’m not sure how to make sure it’s working. What’s the best way to check if the cookie & filter combo is working (ie, make sure my own traffic is not being counted)?
Thanks a bunch,
Phil
I have created the cookie for my machine but how do I delete the cookie from my machine? Thanks
Hi Phil,
I suggest you create multiple profiles in your GA account including a master profile that has ALL data, including your own. Then create a separate profile that excludes your data. You might also want to create test profile to experiment with new settings.
Yael, if you want to delete the cookie just use your browser’s feature for deleting cookies. It’s different from one browser to another, but they all have some type of ‘delete cookie’ functionality.
Thanks for reading and I hope that helps,
Justin
That looks absolutely awfully great, but I wonder: is it still valid for the GA “new code”? This “urchin” seems to me the old one… Any update?
Thanks
Agnes
Hi Agnes,
Unfortunately this only works with the urchin.js code. I’m trying to write another version for the ga.js code.
Thanks for reading the blog,
Justin
Thank you very much for your help!
Dear Justin,
I am creating my own blog at blogspot, and use GA to measure traffic. I use regular ATT DSL connection from home. I use both Firefox and IE.
I’d like to exclude myself from GA, but am having a hard time to understand your instructions.
I copy-pasted the script on my notepad. From that onwards I don’t know what to do in order to reconfigure my cookie, and then set up the filter at GA.
I’d be very grateful if you could help me with more pedestrian step-by-step instructions.
Thank you for you care. And congratulations on your work and popularity!
Tony
Hi Justin
We have been hitting the same problem. Our analytics data has been seriously distorted by our constant presence on the site, as we are constantly editing and administrating it.
Your solution inspired me… to create an easy bookmarklet to add the exclusion cookie.
Well, I hope it is easy. It does make it simple to implement, and everyone working on the site can use it.
You can find it on http://www.techmale.com.
I hope it helps.
Cheers
Ross
Hi Tony,
Unfortunately you can’t use this technique because you can not FTP files to Blogger.What you need to do is create some type of hidden post, or page, that only you can access. This content should have the __utmSetVar(‘exclude-me’) function somewhere in the page. When the page loads, the cookie will be set on your machine. Then you can follow the instructions starting with the filter section.
Hope that helps…
Justin
Thanks for the great tip. Now, how do I verify that the cookie is installed properly on my machine? Thanks!
Hi Justin
Thanks for this blog – you write clearly and are easy to follow.
I am wondering if you can help me – I’m still learning all this stuff. I’ve set up google analytics for my company, and I want to exclude internal traffic by cookies (most of our employees work remotely from across Canada & the US).
I have pasted below the code that I currently have installed, but it doesn’t seem to be working. I know this because I created two profiles in Google Analytics – one that reports all trafic, and one that is supposed to filter out the internal traffic by cookie. However, the numbers are the same, so I know something is wrong.
Can you take a look at my code and see what might be wrong? I have a feeling it has to do with the last line of code. I have been looking at other people’s comments on this in various blogs, and I see many variations:
-“utmSetVar” (Some people have it as just “SetVar” – what is the difference?)
-(‘test_value’) – some people are using (‘exclude_me’) or (‘no_report’) – I’m not sure what the difference is between them and which one I should be using.
Any help you can offer would be appreciated SO MUCH. My code is below. THANK YOU.
——
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”));
var pageTracker = _gat._getTracker(“UA-XXXXX-1”);
pageTracker._initData();
pageTracker._trackPageview();
Jennie It seems that your problem may be that you have not created a specific page on your website that contains the appropriate code. The concept here is that you need to set a cookie on the computers you want to exclude. To set that cookie you need to create a small script.
Also, as of right now, I’ve only outlined how to do this for the old urchin.js tracking code. I need to write up a post on how to do this with the new ga.js tracking code.
Tim Most browsers will let you view your cookies. For example, in FireFox, you can find your cookies in the Preferences section:
Preference > Privacy > Show Cookies
To be honest, I’m not sure how to find cookies in IE, I’m a Mac user :)
Thanks for the questions.
Justin
Does this work for the new GA code or just for Urchin? I noticed “urchin ” in the code, so I should assume that no one has written anything new yet, right?
I just upgraded to the new code almost on top of a network refit that went to NAT. Should I go back to the legacy code?
Thanks in advance for your advice!
Melanie
If just replacing the urchin file name with ga.js will work; I’m willing to do that on my own.
Melanie
Melanie,
The example in this post only works for urchin.js. I have not had a chance to create a version for ga.js yet.
Unfortunately you can’t just replace urchin.js with ga.js. There are a number of function calls that need to be replaced with method calls. I’ll try to get an update out as soon as possible.
Justin
Hi Justin,
This is great. We installed this cookie in July and it has been working perfectly until recently. I created a funnel for a shopping cart goal and am noticing that I am being counted when I am on our website going through the funnel steps (i am able to look in GA at the path and the path is identical to the one I took). I don’t think I cleared cookies in the past so I pulled up the script in a browser and resubmitted the cookie button. I’m hoping this will clear the problem. My understanding is the count me out works for the IP address so in theory I should be able to go to any page of our website and not be counted. Is this correct? Thanks again for a fantastic tool.
-Micki
Micki,
The exclusion is actually based on a cookie, not on your IP address. That’s why this approach can help small businesses or any organization that has a changing IP address.
I would also double check and insure that your filter is correct and is excluding the “user defined” value that you set in your cookie.
Glad you like this technique and thanks for the question.
Justin
I also realized that you can automate the cookie installation method described by Mark M by coding your “cookie page” with an instant redirect script and meta refresh tag (to the real homepage) and assigning it as the homepage in the browser; so the cookie will be automatically replaced on public computers (which are usually set to delete cookies when the browser closes). I haven’t implemented this yet; but it sounds like it should work?
-Melanie
Hi Melanie,
That should also work. This script is in dire need of an update! I’ve been trying to get it done forever, but there are just so many things to blog about.
Justin
Hi, this is very great
I d just like to check: does it work with the new version og GA code?
Thanks
Agnes
Agnes,
Unfortunately no, this only works with the old version f the tracking code.
I’ll try to get something done soon.
Justin
Justin,
Very good script indeed. I always use IP exclusion, but it is tough when you are always changing location… and not dare to visit your own website lest the analytics be biased :-)
Please comment here when you have a version for the new tracking code. I will pingback it ;-)
Cheers,
M.
Just a tip: to make it easily understandable for non-tech staff I changed the Title from “count me out” to :
1. Please type in”remove-me”
2. Go to website
Then a simple email asking them to visit xyz link and follow the on-screen instructions makes it understandable for everyone.
I also added a (little) joke to the alert message on http://www.concept-academy.co.il/no-statcount.html
Feel free to have a look.
Thanks Justin for this gem.
Great Mike !!
I got to the same solution with PHP. I cache the dinamic dns (more than one, home and workplace) in the session, then I exclude the GAnalitycs code.
Thanks, Justin, for the detailed instructions. There’s also (this might be a newer initiative on Google’s part) an Opt-Out Browser Add-on for Google Analytics – http://tools.google.com/dlpage/gaoptout
I have been looking for a way to exclude my own visits from Google’s Analytics. Good to find someone who explains it in a nice simple way!
This is an excellent post and a great idea. I just tried it, tested it and it works. Difficult to find when you’re using the old code. Thanks.
Thanks a lot! This was, as someone already said, the first easy explanation of that process. Thanks for that. And thanks for the “ready-to-use” file – it helps a lot :)
Normally, I don’t really like to read or leave one liners as blog comments….
But I have to say, this is “Definitely” one of the best blogs I have ever read!
By reading your book and actually “applying” your tips – just like this one – my entire business has changed.
Thank you for such “consistent” quality.
Does this make me a Cutroni Groupie? :-)
Yes Phillip, you’re now a groupie :) Thanks for the kind words.
Thank you so much! This worked perfectly.