diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js index 65c12167ba..cbb55d4b60 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js @@ -27,6 +27,10 @@ var UNLOCK_TOKEN_PATTERN = /unlock_token=[a-zA-Z0-9-]+/g var STATE_PATTERN = /state=.[^&]+/g + // prevent visa application IDs from being tracked, as some mistakenly use GOV.UK. to search for these. + var VISA_PATTERN_GWF = /GWF\d{9}/g + var VISA_PATTERN_GB = /GB\d{12}/g + function shouldStripDates () { var metas = document.querySelectorAll('meta[name="govuk:ga4-strip-dates"]') return metas.length > 0 @@ -97,6 +101,8 @@ stripped = stripped.replace(RESET_PASSWORD_TOKEN_PATTERN, 'reset_password_token=[reset_password_token]') stripped = stripped.replace(UNLOCK_TOKEN_PATTERN, 'unlock_token=[unlock_token]') stripped = stripped.replace(STATE_PATTERN, 'state=[state]') + stripped = stripped.replace(VISA_PATTERN_GWF, '[gwf number]') + stripped = stripped.replace(VISA_PATTERN_GB, '[gb eori number]') stripped = this.stripQueryStringParameters(stripped) if (this.stripDatePII === true) { diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.spec.js index e8edf59601..99d866b844 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.spec.js @@ -55,6 +55,11 @@ describe('GOVUK.analyticsGa4.PIIRemover', function () { arr = pii.stripPII(arr) expect(arr).toEqual(strippedArr) }) + + it('strips visa application numbers', function () { + var string = pii.stripPII('my visa application numbers are GWF123456789 and GB123456789000') + expect(string).toEqual('my visa application numbers are [gwf number] and [gb eori number]') + }) }) describe('by default for account specific PII', function () {