Do Not Analyze Me
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:
<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>
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.