This example page is part of a longer article available on my blog. If you have any questions or think there is something that would improve this example please get in touch!!
Facebook's Javascript SDK exposes several key events that we can use to track social engagement. The most commonly implemented features that you might want to track are:
To subscribe to these events you can use the following code:
FB.event.subscribe('edge.create', 'function(targetURL){
_gaq.push(['_trackSocial'], 'facebook', 'like', targetUrl]);
});
To add tracking to any Facebook interaction, you just need to replace the 'edge.create' with the event type you wish to track.
Twitter's Web Intents provide several key events that we can use to track interactions:
While most of them are self-explanatory the only one that might require a little more explanation is the click event. While Twitter's Documentation provides much greater detail than I can here, the click event basically provides extra detail about the part of a Tweet or Follow button that has been clicked.
Subscribing to these events is as simple as:
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]);
}
});
I've set up tracking on each of the social elements on this page, so have a look at the source code to see how they work.
I hope you've found this page useful, please share it if you have!