public
Created

Facebook Like Button Google Analytics

  • Download Gist
ga-facebook.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// This assumes Facebook buttons are using the Facebook Javascript SDK.
// Thanks to Google for most of this code, see the Social Interaction Analytics guide at
// https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
 
// Facebook provides a Javascript event framework that allows you to subscribe to events
// happening within the Facebook Javascript SDK and provides data accordingly.
 
// To track a like, subscribe to the edge.create event and then use the callback to
// execute the Analytics tracking code:
 
FB.Event.subscribe('edge.create', function(targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
});
 
// To track an unlike, subscribe to the edge.remove event and then use the callback to
// execute the Analytics tracking code:
 
FB.Event.subscribe('edge.remove', function(targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
});
 
// To track a share, subscribe to the message.send event and then use the callback to
// execute the Analytics tracking code:
 
FB.Event.subscribe('message.send', function(targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.