Tracking Social Interactions

Google Analytics Data Structure

To validate tracking of Social Interactions, use the following Array in your Jasmine expectations:

['send', 'social', { ─────────────────────> 1&2. (Standard Google Analytics parameters)
    'socialNetwork': 'Facebook', ─────────> 3. Social Interaction Network
    'socialAction': 'Like', ──────────────> 4. Social Interaction Action
    'socialTarget': 'http://example.com' ─> 5. Social Interaction Target (URL)
}]

Sample Jasmine Spec File

Using direct ga() calls, checking proper tracking of Social Interactions could be done in the following manner:

describe('The Google Analytics "Social Interactions" tracking', function () {
   beforeEach(function () {
      // Load the page to test:
      browser.get('index.html');

      // Register the Google Analytics Event Data Interceptor:
      browser.driver.registerGoogleAnalyticsEventDataInterceptor();
   });
 
   it('should fire a Social Interaction when clicking on the "Facebook Like" button', function (done) {
      // Click on the "Facebook Like" Button:
      element( by.css('#facebookLike') ).click();
 
      // Get the "LastEvent" object back from the browser:
      browser.driver.executeScript(function () {
         return window.GAWebTester.getLastEvent();
      })
      .then(
         // Validate the content of the "LastData" object:
         function successCallback (LastData) {
            expect( LastData ).toEqual( ['send', 'social', {
               'socialNetwork': 'Facebook',
               'socialAction': 'Like',
               'socialTarget': 'http://example.com'
            }] );
         },
         // If there was an error getting back the "LastData" object from the browser, fail the test:
         function errorCallback (error) {
            fail('Should not have received Error: ' + JSON.stringify(error));
         }
      )
      .then(done);
   });
});