From 92d990da232015a0720f7baa9a5e8da9db864c47 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Thu, 12 Sep 2019 09:10:18 +0100 Subject: [PATCH] Use pii code in cross linker - avoids duplication, already had email stripping code - also now includes dates and postcodes --- .../google-analytics-universal-tracker.js | 11 +++++------ .../google-analytics-universal-tracker.spec.js | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/analytics_toolkit/google-analytics-universal-tracker.js b/app/assets/javascripts/analytics_toolkit/google-analytics-universal-tracker.js index 7556c43df..1b463c3ad 100644 --- a/app/assets/javascripts/analytics_toolkit/google-analytics-universal-tracker.js +++ b/app/assets/javascripts/analytics_toolkit/google-analytics-universal-tracker.js @@ -3,6 +3,9 @@ var $ = global.jQuery var GOVUK = global.GOVUK || {} + var pii = new GOVUK.pii() + pii.stripDatePII = true + pii.stripPostcodePII = true var GoogleAnalyticsUniversalTracker = function (trackingId, fieldsObject) { function configureProfile () { @@ -26,7 +29,8 @@ } function stripLocationPII () { - sendToGa('set', 'location', stripEmailAddressesFromString(window.location.href)) + console.log(pii.stripPII(window.location.href)) + sendToGa('set', 'location', pii.stripPII(window.location.href)) } // Support legacy cookieDomain param @@ -183,11 +187,6 @@ } } - function stripEmailAddressesFromString (string) { - var stripped = string.replace(/[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g, '[email]') - return stripped - } - GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker global.GOVUK = GOVUK diff --git a/spec/javascripts/analytics_toolkit/google-analytics-universal-tracker.spec.js b/spec/javascripts/analytics_toolkit/google-analytics-universal-tracker.spec.js index 4b6cc35be..4e0a6f8ec 100644 --- a/spec/javascripts/analytics_toolkit/google-analytics-universal-tracker.spec.js +++ b/spec/javascripts/analytics_toolkit/google-analytics-universal-tracker.spec.js @@ -190,9 +190,12 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () { }) describe('when tracking all events', function () { - window.history.replaceState(null, null, '?address=an.email@digital.cabinet-office.gov.uk') - it('removes any email address from the location', function () { + window.history.replaceState(null, null, '?address=an.email@digital.cabinet-office.gov.uk&postcode=sw11wa&date=2019-01-01') + + it('removes any pii from the location', function () { expect(window.ga.calls.mostRecent().args[2]).toContain('address=[email]') + expect(window.ga.calls.mostRecent().args[2]).toContain('postcode=[postcode]') + expect(window.ga.calls.mostRecent().args[2]).toContain('date=[date]') }) })