Tracking User Timings

Google Analytics Data Structure

To validate tracking of User Timings, use the following Array in your Jasmine expectations:

['send', 'timing', { ────────────────────> 1&2. (Standard Google Analytics parameters)
    'timingCategory': 'External Libs', ──> 3. Timing Category
    'timingVar': 'Load Time', ───────────> 4. Timing Variable
    'timingValue': 123, ─────────────────> 5. Timing Value (in ms)
    'timingLabel': 'jQuery' ─────────────> 6. Timing Label
}]

Sample Jasmine Spec File

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

describe('The Google Analytics "User Timing" 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 User Timing when loading the jQuery library', function (done) {
      // 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) {
            // "LastData" will be similar to the following. Due to
            // the inability to know the exact value of "timingValue"
            // beforehand, it it necessary to work around the data:
            //
            // ['send', 'timing', {
            //    'timingCategory': 'External Libs',
            //    'timingVar': 'Load Time',
            //    'timingValue': 123,
            //    'timingLabel': 'jQuery'
            // }]

            expect( LastData[0] ).toEqual( 'send' );
            expect( LastData[1] ).toEqual( 'timing' );
            expect( LastData[2].timingCategory ).toEqual( 'External Libs' );
            expect( LastData[2].timingVar ).toEqual( 'Load Time' );
            expect( typeof LastData[2].timingValue ).toEqual( 'number' );
            expect( LastData[2].timingLabel ).toEqual( 'jQuery' );
         },
         // 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);
   });
});