Bit.ly offers a very simple API for creating short URLs. The service can also provide you with some basic click statistics. Unfortunately there are a few missing pieces to the API. To get around that you’ll have to keep a list of bit.ly links you want to track. Depending on your situation you may need to keep some of the information updated regularly and stored locally to do a deeper analysis of your links.
There are a couple of advanced tricks you can use to get more out of your tracking.
- Add GET arguments to the end of the URL to split test
- Look at stats for any bit.ly link including referring sites, real-time click time-lines, and locations by adding a + to the end of it: http://bit.ly/10HYCo+
- Find out which other bit.ly users have shortened a link using the API – google.com bitly info
– If you want to track clicks from different sources that land at the same page you need use different links. The easiest way to create two links to the same page is to append a GET argument. So if you wanted to promote my site http://halotis.com and wanted to compare Twitter to AdWords then you could create bit.ly links to http://halotis.com?from=twitter and http://halotis.com?from=adwords. You can add more information with more arguments such as http://halotis.com/?from=adwords&adgroup=group1. If you control the landing page, then you will see those arguments in Google Analytics and will have even more information about who clicked your links.
import bitly #http://code.google.com/p/python-bitly/ BITLY_LOGIN = "YOUR_BITLY_LOGIN" BITLY_API_KEY = "YOUR_BITLY_API_KEY" short_url='http://bit.ly/31IqMl' b = bitly.Api(login=BITLY_LOGIN,apikey=BITLY_API_KEY) stats = b.stats(short_url) print "%s - User clicks %s, total clicks: %s" % (short_url, stats.user_clicks, stats.total_clicks)