Search code examples
google-analyticstwitteranalyticsgoogle-analytics-api

Tracking tweets from webpage with Google Analytics


According to Google Analytic's documentation on social tracking, I'm supposed to run this code to notify GA when there's been a tweet:

twttr.events.bind('tweet', function(event) {
  if (event) {
    var targetUrl;
    if (event.target && event.target.nodeName == 'IFRAME') {
      targetUrl = extractParamFromUri(event.target.src, 'url');
    }
    _gaq.push(['_trackSocial', 'twitter', 'tweet', targetUrl]);
  }
});

However, I get an error stating twttr is not defined. How do I get notified of a tweet from my tweet button on my site so that I can track it?


Solution

  • Verify you have included the correct code for the twitter button?describe here

    After that open up the console on firebug and write twttr and hit enter. It should return the twttr Object.

    enter image description here

    If not verify that your tracking code is below the twitter include script (the one that actually creates the twttr Object)

    HTH