Fixing Twitter’s link click tracking with Greasemonkey

Recently Twitter started to track the links being clicked on twitter.com. Instead of sending you directly to, say, www.example.com they started to redirect you to a link like

http://twitter.com/link_click_count?url=http://www.example.com&linkType=web&tweetId=123456&userId=456789&authenticity_token=1d52f617a7fb30a62a04db6c092ce6686f3bef50

I first noticed this new behaviour during one of Twitter’s infamous slow spells. Instead of seeing whatever it was I was supposed to see, all I got was a failwhale.

Twitter probably some reasons why they’ve implemented this redirect, but I don’t like it for two reasons: A) it adds another redirect layer on top of the url-shorteners (tinyurl, bit.ly et al) and B) it’s not as if twitter.com is so rock solid that the redirects will always work.

So I wrote a userscript for Greasemonkeya Firefox extension that allows you to customize the way webpages look and function—to disable the Twitter link click count.

With a little prodding, I found out that links in the timeline with the classes “tweet-url” and “web” are tracked. These classes don’t seem to serve any other purpose, and removing them seems to do the trick. Here’s the userscript code:

var tweeturls = document.getElementById('timeline').getElementsByClassName('tweet-url web');
for(i = tweeturls.length - 1; i >= 0; i--) { 
	tweeturls[i].removeAttribute('class');
}

The first line collects all elements to which the classes “tweet-url” and “web” are applied and that are a descendant of the element with the id timeline. Then you loop through this collection (starting at the last element) and remove the class attribute on all elements it contains. Voila.

You can use the code above of the link below to add this script to Greasemonkey. Since you made it this far, I suppose you know how to do that.

? disabletweettracking.user.js

CHANGELOG

  • version 1.4 — 2010-08-09 — removes the ‘Who to follow’ block. Might need to reconsider the name of this thing.
  • version 1.3 — 1010-07-20 — version 1.2 was borked, this one just works.
  • version 1.2 — 2010-06-22 — as Twitter doesn’t seem to track it’s links in an annoying way anymore, all this version does is removing the target attributes. Uses jQuery.
  • version 1.1 — 2009-10-14 — also removes the target-attribute. No more forced new windows.
  • version 1.0 — 2009-09-09 — initial release