Skip to content

Commit

Permalink
Merge pull request #3523 from alphagov/ga4-ab-test-pageview-attribute
Browse files Browse the repository at this point in the history
Add GA4 pageview meta tag: ab_test
  • Loading branch information
AshGDS authored Jul 27, 2023
2 parents 15571c3 + 0160367 commit 9b3d508
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Add GA4 pageview meta tag: ab_test ([PR #3523](https://github.com/alphagov/govuk_publishing_components/pull/3523))

## 35.13.0

* Fix 100% scroll problem ([PR #3521](https://github.com/alphagov/govuk_publishing_components/pull/3521))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
title: this.getTitle(),
status_code: this.getStatusCode(),

ab_test: this.getMetaContent('ab-test'),
document_type: this.getMetaContent('format'),
publishing_app: this.getMetaContent('publishing-app'),
rendering_app: this.getMetaContent('rendering-app'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Google Tag Manager page view tracking', function () {
title: 'This here page',
status_code: '200',

ab_test: undefined,
document_type: undefined,
publishing_app: undefined,
rendering_app: undefined,
Expand Down Expand Up @@ -380,4 +381,11 @@ describe('Google Tag Manager page view tracking', function () {
expect(window.dataLayer[0]).toEqual(expected)
})
})

it('correctly sets the ab-test parameter', function () {
createMetaTags('ab-test', 'BankHolidaysTest:A')
expected.page_view.ab_test = 'BankHolidaysTest:A'
GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init()
expect(window.dataLayer[0]).toEqual(expected)
})
})

0 comments on commit 9b3d508

Please sign in to comment.