Google Analytics

Social Interactions - Web Tracking (analytics.js)

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

  1. Overview
  2. Implementation
  3. Examples
    1. Facebook
More

Overview

Social Interaction Analytics allows you 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 tracking measures 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.

By default, Google Analytics provides integrated reporting for the +1 Button. This means if you have implemented analytics.js and a +1 Button on the same page, all +1 interactions will be automatically reported as social interactions via each of the trackers on the page. For more information on +1 Analytics, including troubleshooting tips, see About Social Analytics in the Help Center.

Social interactions consist of three types of data:

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

Implementation

To send a social interaction, you pass the ga function the send command with the social hit type

ga('send', 'social', 'facebook', 'like', 'http://mycoolpage.com');

Where:

  • facebook is the socialNetwork
  • like is the socialAction
  • http://mycoolpage.com is the socialtarget

The send command also accepts an optional field object as the last parameter for any of these commands. The field object is a standard JavaScript object, but defines specific field names and values accepted by analytics.js.

For example, you might want to set the page field for a particular social interaction. You do this using:

ga('send', 'social', 'socialNetwork', 'socialAction', 'socialTarget', {'page': '/my-new-page'});

Finally, all the parameters of the send command have their own field names. So you can send a social interaction by only passing a configuration field object to the send command:

ga('send', {
  'hitType': 'social',
  'socialNetwork': 'facebook',
  'socialAction': 'like',
  'socialTarget': 'http://mycoolpage.com',
  'page': '/my-new-page'
});

Read the Field Reference document for a complete list of all the fields that can be used in the configuration field object.

Examples

Since specific details for integrating Social Analytics varies by social network, the rest of this guide provides general best practices on how to set up measure social interactions. We recommend you check the developer documentation for each network to figure out the network specific implementation.

Facebook

According to the Facebook JavaScript SDK, the simplest way to set up and measure a Like button on your page is to use the following code:

<script src="//connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like></fb:like>

Likes

To measure social interactions with this button, you subscribe to Facebook's edge.create event and create a callback function to execute the send command:

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

When a user Likes your page, the callback function is executed and receives the URL of the target being liked. The target is then passed as a value to the ga send method and the social interaction is sent to Google Analytics.







Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.