Sometimes we miss the obvious. When reporting web statistics, how many of us forget to exclude (or at least designate) our own internal traffic?

Google Analytics

Google Analytics

Google Analytics tracks the behaviour of any browser that has cookies and JavaScript enabled. It’s therefore pretty important to isolate the browsing habits of you, your team and your agency (if you have one) from your statistics. If you are editing, reviewing, or merely just keeping an eye on things, you can significantly impact the statistics of your site.

I use WordPress to publish this site and use the Yoast Google Analytics plugin to insert my Google Analytics JavaScript tracking codes. The Yoast plugin is really good at excluding my browsing behaviour when I’m logged in. However, it doesn’t exclude the use of my multiple browsers, multiple devices nor when I’m not logged in.

Exclude internal traffic from Google Analytics

It’s actually fairly complicated to exclude your own / internal team’s browsing habits from Google Analytics because you invariably end up in JavaScript or cookies (or both). I had to search around for quite some time to figure out a way that it works and some of the methods are now deprecated. I’ve tried to simplify this as much as I can without hiding some of the details.

So here’s what you can / should do.

Keep an unfiltered view

First of all, make sure that you also keep an unfiltered view of your Google Analytics stats. It’s worthwhile setting up an “All Traffic” profile in Google Analytics that doesn’t have any Filters or Advanced Segments.

There are two reasons for this a) you can check if your internal filters / segments are working, and b) you might need to use  the raw data at some point. I’ve found “All Traffic” profile quite handy on a few different occasions.

1. Google Analytics OptOut

This is a pretty basic (read brute force) way to exclude your browsing behaviour from Google Analytics. It’s very easy to set up but it excludes your browsing behaviour from all Google Analytics tracked sites.

So, if you only want to exclude your browsing behaviour from your own site, then it’s quite a blunt instrument to achieve this.

You can download the Google Analytics Opt Out tool here.

2. Filter IP addresses

This is the way that Google has documented for excluding internal traffic. It’s reasonably simple to set up but not very user friendly if you connect via a few different sources or on a mobile as you need to set up each of the rules individually.

To exclude via IP address, you can use either ISP domain or specific IP addresses / netmasks. To do this go to the Admin console in Google Analytics and implement different Filters.

There is a good description of what to do on the Google Analytics site here.

3. Cookies

I think using cookies is the best way to exclude internal traffic, as it’s based on the way that Google Analytics tracks your behaviour, but it takes a bit of time to set up. You also need to understand how to check your browser’s cookies to see if the method has worked. However, once you’ve set the cookie method up once, then its quite easy to set up a bookmark so that you can re-use the cookie across many devices.

There are two ways to implement the cookie method… one has been deprecated by Google (but still works). Both require you to put an HTML file on your web site, and uses the Google Analytics JavaScript function ga.js, to set a cookie value that you can then track in Google Analytics to exclude your behaviour.

The _SetVar() approach still works but Google recommend that you use the _SetCustomVar() instead. I used to exclude my internal traffic using the _SetVar() method but have recently moved to the _SetCustomVar() method instead.

_SetCustomVar()

The _SetCustomVar() method puts a value under the __utmv cookie for the domain name where the HTML file is hosted. I’ve included a sample HTML file below that uses the Exclude=Yes combination. You will need to update your GA identifier and you can use a different value for the cookie is you wish.

To do this, create a HTML file based on the example below, and then save the HTML file to your webserver with a filename that you will remember. Something like exclude_cookie.html or similar. You can then create a bookmark to the file so you can then run the file from each of your browsers / devices so set the cookie for all required devices.

They next step is to check for the cookie value from Google Analytics, For the setCustomVar method this is done via Advanced Segments. You simply add an Advanced Segment that excludes for the cookie value that you have set.

For my example HTML below, the Custom Variable (Key 1) is Exclude and the Value is Yes. Don’t forget to change your Google Analytics account ID.

<!DOCTYPE html PUBLIC ì-//W3C//DTD XHTML 1.0 Transitional//ENî ìhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdî>
<html xmlns=îhttp://www.w3.org/1999/xhtmlî>
<head>
<meta http-equiv=îContent-Typeî content=îtext/html; charset=iso-8859-1? />
<title>Google Analytics Exclude Traffic _setCustomVar</title>

<!-- Prevents indexing of this page by search engines -->
<META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW">

<!-- Set GA cookie Exclude -->
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxx-1']);
  _gaq.push(['_setCustomVar', 1, 'Exclude', 'Yes', 1]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

</head>

<body>
<div align="center">
        <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td>
              <div align="center">
                <p><font size="6">Remove internal traffic for Google Analytics using _setCustomVar method</font></p>
                <p><font size="4">Cookie __utmv = Exclude</font></p>
              </div>
            </td>
          </tr>
        </table>
      </div>
</body>
</html>

That’s pretty much it. Now you should be able to see the traffic coming from an internal user based on the Advanced Segments.

There is a good resource on Setting CustomVariables here.

_SetVar()

Again, the _SetVar method puts a cookie under the __utmv for the domain name where the HTML file is hosted. This a very similar approach to the _SetCurrentVar above. However rather than using the Advanced Segment to see / exclude internal traffic, the _SetVar() method uses a Filter.

You need to add a new Filter that excludes a cookie value. This is done under Filter, then select Custom Filter, then Filter Pattern is the value of the cookie.

For my example HTML below, the value that I’ve used is “Exclude”.

<!DOCTYPE html PUBLIC ì-//W3C//DTD XHTML 1.0 Transitional//ENî ìhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdî>
<html xmlns=îhttp://www.w3.org/1999/xhtmlî>
<head>
<meta http-equiv=îContent-Typeî content=îtext/html; charset=iso-8859-1? />
<title>Google Analytics Exclude Traffic _setVar</title>

<!-- P	revents indexing of this page by search engines -->
<META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW">

<!-- Set GA _setVar Exclude cookie -->
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxx-1']);
  _gaq.push(['_setVar', 'Exclude']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

</head>
<body>
<div align="center">
        <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td>
              <div align="center">
                <p><font size="6">Remove internal traffic for Google Analytics using _setVar method</font></p>
                <p><font size="4">Cookie __utmv = Exclude</font></p>
              </div>
            </td>
          </tr>
        </table>
      </div>
</body>
</html>

I would recommend against using the _SetVar method and using the _SetCustomVar instead.

Other tips

1. There easiest way to check what cookies are being set for your site is to use the developer tools as part of your browser. I use Chrome as my browser (but this works similarly in other browsers). To get to the developer tools in Chrome, you simply right click the web page and use Inspect Element. There is an option to view cookies.

2. The Google Analytics Real-Time reports are really handy to troubleshoot internal vs external filters and advanced segments. You can use your own traffic to test edge cases.

3. It’s worth understanding how Google Analytics uses cookies as there are a few different cookies as part of Google Analytics. These are described below. A good resource on Google Analytics cookies is here. The important cookie for excluding your browsing behaviour is the custom variable cookie UTMV.

  • UTMA – The Visitor Identifier
  • UTMB – 30 Minute session identifier
  • UTMC – On Exit session identifier
  • UTMV – Custom Variable Cookie
  • UTMZ – Visitor segmentation

4. The Google Analytics Advanced Segments help is here.

5. The Google Analytics Filters help is here.

Good luck!

This isn’t the easiest process in the world. Google Analytics is really powerful but the documentation can be a bit tricky.

My view is that it’s worth the effort to get the cookie version working and then create a bookmark to use across all of your different users / devices. Let me know how you go.

  1. Hi Darren,
    You can use the cookie method in reverse to show the internal traffic.
    Rather than *excluding* traffic that has the cookie set to Yes, you *only include* traffic that has the cookie set to Yes. You can do this by setting up a new View and then using Advanced Segments.
    This is probably a fairly good way to check that your cookies are working correctly. You can view your own browsing traffic via Real-Time reporting in GA.
    Steve

    PS. I had to log out of WordPress to stop the Yoast plugin automatically removing internal traffic.

  2. Good resource Steven, finding anything else useful on advanced segments was difficult.

    I did have a couple questions with the setup-

    If I define the same cookie in your example am I then filtering it out by creating an Advanced Segment filter with “Custom Variable (key 1) – Contains – Yes”?

    And do you know if changing segment changes real time analytics? It’s the only page without a segment selector on.

    Thanks again for taking the time to put this together.

    • Hi Dominic,

      Updated: Advanced segments don’t work for real-time analytics. The advanced segments only work for other views. However, filters do work in real-time views.

      Updated: For internal traffic the Advanced Segment should have Custom Variable (Key 1) – Contains – Exclude and then have Custom Variable (Value 01) – Contains – Yes. To exclude internal traffic you would do the opposite.

      Best of luck.

      Steve

Leave a Reply