Mar 022011
 

I like using Google Analytics for tracking statistics. Those statistics read like porn to guy who loves numbers. There is only one problem with them – they count every visitor. That would also mean that my administrative tasks are skewing numbers. We cannot have that!

In order to disable logging own visits we need to check what exactly Analytics’ code does:[xml highlight=”7″]
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-4401313-2’]);
_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>
[/xml]

Code is pretty simple and only place where any action can possibly happen is in line 7 where we see ga.js script. Depending on whether our page is http or https those URL’s are http://www.google-analytics.com/ga.js and https://ssl.google-analytics.com/ga.js respectively. As soon as we disable those two servers our own visits will not be logged.

Since we cannot disable servers as such we need to do next best thing and disable them in our part of universe. There is nice file called “hosts” situated in “C:\Windows\System32\drivers\etc” (or in “/etc” for *nix systems). In this file we can override any DNS resolution and assign any IP address to any host name.

File format is quite simple and I will not explain it here. It is enough to say that we just need to append two lines (after adding write permissions, by default this file is not writable by normal user):

···
127.0.0.1	www.google-analytics.com
127.0.0.1	ssl.google-analytics.com

These lines are just forwarding any call to Analytics servers to our own computer. Since we do not have Google’s infrastructure it is pretty safe to assume that all requests will go nowhere. And that also means that computer with this “fix” will not be recorded by Google Analytics.

P.S. Modifications to “hosts” file are great way to annoy somebody in office who left computer unlocked.

  2 Responses to “Do not analyze me”

Comments (2)
    • They have two solutions.

      One is filtering by IP address (or range) and it does not play nicely with dynamic addresses (that is works, but you need to change filter every time you change your IP). Even worse, if you are behind NAT, all users behind same NAT are blocked. I will not even go into need to limit every filtered IP by time (since somebody else might have your address tomorrow).

      Another solution with JavaScript is much better but here I have issue with having to do same thing in every browser I have. While I only use Chrome for standard browsing, when it comes to testing, I use few more. This procedure needs to be done in each of them. If you forget to do it in one, data is already ruined.

 Leave a Reply

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>