Skip to content

Commit

Permalink
Merge pull request #2909 from alphagov/update_sendPageView_object_loc…
Browse files Browse the repository at this point in the history
…ation

Update sendPageView object location
  • Loading branch information
JamesCGDS authored Aug 18, 2022
2 parents 3b47f29 + a305210 commit b359b32
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add link click tracking ([PR #2904](https://github.com/alphagov/govuk_publishing_components/pull/2904))
* Ensure tab clicks grab the tabs href for gtm ([PR #2884](https://github.com/alphagov/govuk_publishing_components/pull/2884))
* Update gtm naming conventions ([PR #2906](https://github.com/alphagov/govuk_publishing_components/pull/2906))
* Update sendPageView object location ([PR #2909](https://github.com/alphagov/govuk_publishing_components/pull/2909))

## 30.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
//= require ./analytics-ga4/ga4-link-tracker
//= require ./analytics-ga4/ga4-event-tracker

window.GOVUK.Gtm.sendPageView() // this will need integrating with cookie consent before production
window.GOVUK.analyticsGA4.pageViewTracker.sendPageView() // this will need integrating with cookie consent before production
window.GOVUK.analyticsGA4.linkTracker.trackLinkClicks()
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
'use strict'

var GOVUK = global.GOVUK || {}
GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}

GOVUK.Gtm = {
GOVUK.analyticsGA4.pageViewTracker = {
PIIRemover: new GOVUK.analyticsGA4.PIIRemover(), // imported in analytics-ga4.js
nullValue: null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ describe('Google Tag Manager page view tracking', function () {
}

it('returns a standard page view', function () {
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a page view with a specific status code', function () {
window.httpStatusCode = 404
expected.page_view.status_code = '404'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Google Tag Manager page view tracking', function () {
expected.page_view[tag.gtmName] = tag.value
}

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

Expand Down Expand Up @@ -156,7 +156,7 @@ describe('Google Tag Manager page view tracking', function () {
expected.page_view[tag.gtmName] = tag.value
}

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

Expand All @@ -177,99 +177,99 @@ describe('Google Tag Manager page view tracking', function () {
content.setAttribute('lang', 'wakandan')
expected.page_view.language = 'wakandan'

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('set incorrectly', function () {
expected.page_view.language = nullValue

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})
})

it('returns a pageview without a language', function () {
expected.page_view.language = nullValue

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview with history', function () {
createMetaTags('content-has-history', 'true')
expected.page_view.history = 'true'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview without history', function () {
createMetaTags('content-has-history', 'banana')
expected.page_view.history = 'false'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a withdrawn page', function () {
createMetaTags('withdrawn', 'withdrawn')
expected.page_view.withdrawn = 'true'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page with a first published date', function () {
createMetaTags('first-published-at', '2022-03-28T19:11:00.000+00:00')
expected.page_view.first_published_at = '2022-03-28'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page with a last updated date', function () {
createMetaTags('updated-at', '2021-03-28T19:11:00.000+00:00')
expected.page_view.updated_at = '2021-03-28'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page with a last public updated date', function () {
createMetaTags('public-updated-at', '2020-03-28T19:11:00.000+00:00')
expected.page_view.public_updated_at = '2020-03-28'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page marked with a publishing government', function () {
createMetaTags('publishing-government', 'labour')
expected.page_view.publishing_government = 'labour'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page marked with a political status', function () {
createMetaTags('political-status', 'ongoing')
expected.page_view.political_status = 'ongoing'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page marked with a primary publishing organisation', function () {
createMetaTags('primary-publishing-organisation', 'Home Office')
expected.page_view.primary_publishing_organisation = 'Home Office'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page marked with ids for contributing organisations', function () {
createMetaTags('analytics:organisations', 'some organisations')
expected.page_view.organisations = 'some organisations'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

it('returns a pageview on a page marked with world locations', function () {
createMetaTags('analytics:world-locations', 'some world locations')
expected.page_view.world_locations = 'some world locations'
GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()
expect(window.dataLayer[0]).toEqual(expected)
})

Expand All @@ -294,7 +294,7 @@ describe('Google Tag Manager page view tracking', function () {
linkForURLMock.href = '#[email protected]'
linkForURLMock.click()

GOVUK.Gtm.sendPageView()
GOVUK.analyticsGA4.pageViewTracker.sendPageView()

// Reset the page location for other tests
linkForURLMock.href = '#'
Expand Down

0 comments on commit b359b32

Please sign in to comment.