Thursday, February 21, 2008

HOWTO: Exclude your visits from Google Analytics


In my view, one of the minuses of Google Analytics (GA) is the difficulty of excluding our own traffic (aka internal traffic) from the reports. As per this help article, there are two methods of achieving this. One is to set up a filter to exclude traffic from a given IP address or a range of addresses. This method is undesirable if you are using a connection that assigns dynamic addresses for each session.

The other method is to filter using a cookie installed in your browser. This method is more reliable and safer than using the first method. But the caveat is installing the cookie as it is not straight forward. And the second method described in the help page is flawed according to this discussion.

The Steps

Here are the tried and tested steps to exclude your traffic from GA.

1) Open your template in the Edit HTML mode and scroll right to the end where your tracking code is installed. Locate the script shown below and add the line shown in red.

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");

Replace the variable passed to the _setVar() function with something applicable to you. The string you provide here ("exclude_ids_bguide" in this case) is called the filter pattern and it will be used later when we create the filter.

2) Save the template and visit your blog from all the browsers that you want this cookie installed. For example, if you are using Firefox and IE, visit your blog's homepage from both the browsers. If the page is already loaded, make sure that you do a page refresh.

The next step is VERY IMPORTANT!

3) Go back immediately and remove the line added (i.e. the line shown in red) in step (1), from your blog template and save it again. If you leave this line, all visitors to your blog will also get the cookie installed and you will not have any visits. That's the danger here. Make sure that you remove it immediately after step (2)

4) Login to GA and create a Custom Filter for this cookie. Provide the values as shown in the figure below and select the profile (i.e. your blog address) that you want to exclude. Make sure that you copy the exact filter pattern that you gave in step (1) above.

You will have to wait about a day until you confirm that your visits are now excluded.

The content of this article is based on this discussion thread on the Analytics Help user group. I thank all the contributors to that thread.