Skip to content

Instantly share code, notes, and snippets.

@yahelc
Created September 19, 2011 20:22
Show Gist options
  • Save yahelc/1227501 to your computer and use it in GitHub Desktop.
Save yahelc/1227501 to your computer and use it in GitHub Desktop.
Twitter Intents Events + Google Analytics Track Social
if (window.twttr) {
var event_names = ["click", "tweet","retweet","follow","favorite"];
for(var i = 0; i<event_names.length;i++)
{
twttr.events.bind(event_names[i], function(intent) {
if(intent)
{
var target = document.createElement("a");
target.href = decodeURIComponent(intent.target.src.match(/[&#?]url=([^&]*)/)[1]);
_gaq.push(["_trackSocial","Twitter", intent.type, target.href.replace(target.hash,""), target.pathname]);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment