-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop redacting dates in GA4 tracking on GOVUK search pages
- Loading branch information
Showing
5 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,7 +297,7 @@ describe('GA4 core', function () { | |
|
||
it('standardises search terms for consistency across trackers', function () { | ||
var searchTerm = 'NO UPPERCASE, NO %2B plus + signs, NO PII [email protected] SW1A 2AA 1st Jan 1990 and NO extra spaces \n \r ' | ||
var expected = 'no uppercase, no plus signs, no pii [email] [postcode] [date] and no extra spaces' | ||
var expected = 'no uppercase, no plus signs, no pii [email] [postcode] 1st jan 1990 and no extra spaces' | ||
|
||
searchTerm = GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(searchTerm) | ||
expect(searchTerm).toEqual(expected) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,6 +375,34 @@ describe('Google Tag Manager page view tracking', function () { | |
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
||
it('doesn\'t remove date pii from the location if on a search page', function () { | ||
spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getSearch').and.returnValue('?keywords=2020-01-01') | ||
|
||
// We can't spy on location, so instead we use an anchor link to change the URL temporarily | ||
|
||
// Reset the URL so we can build the expected link string | ||
var linkForURLMock = document.createElement('a') | ||
linkForURLMock.href = '#' | ||
linkForURLMock.click() | ||
var location = document.location.href | ||
|
||
expected.page_view.location = location + '[email]/[postcode]?keywords=2020-01-01' | ||
expected.page_view.search_term = '2020-01-01' | ||
expected.page_view.query_string = 'keywords=2020-01-01' | ||
|
||
// Add personally identifiable information to the current page location | ||
linkForURLMock.href = '#[email protected]/SW12AA?keywords=2020-01-01' | ||
linkForURLMock.click() | ||
|
||
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init() | ||
|
||
// Reset the page location for other tests | ||
linkForURLMock.href = '#' | ||
linkForURLMock.click() | ||
|
||
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
||
it('can redact ga parameters as expected', function () { | ||
var url = 'https://www.gov.uk/welfare?' | ||
var param1 = '_ga=2.237932419.220854294.1692605006-1618308030.1687790776' | ||
|
@@ -558,20 +586,28 @@ describe('Google Tag Manager page view tracking', function () { | |
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
||
it('correctly sets the query_string parameter without PII date redaction if a search term exists', function () { | ||
spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getSearch').and.returnValue('?keywords=hello&query2=world&[email protected]&postcode=SW12AA&birthday=1990-01-01&_ga=19900101.567&_gl=19900101.567') | ||
expected.page_view.search_term = 'hello' | ||
expected.page_view.query_string = 'keywords=hello&query2=world&email=[email]&postcode=[postcode]&birthday=1990-01-01&_ga=[id]&_gl=[id]' | ||
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init() | ||
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
||
describe('search_term parameter', function () { | ||
describe('using the query parameter "keywords"', function () { | ||
it('correctly sets the parameter using ?keywords= with PII values redacted', function () { | ||
spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getSearch').and.returnValue('[email protected]+SW12AA+1990-01-01&another=one') | ||
expected.page_view.query_string = 'keywords=hello+world+[email]+[postcode]+[date]&another=one' | ||
expected.page_view.search_term = 'hello world [email] [postcode] [date]' | ||
expected.page_view.query_string = 'keywords=hello+world+[email]+[postcode]+1990-01-01&another=one' | ||
expected.page_view.search_term = 'hello world [email] [postcode] 1990-01-01' | ||
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init() | ||
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
||
it('correctly sets the parameter using &keywords= with PII values redacted', function () { | ||
it('correctly sets the parameter using &keywords= with PII values redacted except for dates', function () { | ||
spyOn(GOVUK.analyticsGa4.core.trackFunctions, 'getSearch').and.returnValue('?test=true&[email protected]+SW12AA+1990-01-01&another=one') | ||
expected.page_view.query_string = 'test=true&keywords=hello+world+[email]+[postcode]+[date]&another=one' | ||
expected.page_view.search_term = 'hello world [email] [postcode] [date]' | ||
expected.page_view.query_string = 'test=true&keywords=hello+world+[email]+[postcode]+1990-01-01&another=one' | ||
expected.page_view.search_term = 'hello world [email] [postcode] 1990-01-01' | ||
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init() | ||
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|
@@ -620,9 +656,9 @@ describe('Google Tag Manager page view tracking', function () { | |
document.body.removeChild(div) | ||
}) | ||
|
||
it('correctly sets the parameter with PII values redacted', function () { | ||
it('correctly sets the parameter with PII values redacted, except dates', function () { | ||
div.setAttribute('data-ga4-search-query', 'hello world [email protected] SW12AA 1990-01-01') | ||
expected.page_view.search_term = 'hello world [email] [postcode] [date]' | ||
expected.page_view.search_term = 'hello world [email] [postcode] 1990-01-01' | ||
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init() | ||
expect(window.dataLayer[0]).toEqual(expected) | ||
}) | ||
|