Skip to content

Instantly share code, notes, and snippets.

@aranw
Created December 6, 2011 14:38
Show Gist options
  • Save aranw/1438402 to your computer and use it in GitHub Desktop.
Save aranw/1438402 to your computer and use it in GitHub Desktop.
Google Analytics Social Tracking Code
(function (b) {
(function (a) {
"__CF" in b && "DJS" in b.__CF ? b.__CF.DJS.push(a) : "addEventListener" in b ? b.addEventListener("load", a, !1) : b.attachEvent("onload", a)
})(function () {
"FB" in b && "Event" in FB && "subscribe" in FB.Event && (FB.Event.subscribe("edge.create", function (a) {
_gaq.push(["_trackSocial", "facebook", "like", a])
}), FB.Event.subscribe("edge.remove", function (a) {
_gaq.push(["_trackSocial", "facebook", "unlike", a])
}), FB.Event.subscribe("message.send", function (a) {
_gaq.push(["_trackSocial", "facebook", "send", a])
}));
"twttr" in b && "events" in twttr && "bind" in twttr.events && twttr.events.bind("tweet", function (a) {
if (a) {
var b;
if (a.target && a.target.nodeName == "IFRAME") a: {
if (a = a.target.src) {
a = a.split("#")[0].match(/[^?=&]+=([^&]*)?/g);
b = 0;
for (var c; c = a[b]; ++b) if (c.indexOf("url") === 0) {
b = unescape(c.split("=")[1]);
break a
}
}
b = void 0
}
_gaq.push(["_trackSocial", "twitter", "tweet", b])
}
})
})
})(window);
@aranw
Copy link
Author

aranw commented Dec 6, 2011

Credit for this code goes to @craigmdennis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment