How To Use The ReTweet BlogEngine.net Twitter Extension To Track Short URLs With bit.ly and Google Analytics

by Chris Arkwright | Sunday, July 26, 2009  

If you are using the ReTweet on your BlogEngine.net site, then you may be interested in this.

I recently made another post on our blog regarding an update to the code that allows the use of special characters in the title through URL encoding. You can see that original post here.

This is a second code update that allows one to track the short URL via Google Analytics.

Assuming that you have already installed the Google Analytics tracking code on your site, you can track short URLs by updating the following code of the retweet.cs file.


Line 93: string address = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" + url + System.Web.HttpUtility.UrlEncode("?utm_source=twitter&utm_medium=social-media&utm_term=&utm_content=from-twitter-account&utm_campaign=test-campaign") + "&login=" + bitlyUserName + "&apiKey=" + bitlyApiKey + "&history=" + activateHistory;

 

The emboldened part of the code above is the trick. It URL encodes the necessary tracking parameters in order to prevent from interfering with the bit.ly API. Of course you can change the underlined variables to reflect whatever you want to show up in Google Analytics.

This is super useful for tracking activity through Twitter.

For more information on building tracking URLs for use with Google Analytics, check out their URL Builder.


Filed Under:

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading