Watching the Watchers

by ZoeB

I'm sure most 2600 readers are aware of Google Analytics.  It's a handy way for web site owners to see what their visitors get up to without having to learn how to analyze Apache log files.

More paranoid readers may have worked out that Google has a lot of information at this point.  Using Google Analytics alone, they can keep track of which web pages people look at, not just on individual sites but from one website to the next.  This works if all the sites in question use Google Analytics, which increasingly more web developers are recommending to their clients due to its ease of use.

As someone who values her privacy and likes tinkering around with computers, I thought it would be a fun little project to stop my computer from talking to Google Analytics.  It only takes a few minutes, and the effect will last until Google decides to change the URL of their JavaScript file that keeps track of people browsing the web.  This will probably be quite some time, as they'd need to tell a lot of people to update every page of their website.

Redirecting Your Browser

As you can see by simply viewing the HTML source of any site that uses Google Analytics, the program that keeps track of your movements on the web is available at: www.google-analytics.com/urchin.js

So you may want to tell your computer not to access that particular domain name...

To do this, edit your /etc/hosts file, which keeps track of which domain names go to which IP addresses.

(It's in a different directory in Windows, but GNU/Linux and Mac OS X users should be able to pop open a terminal application and just start editing it using sudo or su and the text editor of their choice.  If in doubt, search online for more details.)

This is the line you need to add to /etc/hosts:

127.0.0.1     www.google-analytics.com

Once you save the file, your computer will think that any traffic for that domain name should go to itself rather than to the real site, so it won't actually talk to the real Google Analytics server anymore.

Finding Out Who Uses Google Analytics

If you're running an Apache web server and know how to set up domain names on it, things get a little bit more fun.

You can tell Apache that it is indeed the server that should receive requests for files on that domain name by editing httpd.conf and setting up a directory to host that domain's files.

If you're not familiar with Apache, you'd do well to read up on it first; it's notoriously finicky about its configuration file.

The simplicity of setting up Google Analytics is vital for its popularity.  This means that it's also very simple to serve the appropriate file locally.

Just create a plain text file called urchin.js in your new directory and type the following into it:

function urchinTracker() {
  window.status = 'This site tried to contact Google Analytics';
}

That's it!

Whenever you access a site that tries to monitor your activity using Google Analytics, your web browser will instead tell you about it by writing a message in your browser's status bar.

Naturally, you can change this script to do whatever you want.

Bear in mind that Firefox doesn't let JavaScript programs write to the status bar by default.  If you want, you can override this by going to the Firefox preferences, clicking on the Content tab, clicking on the Advanced button next to the Enable JavaScript checkbox, and ticking Change status bar text.

Return to $2600 Index