Skip to content

Commit

Permalink
Add discovery_engine_attribution_token to GA4 pageview
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Mar 25, 2024
1 parent d41506c commit 832b8fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -62,7 +62,8 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
intervention: this.getBannerPresence('[data-ga4-intervention-banner]'),
query_string: this.getQueryString(),
search_term: this.getSearchTerm(),
spelling_suggestion: this.getMetaContent('spelling-suggestion')
spelling_suggestion: this.getMetaContent('spelling-suggestion'),
discovery_engine_attribution_token: this.getMetaContent('discovery-engine-attribution-token')
}
}
window.GOVUK.analyticsGa4.core.sendData(data)
Expand Down
Expand Up @@ -60,7 +60,8 @@ describe('Google Tag Manager page view tracking', function () {
intervention: undefined,
query_string: undefined,
search_term: undefined,
spelling_suggestion: undefined
spelling_suggestion: undefined,
discovery_engine_attribution_token: undefined
}
}
spyOn(GOVUK.analyticsGa4.core, 'getTimestamp').and.returnValue('123456')
Expand Down Expand Up @@ -644,4 +645,11 @@ describe('Google Tag Manager page view tracking', function () {
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init()
expect(window.dataLayer[0]).toEqual(expected)
})

it('correctly sets the discovery_engine_attribution_token parameter', function () {
createMetaTags('discovery-engine-attribution-token', 'searchyMcSearch')
expected.page_view.discovery_engine_attribution_token = 'searchyMcSearch'
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init()
expect(window.dataLayer[0]).toEqual(expected)
})
})

0 comments on commit 832b8fb

Please sign in to comment.