How do I apply Google Analytics to the follow button?


#1

I am trying to add google analytics tracking to see how many people click the follow button on a page I am building. I have looked at the developer code below and was wondering do I need to wrap it in some kind of call back function

// First, load the widgets.js file asynchronously window.twttr = (function (d,s,id) { var t, js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } }); }(document, "script", "twitter-wjs"));

// Define our custom event handlers
function clickEventToAnalytics (intentEvent) {
if (!intentEvent) return;
var label = intentEvent.region;
pageTracker._trackEvent(‘twitter_web_intents’, intentEvent.type, label);
}

function tweetIntentToAnalytics (intentEvent) {
if (!intentEvent) return;
var label = “tweet”;
pageTracker._trackEvent(‘twitter_web_intents’, intentEvent.type, label);
}

function favIntentToAnalytics (intentEvent) {
tweetIntentToAnalytics(intentEvent);
}

function retweetIntentToAnalytics (intentEvent) {
if (!intentEvent) return;
var label = intentEvent.data.source_tweet_id;
pageTracker._trackEvent(‘twitter_web_intents’, intentEvent.type, label);
}

function followIntentToAnalytics (intentEvent) {
if (!intentEvent) return;
var label = intentEvent.data.user_id + " (" + intentEvent.data.screen_name + “)”;
pageTracker._trackEvent(‘twitter_web_intents’, intentEvent.type, label);
}

// added this code to track follows Probably wrong

function followIntentToAnalytics (intentEvent) {
if (!intentEvent) return;
var label = intentEvent.data.user_id + " (" + intentEvent.data.screen_name + “)”;
pageTracker._trackSocial(‘twitter’, ‘follow’, ‘myTwitterHandleHere’);
}

// Wait for the asynchronous resources to load
twttr.ready(function (twttr) {
// Now bind our custom intent events
twttr.events.bind(‘click’, clickEventToAnalytics);
twttr.events.bind(‘tweet’, tweetIntentToAnalytics);
twttr.events.bind(‘retweet’, retweetIntentToAnalytics);
twttr.events.bind(‘favorite’, favIntentToAnalytics);
twttr.events.bind(‘follow’, followIntentToAnalytics);
});


#2

Ben,

Were you able to get that code working? I’m trying to do the same thing but I haven’t been able to get the intent events to fire.


#3