Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass cohort name to universal analytics set dimension #251

Merged
merged 2 commits into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var test = new GOVUK.MultivariateTest({
});
```

`customDimensionIndex` is the index of the custom variable in Google Analytics. GA only gives 50 integer slots to each account, and it is important that a unique integer is assigned to each test. Current contact for assigning a custom var slot for GOV.UK is: Ashraf Chohan <ashraf.chohan@digital.cabinet-office.gov.uk>
`customDimensionIndex` is the index of the custom variable in Google Analytics. GA only gives 50 integer slots to each account, and it is important that a unique integer is assigned to each test. Current contact for assigning a custom var slot for GOV.UK is: Tim Leighton-Boyce <tim.leighton-boyce@digital.cabinet-office.gov.uk>

## Primary Links

Expand Down
4 changes: 1 addition & 3 deletions javascripts/govuk/multivariate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
if (this.customDimensionIndex) {
GOVUK.analytics.setDimension(
this.customDimensionIndex,
this.cookieName(),
cohort,
2 // session level
this.cookieName() + "__" + cohort
);
}
};
Expand Down
17 changes: 13 additions & 4 deletions spec/unit/multivariate-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("MultivariateTest", function() {
expect(fooSpy).toHaveBeenCalled();
});

it("should set a custom var if one is defined", function() {
it("should set a custom var with the name and cohort if one is defined", function() {
GOVUK.cookie.and.returnValue('foo');
var test = new GOVUK.MultivariateTest({
name: 'stuff',
Expand All @@ -59,10 +59,19 @@ describe("MultivariateTest", function() {
});
expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
2,
'multivariatetest_cohort_stuff',
'foo',
2
'multivariatetest_cohort_stuff__foo'
);
});

it("should trigger an event to track that the test has been run", function() {
GOVUK.cookie.and.returnValue('foo');
var test = new GOVUK.MultivariateTest({
name: 'stuff',
cohorts: {
foo: {},
bar: {}
},
});
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
'multivariatetest_cohort_stuff',
'run',
Expand Down