Tracking Custom Dimensions

Google Analytics Data Structure

To validate tracking of Custom Dimensions, use the following Array in your Jasmine expectations:

['set', 'dimension1', 'Visitor']
  │      │             └─────────────────> 3. Dimension Value
  │      └───────────────────────────────> 2. Dimension Index
  └──────────────────────────────────────> 1. (Standard Google Analytics parameter)

Sample Jasmine Spec File

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

describe('The Google Analytics "Dimension" tracking', function () {
   beforeEach(function () {
      // Load the page to test:

      // Register the Google Analytics Event Data Interceptor:
   it('should fire a Dimension when clicking on the Jumbotron CTA', function (done) {
      // Click on the "Jumbotron" CTA:
      element( by.css('#jumbotronCTA') ).click();
      // Get the "LastEvent" object back from the browser:
      browser.driver.executeScript(function () {
         return window.GAWebTester.getLastEvent();
         // Validate the content of the "LastData" object:
         function successCallback (LastData) {
            expect( LastData ).toEqual( ['set', 'dimension1', 'Visitor'] );
         // 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));