Google Analytics

Well all know about the mega massive search giant known as Google. Also, they have this obsession with tracking its users. I am familiar with this tracking system on a minor scale, and I do my best to avoid it, just because I can. For those of you who don't like big brother looking over your shoulder, but still want to enjoy the services provided by him, you probably want to keep reading because this script I have for you enables you to search on google without having to deal with too many of their tracking systems getting in your way.

Personally, I browse in FireFox, and I use the extensions NoScript and Request Policy to help protect me against a lot of unwanted things people like to embed in their websites. Be they scripts or even advertisements. In most cases, I can even block google-analytics ran by other people's websites as well. Google likes to embed things in their links that you click. This is how they keep track of what you click so they can order their links appropriately. When you click on these links in their search results they used to do one of two things. At first, there was a "onclick" even attached to the link. When you click on the link, it would change the destination to "http://www.google.com/url?url=[The Url]" This irked me in all the wrong ways because it was like Google was sneaking something under your link before you clicked on it. That /url?url= actually pointed to a part of the Google application, which I suspected to track the link the time you clicked, the related search, what you ate last week, and all the other crazy little things they thought were necessary related to that link. Once you landed on that /url?url= page, it would then send a 302 redirect to your destination. At this point in the application, Request Policy would step in and say that's not allowed, because technically, Google was making a request to an unauthorized third party.

When I noticed this, I created a GreaseMonkey script to remove the "onclick" from all of the search results, iteratively. This worked for a while, until (again, I suspect) Google found out about this and didn't like it. So, instead they changed their links to activate on a "onmousedown" method instead. This was no problem as I simply added the removal of the onmousedown handle as well in my GreaseMonkey script. This worked for the longest time until only just recently after Google Instant was released.

I laugh at this because (again, I suspect) Google said "fuck it" and just took out the on{whatever} handles. Now every single search result points to /url?url=[Your search result]. I applaud Google for their persistance, but they aren't going to stop me. It took a bit of working and string manipulation, but I modified my GreaseMonkey script to remove the bullshit from Google's analytics. Below in the code sample is the result of my efforts. It removes all attached onmousedown and onclick events from the search results, then it finds the target of the search results and strips out the Google tracking data.

You can also click here to quickly install this script into your GreaseMonkey extension :>

// ==UserScript==
// @name Google-Analytics
// @namespace http://www.google.com/
// @description Kills Google Scripts from being able to track my clicks >D
// @include http://www.google.com/
// ==/UserScript==

var a = document.getElementsByTagName('a'), link, index;
for(var i in a){
before = a[i].getAttribute('onmousedown');
link = a[i].getAttribute('href');
if( link.indexOf('/url?url=') != -1 ){
index = link.substr(9);
link = index.substr(0, index.indexOf('&'));
a[i].setAttribute('href', unescape(link));

Happy tracking-less browsing! ;)

No comments:

Post a Comment