Exclude Self-traffic from your Website’s Access Reports

Published by Tomas  Vitvar on January 13, 2009 in Ideas,Programming

I use Google Analytics to track my website’s traffic. Since I also often use information on my website to quickly search for a paper I wrote and refer to it, I access my website quite often. From this reason I need to exclude my own traffic from reports generated by Goolge Analytics. Google Analytics comes with two suggestions how to do this, however, neither of them is really suitable for me. The first option is to exclude all traffic based on one or more IPs. I can set a filter to exclude a traffic from my work as well as home networks, however, I do not really want to exclude a traffic from my colleagues which such a filter would do too (my work place has a single public IP shared by all outgoing connections). The other option is to set a variable (cookie) on all pages you want to exclude and create a filter based on that variable. This option is not any better as I would need to always set such variable on every new page I create, that is, call a specific javascript method when page loads, deploy the page to my web server, access the page to set the cookie for my own access, and then remove the javascript method call and redeploy the new page for public access.

Fortunately, a very simple solution came into my mind (currently only works on Firefox). First, I create a custom variable in the Firefox configuration settings called general.useragent.extra.private and set its value to my_agent” (please use your own unique identification, type about:config in your browser’s address bar to create and set such variable). This will add the “my_agent” string to the browser’s agent identification that you can read from within the javascript in the browser by userAgent property of the navigator object (navigator.userAgent). After that you can just add a simple condition to your page’s javascript code that calls Google Analytics methods to track your page’s traffic. The script could look like:

<script type="text/javascript">
    if (navigator.userAgent.indexOf('my_agent') == -1) {
        var pageTracker = _gat._getTracker("UA-xxx");
        pageTracker._trackPageview();
    }
</script>
Update: In Safari, you can set a custom user agent string by enabling Develop menu (goto "Preferences->Advanced->Show Develop Menu in Menu Bar") and in the develop menu "User Agent->Other..." set the user agent string.    

One Response to “Exclude Self-traffic from your Website’s Access Reports”

  1. What a super blog post it was. Nice share. But I am having difficulty with this feeds. I could’n to subscribe. Is there anybody else experiencing similar issue with your feed?

Leave a Reply

-->

Blog

Archive