Twitter tracking clicks to external sites

Lately, while using the Twitter web interface with Javascript turned on, I've been redirected to a Privoxy error page whenever I click on an external link:

Request for blocked URL

Your request for http://twitter.com/link_click_count?url=http%3A%2F%2Fexample.com&linkType=web&tweetId=1234567890&userId=12345678&authenticity_token=f5920ebf56bfa111c54bb9f86814cafa76de00fa was blocked.

Block reason: Path matches generic block pattern.

Looking a little closer at the blocked URL, I noticed that for every external link you click, Twitter logs the destination URL, the originating tweet and your user ID.

So what can you do to opt out of this tracking?

Disable Javascript

This is by far the easiest solution. You can simply install an extension like Noscript and use Twitter with Javascript turned off. That's what I do most of the time since the website is mostly usable without it.

A very fortunate side-effect of using Twitter without Javascript is that you can avoid a number of the worms which propagate through that service from time to time.

For those times when I have to enable Javascript on the site, I use Privoxy, a great privacy-enhancing web proxy, to alter the Javascript code executed when clicking on external links. This effectively disables the extra tracking and takes me directly to the intended URL.

First of all, make sure you have this line in your /etc/privoxy/config:

filterfile user.filter

then, add this filter to /etc/privoxy/user.filter:

FILTER: twitter-link-count Disable the Twitter link tracker  
s@{var A=\$\("\#content a\.tweet-url"\);A\.live\("mousedown",twttr\.countClick\)}@{}@ig

and finally turn this filter on for the affected URLs (/etc/privoxy/user.action):

{ +force-text-mode +filter{twitter-link-count} }  
.twimg.com/.*/javascripts/front.js

Switch to Identica

If you want to avoid similar privacy problems in the future, you can also switch to an Open platform which respects your basic freedoms.

The main contestant in this space is Identica. It's a great alternative to Twitter and has a lot of interesting features (like groups and XMPP integration) which are not yet available on Twitter.

The StatusNet developers have kindly released their source code under the AGPL and their goal is to build the most open micro-blogging system out there.

So go over there now and claim your username!

OpenStreetMap/OpenLayers and Privoxy

I have been meaning to switch to OpenStreetMap for a while now, but the fact that it didn't work with Privoxy was holding me back. I don't enjoy surfing the web without protection and Privoxy is one of the most convenient ways of enhancing one's browsing experience on Debian and Ubuntu.

So I decided to spend some time trying to figure out what was wrong. If you want to skip the details and just get the fix, scroll down to the bottom of this post for the solution.

Finding all affected URLs

In order to get a list of all of the URLs that Privoxy filters when one visits the front page of OpenStreetMap, I did the following:

  • Added "debug 1" to /etc/privoxy/config

  • Restarted Privoxy: sudo /etc/init.d/privoxy restart

  • Cleared Firefox cache: Tools | Clear Private Data...

  • Loaded www.openstreetmap.org in Firefox

  • Copied from the Privoxy log (/var/log/privoxy/logfile) all requested URLs (except the image ones)

Comparing the files

Armed with the list of all affected URLs, I downloaded them through Privoxy using wget into a privoxy/ directory:

$ http_proxy=localhost:8118 wget URL

Then I downloaded the same URLs without Privoxy into a noproxy/ directory:

$ http_proxy= wget URL

To find identical files, I ran md5sums in each directory:

md5sum *

After deleting all identical files, I was left with:

index.html  
OpenLayers.js?1251388304

Which I diff'ed together:

colordiff -u noproxy/FILE privoxy/FILE

The first file, index.html did not have any relevant changes, but I noticed in the second one that a few of these

this.moveTo(this.position)

were replaced with

''.concat(this.position)

Searching for "concat" in /etc/privoxy/, I found that the "jumping-windows" filter was the culprit. After disabling it, all of the problems went away.

I have filed a bug upstream.

The Solution

Here's what you need to put in your /etc/privoxy/user.action:

{-filter{jumping-windows}}  
.openstreetmap.org