Google Analytics – Hiding your own visits

As a web developer I’m interested in the visitor statistics for any site that I manage, but with this new blog I find that my own visits are swamping the results. On commercial sites I’ve used IP address filtering to exclude employee visits, since they are usually coming from a limited number of access points related to company offices, but in this case I view my blog from several difference devices with dynamic IP addresses.

Trawling the web I found a solution using _setVar on but this approach is now deprecated.

Several more searches gave me a solution that works using _setCustomVar which is the replacement for _setVar.

Step 1 – Adding the exclusion to your site

Firstly, I assume you have the standard Google Analytics tracking code somewhere on your pages, like this:

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

Then create a simple page with the following additional script:

  var _gaq = _gaq || [];
  _gaq.push(['_setCustomVar', 1, 'Me', 'yes', 1]);

(It doesn’t matter where the script goes, although I put it just below my tracking script which means I can also remove the var _gaq = _gaq || []; line).

The page content doesn’t matter (I just show a message saying my own visits are now excluded), but it shouldn’t be linked by other pages in the site or your sitemap, and should have a URL you can remember.

To exclude your own visits you simply access this page from every browser you use, and it sets the custom variable in a cookie that is used in the next step. If you clear your cookies or use a different browser you need to visit the page again before accessing the rest of your site.

Step 2 – Configuring Google Analytics

To use this cookie, we create an “Advanced Segment” that will filter tracking based on it.

  1. View the Dashboard report for the site you are interested in (the one associated with the UA-????????-? in the tracking code).
  2. In the top right corner there is a dropdown labeled Advanced Segments:, select this and it gives you the option to manage Advanced Segements.
  3. Select the Create a new advanced segment link which gives you a report builder interface.
  4. Expand the Visitors dimension in the green part on the left, and drag the Custom Variable (Key 1) entry onto the report dimension or metric area.
  5. For the Condition enter “Does not match exactly” and for the Value enter the name from your _setCustomVar call (in this case Me). Note it’s the name that you enter, not the value. It should look like this:
  6. Save the segment as “Exclude own visits” and you can now apply this to your reports by using the Advanced Segments selection screen as accessed in point 2.
  7. You can create the opposite filter by using Condition “Matches exactly” instead, and name it “Own visits”.

One thing I haven’t yet discovered is how to set an Advanced Segment to be the default view on the dashboard, comments on how to solve this would be very welcome.

Leave a Reply

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