Alfred App Extension for shortening links with Google analytics campaign tracking and pro

This is a simple script I use to consistently embed Google Analytics campaign tracking code within short urls. The approach is similar to my Klout user score look-up: it uses Alfred App Powerpack extensions (and Growl)

The GA tracking code lets us know how our overall “direct social” efforts are performing and shows with sources (Twitter, Facebook, LinkedIn) are performing best.

(I’ve stored my bitly.API_KEY and bitty.API_LOGIN in the bitly library in my python path. Get a copy of the library here.)


import sys
import bitly

if len(sys.argv) < 2:
if len(sys.argv) == 3:
	if sys.argv[2] == 'facebook':
		short_url = bitly.shorten(sys.argv[1]+"?utm_source=facebook&utm_medium=social&utm_campaign=sm-direct")
	elif sys.argv[2] == 'linkedin':
		short_url = bitly.shorten(sys.argv[1]+"?utm_source=linkedin&utm_medium=social&utm_campaign=sm-direct")
	elif sys.argv[2] == 'twitter':
		short_url = bitly.shorten(sys.argv[1]+"?utm_source=twitter&utm_medium=social&utm_campaign=sm-direct")
	short_url = bitly.shorten(sys.argv[1]+"?utm_source=twitter&utm_medium=social&utm_campaign=sm-direct")


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s