To validate tracking of Content Grouping, use the following Array in your Jasmine expectations:
['set', 'contentGrouping1', 'Product Pages']
│ │ └───────────> 3. Content Grouping Value
│ └───────────────────────────────> 2. Content Grouping Index
└──────────────────────────────────────> 1. (Standard Google Analytics parameter)
Using direct ga()
calls, checking proper tracking of Content Grouping could be done in the following manner:
describe('The Google Analytics "Content Grouping" 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 register a Content Grouping when loading the page', 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) {
expect( LastData ).toEqual( ['set', 'contentGrouping1', 'Product Pages'] );
},
// 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);
});
});