Count Me Out: GA.JS Version

A while back I wrote a post called Count Me Out! that explained how to exclude Google Analytics data based on the custom segment value.

My previous post was based on the old, urchin.js tracking code, and a lot of people have been waiting for an update. It’s taken a while, but here it is.

I will mention that my favorite way to exclude traffic from Google Analytics is using an IP exclude filter. An IP based exclude filter is very accurate unless you having a changing IP. The method below works best if you have a dynamic or changing IP address.

Even if you’re not interested in this post, there is a fun ‘group activity’ below. Please try it!

The old version of this hack method required you to add a new page to your website. That page would set the GA custom segment cookie (named __utmv) on your computer.

This technique works fine, but who wants to add a new page to their site? It can be a pain.

I’ve simplified this technique by removing that page. You can enter the JavaScript directly into your browser.

Step 1: Set Custom Segment Cookie

Go to the site that you are tracking with Google Analytics and view a page.

Copy the code below and paste it into the location bar of your browser and click ‘enter’ on your keyboard.

You should see a message that says, “Custom segment has been set. Time to create a filter.”

Here’s a tip, you can bookmark this JS to make it easy to reset the cookie in the future. I set the cookie every time I fire up my browser.

Step 2: Create Exclude Filter

Next, create an exclude filter in Google Analytics to exclude the user defined segment (i.e. the cookie) you just created:

This filter will exclude anyone with a custom segment cookie with a value of ‘remove-me’.

Remember, cookies are specific to a browser and computer. If you use mulitple browsers or multiple computers you need to set the cookie using all the browsers on all the computers you use.

Having Some Fun With This!

You’ve probbaly figured out that you can set the custom segment cookie on anyone’s website as long as they’re using GA. This means that you can add data to their User Defined report. Let’s try this on my site!

Navigate to and place the following code in the location bar of your browser after the page has loaded. Change FOO to whatever you want and press enter on your keyword. That’s it. You’re now in my data.

I’ll post some of the more popular and creative values in Twitter and maybe here at a later date.

Please try to keep it clean. I often review data with my 4 year old son :)

Thoughts on the Old Method

The old version of this technique uses a form to set the custom segment cookie which is pretty handy if you have a lot of people in remote locations that need to be excluded from the data. Just send all your coworkers, contractors, etc. a link to the page and ask them to set the cookie on their computer. It’s a little easier than asking them to paste JS into their browser.

If you’re interested in using this technique here is a new version of the page and the process.

Step 1: Create a new page on your site using the code below.

** Note ** The information below is in an iFrame. If you receive this post via email you may not see the contents.

Step 2: Go to the new page you just added, fill out the form, and click the ‘Create Cookie’ button. Keep track of the value you enter into the form, you need it for step 3.

Step 3: Finally, create an exclude filter in Google Analytics to exclude the value that you entered into the form. Remember, you need to use a regular expression for the filter field. So if you entered ‘remove-me’ in the form, enter ‘remove-me’ as the Filter Field.

That’s it. Sorry for the lame post, but I’m trying to update a lot of the old code and posts on the site.

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.


    1. says

      Ha! Thanks John. I was going to mention using campaign tracking to exclude traffic, but I just wanted to keep this post about the custom segment hack.

      I’ll look for your wonderful message soon!

    2. says

      I noticed that the JS sets the variable ‘exclude-me’ but the filter pattern in the example is ‘remove-me’.

      You might want to make them match so that people who blindly follow your example (like me) don’t set it up incorrectly!

    3. says

      Just read the post. Need a small inquiry here. The cookies code seems to be working only on Firefox browsers isn’t it? abt other browsers like IE, Opera, Chrome..Seems not working there

      • says

        I just ran another test on Chrome and I am seeing the JS message and the cookie. Are you on a developer version? One other thing to check is make sure you are on a site that is running GA. I often forget to do that :)

    4. says

      Huhh it worked now .. its a stupid mistake i made here..I’m not on a site that is running GA.

      Many Thanks Justin for being so patient in replying to me

      Cheers !

    5. FMK says

      I’ve had problems with using _setVar() where it causes unwanted visits to be counted in profiles. For instance, if I have a profile including only traffic to one subdomain, visits will show up from other subdomains although pageviews do not. This leads to weird looking reports where there are thousands of visits and 0 pageviews. This problem only appears when _setVar() is used. It also appears to be responsible for changing the hostname to (not set). I’ve searched for solutions and played with different combinations of filters and the only solution I’ve found is to never use google’s _setVar() function. Some others have written their own javascript functions to set the _utmv cookie without the side effects. That seems workable although I haven’t tried that out yet. Could you post something about using _setVar(), what it actually does (vs what it’s documented to do) and how we should work with it? Thanks.

      • says


        Absolutely, you could use an advanced filter. But GA will sample your site data if there are more than 200k visits in the date range you’re looking at. And this can cause some weird data given the small volume of traffic from the custom segment.

        Thanks for the suggestions and thanks for reading the blog.


    6. says

      Hi Justin, I’m setting up some tracking using GA and am having a problem that hopefully you can help with. I think your book will be very helpful to me for e-commerce and I plan to use that at that time.

      The problem is this. When the user arrives from a banner at the site, the entire UTM string shows in the address bar like this:

      whereas all I’d like them to see in the browser is as I’ve noticed happens when other sites I go to using GA show despite the link showing the whole string. I tried a mod_rewrite i.e. (rewritecond and rewriterule) and can strip all the ?utm… string off, but then nothing is collected by GA.

      I thought there must be something I need to fix in the GA script but can’t figure it out. Apart from this, the GA seems to be working fine.

      Any help is much appreciated.


      • says


        You’re not doing anything wrong. In order for GA to collect the data you need to see the campaign parameters in the URL of the page. If the parameters are not there then the JS won’t be able to identify where the visitor came from. Sorry for the bad news!

        Thanks for the question,


    7. says

      Hi Justin,
      I got your GA book… Great stuff! I learned (and am continuing to) learn alot!

      I have a question about setting the Custom Segment Cookie/ Exclude Filter.

      Do you have an idea about how stable the cookie is?

      When I set up a client’s WordPress website with GA and want to exclude them (and me too!) using this method, how often should they reset the cookie? You mention that you set it every time you fire up your browser. That’s an onerous task to ask my clients to do.

      Do you know of a way to automatically reset the cookie periodically?


      • says

        Hi Ken,

        Glad you like the PDF. Look for a new version this summer.

        Re: your question, the cookie will last 6 mo as long as it is not erased. if you’re using WP you could reset the cookie set every time the user logs in. That will give you a reliable way to keep it on the user’s machine.

        Thanks for reading the blog and thanks for the question.


        ps – if you want to send the cookie value by email you’ll need to make that tweak, I’m busy updating/writing books :)

    8. says

      Hi Justin,
      As a followup to my previous question… I’m not super great at getting forms to do “unusual” things. Would it be possible to have your “Count Me Out” form set the cookie *and* have the value sent to me via email on the same click?

      That way I could have a client set the cookie on their computer and also inform me of what I need to exclude in their Analytics…


    9. says


      Thanks so much for the tip! This will be SUPER helpful for everyone over here on the Pelotonics team. It makes sense to just create a bookmark since a lot of us are clearing our cookies everyday.

      Cheers mate!

    10. says

      I know this post is a bit old and all but I would just like to ask a small question! This code doesn’t seem to work in IE8, it just doesn’t create any cookie, it should work right? It works in Firefox and Chrome. Could you please tell me if it works with you or it’s just me? Thank you.

      • says


        I have not tried it in IE8, in fact, I haven’t used IE in a couple of years :) But yes, you are correct, it should set a cookie. I’ll see if I can debug it soon. But, to be honest, the User Defined feature will be deprecated in the future and we should use Custom Variables.


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>