Skip to content

Commit

Permalink
Add analytics dimension for A/B tests
Browse files Browse the repository at this point in the history
Link meta tags named `govuk:ab-test` to a custom Google Analytics
dimension. The value of the meta tag and the dimension is a combination
of the test name and bucket name, such as `EducationNavigation:B`.

This links to existing Session dimension 13, which has been used for A/B
tests in the past.

Note that only one A/B test can use this dimension at once, otherwise
the value will be overridden by different tests.
  • Loading branch information
suzannehamilton committed Feb 1, 2017
1 parent d00183f commit 6b23be6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/analytics/static-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
this.setOrganisationsDimension(dimensions['analytics:organisations']);
this.setWorldLocationsDimension(dimensions['analytics:world-locations']);
this.setRenderingApplicationDimension(dimensions['rendering-application']);
this.setAbTestDimension(dimensions['ab-test']);
};

StaticAnalytics.prototype.trackPageview = function(path, title, options) {
Expand Down Expand Up @@ -156,5 +157,9 @@
this.setDimension(21, position);
};

StaticAnalytics.prototype.setAbTestDimension = function(testNameAndBucket) {
this.setDimension(40, testNameAndBucket);
};

GOVUK.StaticAnalytics = StaticAnalytics;
})();
2 changes: 2 additions & 0 deletions spec/javascripts/analytics/static-analytics-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe("GOVUK.StaticAnalytics", function() {
<meta name="govuk:political-status" content="historic">\
<meta name="govuk:analytics:organisations" content="<D10>">\
<meta name="govuk:analytics:world-locations" content="<W1>">\
<meta name="govuk:ab-test" content="name-of-test:name-of-ab-bucket">\
');

analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
Expand All @@ -74,6 +75,7 @@ describe("GOVUK.StaticAnalytics", function() {
expect(universalSetupArguments[8]).toEqual(['set', 'dimension7', 'historic']);
expect(universalSetupArguments[9]).toEqual(['set', 'dimension9', '<D10>']);
expect(universalSetupArguments[10]).toEqual(['set', 'dimension10', '<W1>']);
expect(universalSetupArguments[11]).toEqual(['set', 'dimension40', 'name-of-test:name-of-ab-bucket']);
});

it('ignores meta tags not set', function() {
Expand Down

0 comments on commit 6b23be6

Please sign in to comment.