Skip to content

Commit

Permalink
Merge pull request #3680 from alphagov/ga4-filter-smokey-tests
Browse files Browse the repository at this point in the history
Prevent GA4 data sending during Smokey tests
  • Loading branch information
AshGDS authored Oct 26, 2023
2 parents 932738f + c75df71 commit 7fe224b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## Unreleased

* Add metadata inverse no padding option ([PR #3689](/~https://github.com/alphagov/govuk_publishing_components/pull/3689))
* Prevent GA4 data sending during Smokey tests ([PR #3680](/~https://github.com/alphagov/govuk_publishing_components/pull/3680))

## 35.20.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
firstScript.parentNode.insertBefore(newScript, firstScript)
},

getUserAgent: function () {
return navigator.userAgent
},

sendData: function (data) {
// Prevent any GA4 data being sent during Smokey tests
if (this.getUserAgent() === 'Smokey Test / Ruby') {
return
}

data.govuk_gem_version = this.getGemVersion()
// set this in the console as a debugging aid
if (window.GOVUK.analyticsGa4.showDebug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ describe('GA4 core', function () {
})
})

it('does not push data to the dataLayer if it is a Smokey test', function () {
spyOn(GOVUK.analyticsGa4.core, 'getUserAgent').and.returnValue('Smokey Test / Ruby')
var data = {
hello: 'I must be going'
}
GOVUK.analyticsGa4.core.sendData(data)
expect(window.dataLayer).toEqual([])
})

describe('link tracking functions', function () {
describe('find tracking attributes on elements', function () {
var element
Expand Down

0 comments on commit 7fe224b

Please sign in to comment.