Ubuntu / Linux news and application reviews.

Track clicks on short URLs from Twitter with Google Analytics for your own links that is.


Because of the url shortening services, you will see clicks on short urls from Twitter tools that redirect to your website as direct hits. Yeah, you can see those coming from Twitter.com, but most of the people using Twitter never even visit twitter.com. Yoast published an article for how to use it with short url service http://cli.gs but i did what he said in that post and yet it didn't work for me. Also, you need a server to upload a file and so on, while it can be done in a much easier way. Here's how to do it using a simple bookmarklet / no extenral php file needed:

1. bookmarklet to use with api (if you want individual statistics for links on http://cli.gs - requires an account on http://cli.gs and then an api key): create a new bookmark with this code in it:


javascript:(function(){%20window.open('http://cli.gs/api/v1/cligs/create?url='+encodeURIComponent(location.href+'?utm_campaign=blog&utm_source=twitter&utm_medium=micro-blog')+'&title='+encodeURIComponent(document.title)+'&key=YOUR_API_KEY'+'&appid=77');%20})();


Of course, replace YOUR_API_KEY with ... your api key :)

2. bookmarklet to use without an account: create a new bookmark with this code in it:

javascript:(function(){%20window.open('http://cli.gs/cligs/new?url='+encodeURIComponent(location.href'?utm_campaign=blog&utm_source=twitter&utm_medium=micro-blog')+'&title='+encodeURIComponent(document.title));%20})();


When you are on a page you wish to shorten url and track, click the bookmarklet and and there you have it: the short url with GA campaign tracking in it.

Now some explainations on how this tracks clicks to short urls using Google Analytics.


This method of tracking uses Google Analytics' campaign tracking feature. It will track anyone visiting the site as a result of your tweet, regardless of where they clicked on the URL. It doesn’t matter if it’s in an email client, hosted email app. etc. This is the secret to tracking tweets with GA: adding campaign information to your short url. The campaign information in the URL will bucket the visitor as part of the blog campaign and as someone who was reached by the ‘micro-blogging’ medium. Here’s how the data looks in the All Traffic Sources report:



twitter GA