t.co and your web stats

Take a look at this screen shot from my Google Analytics dashboard.

These are all click-throughs from tweets. They are all referred by Twitter’s URL shortener (t.co). Unfortunately this data is fairly useless. I’d like to know who the influential tweeters are and what the tweets said. I could search Twitter for the full URLs, but Twitter search is – quite frankly – rubbish for this.

My initial reaction to this vague and seemingly obfuscated data was annoyance, but after doing some research I now see that this data is actually a bonus. That doesn’t mean it can’t be improved though.

How referrer tracking normally works

If the request to t.co contains a ‘Referer’ (sic) header, Twitter responds with a regular HTTP redirect. This type of redirect keeps the original referrer intact and so that is what goes into your web stats. This is what we’d like ideally like to see – to be able to click through to the actual tweet.

URL shorteners have their critics, but shorteners don’t in themselves prevent us seeing where our traffic originally came from.


There are circumstances under which your browser won’t send the original referrer to t.co when you click a link –

  1. If you’re not clicking from an actual Web page. (e.g. from an app or Twitter client)
  2. If you’re clicking from a secure web page (e.g. https://twitter.com/)

You’ve guessed it; this accounts for the huge majority of clicks from Tweets. Possibly all of them.

So why are we seeing t.co at all?

Without the referrer header, your stats would show these clicks as ‘direct traffic’. The reason t.co shows up at all is because Twitter do something different to other shorteners such as bit.ly.

If there is no referrer in the request to t.co and the user agent is a normal browser (i.e. you’re a human), Twitter responds with an HTML document containing both a JavaScript redirect and a meta refresh fallback. The upshot of this is that an interim web page is inserted in between the referring source and your target page. In this case t.co ends up in your web stats instead of the source.

A purist might argue that this breaks the web, but from an analytics perspective this is more useful than the clicks showing up as ‘direct traffic’. At least we know they’re from tweets.

Room for improvement

Obviously there are privacy issue with tracking users’ clicks, (hence the missing referrer in clicks over SSL) But for people with a public Twitter timeline it would be very handy if Twitter could provide richer data in t.co links beyond just where they link to. This could simply be X-Twitter-User-Id and/or X-Twitter-Tweet-Id headers in the response showing who originally shortened the URL and/or who is passing it on.

An API for this would be ideal, but of course Twitter have their own Analytics system, so I don’t expect they’ll want to make t.co any better for the non-paying customers.

Campaign tracking on the cheap

If you use Google Analytics and don’t pay for any fancy social media management tools, it’s very easy to embed Google Analytics campaign tracking tokens into your original URL.

This is the URL I use in my Twitblock tweet button:

All traffic clicking on the shortened t.co links will show up in the Campaign section of your traffic sources. If you forget the names of the parameters you can use this handy link builder.