Tracking Facebook OpenGraph Referrals in Google Analytics

Facebook Insights aren’t always predictable, and don’t give you an accurate picture of how much of your traffic is coming from FB. You can track this with the following code snippet:

window.param = function(name) {
return decodeURIComponent((new RegExp(‘[?|&]’ + name + ‘=’ + ‘([^&;]+?)(&|#|;|$)’).exec(||[,””])[1].replace(/+/g, ‘%20’))||null;
var ref = param(“fb_ref”),
source = param(“fb_source”);
source && _gaq.push([‘_trackEvent’, “FB”, source, ref]);