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?
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.
If not verify that your tracking code is below the twitter include script (the one that actually creates the twttr Object)
HTH
If you are loading the Twitter API asynchronously, you need to wrap the twttr.events
functions inside the following:
twttr.ready(function(twttr) {
});
This way it will wait for the async resources to finish loading before trying to access them.
You can see more here:
Twitter Documentation
If you wrap a check for the type of the twttr object then that will fix it:
// Twitter API 'Tweet' button tracking
if (typeof(twttr) != 'undefined') {
twttr.events.bind('click', function(event) {
_gaq.push(['_trackSocial', 'twitter', 'tweet', document.location.href, location.pathname]);
});
}
精彩评论