Count Me Out!

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:

Filter to exclude user defined cookie.

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.

Like this post? Share it:


And how about checking out these related posts:

  1. How Google Analytics Tracks Third-Party Domains
  2. Creating Test Profiles in Google Analytics

Comments

  1. Tim says:

    Thanks for the great tip. Now, how do I verify that the cookie is installed properly on my machine? Thanks!

  2. Jennie says:

    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();

  3. 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

  4. 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

  5. If just replacing the urchin file name with ga.js will work; I’m willing to do that on my own.

    Melanie

  6. 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

  7. Micki says:

    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

  8. 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

  9. 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

  10. 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

  11. Agnes says:

    Hi, this is very great
    I d just like to check: does it work with the new version og GA code?
    Thanks
    Agnes

  12. Agnes,

    Unfortunately no, this only works with the old version f the tracking code.

    I’ll try to get something done soon.

    Justin

  13. 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.

  14. Jen says:

    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.

  15. Heros says:

    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.

  16. Aviva B says:

    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

  17. Daniel says:

    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!

  18. Don McCauley says:

    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.

  19. Luke says:

    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 :)

  20. Philip says:

    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? :-)

  21. Yes Phillip, you’re now a groupie :) Thanks for the kind words.

Trackbacks

Speak Your Mind

*