• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Editing the FB.init code to enable Social Interaction Tracking

#1
I'm trying to add Google Analytics new Social Interaction Tracking and need to add some code after FB.init. What would be the best way to do this since the code isn't available from the template files?

HTML:
window.fbAsyncInit = function() {
  FB.init({appId: '<APPID>', status: true, cookie: true, xfbml: true});
  FB.Event.subscribe("edge.create",function(response) {
    if (response.indexOf("facebook.com") > 0) {
      _gaq.push(['_trackSocial','facebook','fan',response]);
    } else {
      _gaq.push(['_trackSocial','facebook','like',response]);
    }
  });
FB.Event.subscribe("edge.remove",function(response) {
  if (response.indexOf("facebook.com") > 0) {
    _gaq.push(['_trackSocial','facebook','unfan',response]);
  } else {
    _gaq.push(['_trackSocial','facebook','unlike',response]);
  }
});
FB.Event.subscribe("message.send", function(response) {
    _gaq.push(['_trackSocial','facebook','send',response]);
});
};
 

digitalpoint

Well-known member
#2
You don't need to do it during FB.init... you can do it after the fact just fine via your own JavaScript... FB.init needs to be called first, but it can be 10 minutes earlier (as an example) and binding the callbacks would still work.

This means you can just have your own JavaScript file that is included after FB.init is called.

We do the same thing for our Tweet button as well. You might find this post useful: http://xenforo.com/community/threads/better-google-analytics.21559/#post-272530