In a previous post I explained how you can use Google Analytics to track social button and contact form on multiple pages. The previous code was implemented using GA’s _trackEvent method purely because back then Google did not have a specific method for social interaction tracking. In this post I will give you an overview of tracking social interactions with _trackSocial method which has recently been introduced to GA.

_trackSocial is a GA method which essentially sends social interaction data over to Google Analytics. This method can only be called after the user has completed a social interaction such as clicking Google +1 button. Please remember every social network has their own specific way of implementing their social buttons, therefore you might have to adapt this _trackSocial method to work with your social network of choice.

The TrackSocial Method:

The _trackSocial method has four parameters, of which two are required and two are optional. The required parameters are “network” and “socialAction”, the optional parameters are “opt_target” and “opt_pagePath”.

Here is a quick overview of what each parameters represent:

  • network A string representing the social network being tracked (e.g. Facebook, Twitter, LinkedIn)
  • socialAction A string representing the social action being tracked (e.g. Like, Share, Tweet)
  • opt_target A string representing the URL (or resource) which receives the action.
  • opt_pagePath A string representing the page by path (including parameters) from which the action occurred.

Implementing _trackSocial:

You should always consider GA’s queueing command, this will ensure that the _trackSocial method will get executed regardless of your website or CMS using the traditional or asynchronous GA tracking code.

Tracking Facebook Likes:

To track Likes with Google Analytics, subscribe to Facebook’s edge.create event and create a callback function to execute the Google Analytics tracking code.

FB.Event.subscribe('edge.create', function(targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);

When a user Likes your page, the callback function is executed and receives the URL of the resource being liked. The resource is then passed as a value to the _trackSocial method so Google Analytics can report on the network, action and URL being liked.

Tracking Facebook Unlikes:

If you would like to track Facebook Unlikes then you need to invoke the Facebook API as indicated below.

FB.Event.subscribe('edge.remove', function(targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);