Social Interactions

This guide describes how to measure social interactions using analytics.js.

Overview

You can use social interaction analytics to measure the number of times users click on social buttons embedded in webpages. For example, you might measure a Facebook "Like" or a Twitter "Tweet".

While event measurement can help you analyze general user-interactions very well, Social Analytics provides a consistent framework for recording social interactions. This in turn provides a consistent set of reports to compare social network interactions across multiple networks.

If you're unfamiliar with social interactions in Google Analytics, or you're not sure what values to use for the social network, action, or target, you should first read the article About Social plugins and interactions in the Analytics Help Center.

Implementation

Social interaction hits can be sent using the send command and specifying a hitType of social. The send command has the following signature for the social hit type:

ga('send', 'social', [socialNetwork], [socialAction], [socialTarget], [fieldsObject]);

Social interaction fields

The following table summarizes the social interaction fields:

Field Name Value Type Required Description
socialNetwork text yes The network on which the action occurs (e.g. Facebook, Twitter)
socialAction text yes The type of action that happens (e.g. Like, Send, Tweet).
socialTarget text yes Specifies the target of a social interaction. This value is typically a URL but can be any text. (e.g. http://mycoolpage.com)

For a more in-depth description of each of these fields, see Data collection in the Analytics Help Center.

Examples

The following command sends a social interaction hit to Google Analytics indicating that a Facebook like button was clicked for the site http://myownpersonaldomain.com:

ga('send', 'social', 'Facebook', 'like', 'http://myownpersonaldomain.com');

Note that as with all send commands, the fields passed in the convenience parameters may also be specified in the fieldsObject. The above command could be rewritten as:

ga('send', {
  hitType: 'social',
  socialNetwork: 'Facebook',
  socialAction: 'like',
  socialTarget: 'http://myownpersonaldomain.com'
});

Facebook

If you use the official Facebook Like buttons and subscribe to the edge.create event, when a Like action happens, you are notified.

FB.Event.subscribe('edge.create', function(url) {
  ga('send', 'social', 'facebook', 'like', url);
});

For more details, refer to the Facebook JavaScript SDK.