From 8a98c73b080c1dcc8c8c0059d1981b05180527f3 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 20 Feb 2020 11:03:03 +0000 Subject: [PATCH] Make analytics send the same title for all pages Sets it on the tracker which means this value gets sent for each: - pageview - event See: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages We can only test that this has been set on the tracker, not how that effects what is sent to GA, in the JS tests. This change has been tested in-browser with the Chrome Analytics Debugger. This revealed the contents of what is in the beacon sent to GA and allowed confirmation the title was being set correctly. See: https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna/related --- app/assets/javascripts/analytics/analytics.js | 1 + tests/javascripts/analytics/analytics.test.js | 1 + tests/javascripts/analytics/init.test.js | 6 +++--- tests/javascripts/cookieSettings.test.js | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/analytics/analytics.js b/app/assets/javascripts/analytics/analytics.js index 711f6ec80..a776f93a2 100644 --- a/app/assets/javascripts/analytics/analytics.js +++ b/app/assets/javascripts/analytics/analytics.js @@ -15,6 +15,7 @@ window.ga('set', 'anonymizeIp', config.anonymizeIp); window.ga('set', 'allowAdFeatures', config.allowAdFeatures); window.ga('set', 'transport', config.transport); + window.ga('set', 'title', 'GOV.UK Notify'); }; diff --git a/tests/javascripts/analytics/analytics.test.js b/tests/javascripts/analytics/analytics.test.js index ea4b91fe2..1f11544e8 100644 --- a/tests/javascripts/analytics/analytics.test.js +++ b/tests/javascripts/analytics/analytics.test.js @@ -52,6 +52,7 @@ describe("Analytics", () => { expect(setUpArguments[1]).toEqual(['set', 'anonymizeIp', true]); expect(setUpArguments[2]).toEqual(['set', 'allowAdFeatures', false]); expect(setUpArguments[3]).toEqual(['set', 'transport', 'beacon']); + expect(setUpArguments[4]).toEqual(['set', 'title', 'GOV.UK Notify']); }); diff --git a/tests/javascripts/analytics/init.test.js b/tests/javascripts/analytics/init.test.js index 8384b826f..6bf7a31c8 100644 --- a/tests/javascripts/analytics/init.test.js +++ b/tests/javascripts/analytics/init.test.js @@ -111,10 +111,10 @@ describe("Analytics init", () => { test("A pageview will be registered", () => { - expect(window.ga.mock.calls.length).toEqual(5); + expect(window.ga.mock.calls.length).toEqual(6); - // The first 4 calls configure the analytics tracker. All subsequent calls send data - expect(window.ga.mock.calls[4]).toEqual(['send', 'pageview', '/privacy']); + // The first 5 calls configure the analytics tracker. All subsequent calls send data + expect(window.ga.mock.calls[5]).toEqual(['send', 'pageview', '/privacy']); }); diff --git a/tests/javascripts/cookieSettings.test.js b/tests/javascripts/cookieSettings.test.js index a6c6f1344..4bc85a213 100644 --- a/tests/javascripts/cookieSettings.test.js +++ b/tests/javascripts/cookieSettings.test.js @@ -231,8 +231,8 @@ describe("Cookie settings", () => { expect(window.GOVUK.initAnalytics).toHaveBeenCalled(); expect(window.ga).toHaveBeenCalled(); - // the first 4 calls are configuration - expect(window.ga.mock.calls[4]).toEqual(['send', 'pageview', '/privacy']); + // the first 5 calls are configuration + expect(window.ga.mock.calls[5]).toEqual(['send', 'pageview', '/privacy']); });