Skip to content

Commit

Permalink
PR Change: use false instead of 'analytics disabled'
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Mar 1, 2024
1 parent dc8c796 commit 986bffa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Expand Up @@ -23,7 +23,7 @@
Analytics.prototype.sendToTrackers = function (method, args) {
// Allows us to stop sending tracking at the moment a user sets their usage cookies to "false" on the cookie settings page.
if (window.GOVUK.stopSendingAnalytics) {
return 'analytics disabled'
return false
}

for (var i = 0, l = this.trackers.length; i < l; i++) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ describe('GA4 core', function () {
window.GOVUK.stopSendingAnalytics = true
GOVUK.analyticsGa4.core.sendData({})
expect(window.dataLayer[0]).toEqual(undefined)
expect(GOVUK.analyticsGa4.core.sendData()).toEqual('analytics disabled')
expect(GOVUK.analyticsGa4.core.sendData()).toEqual(false)
})

describe('query strings allow pushing to a fake dataLayer', function () {
Expand Down
Expand Up @@ -324,22 +324,20 @@ describe('GOVUK.Analytics', function () {
})

describe('when window.GOVUK.stopSendingAnalytics is true', function () {
var disabledMessage = 'analytics disabled'

beforeEach(function () {
window.GOVUK.stopSendingAnalytics = true
})

it('disables pageview tracking', function () {
expect(analytics.trackPageview()).toEqual(disabledMessage)
expect(analytics.trackPageview()).toEqual(false)
})

it('disables share tracking', function () {
expect(analytics.trackShare()).toEqual(disabledMessage)
expect(analytics.trackShare()).toEqual(false)
})

it('disables event tracking', function () {
expect(analytics.trackShare()).toEqual(disabledMessage)
expect(analytics.trackShare()).toEqual(false)
})
})
})
Expand Up @@ -227,12 +227,12 @@ describe('cookieSettings', function () {

expect(window.GOVUK.stopSendingAnalytics).toEqual(true)

// Expect the "analytics disabled" return value now when you send an analytics event
var disabledMessage = 'analytics disabled'
expect(analytics.trackEvent()).toEqual(disabledMessage)
expect(analytics.trackShare()).toEqual(disabledMessage)
expect(analytics.trackPageview()).toEqual(disabledMessage)
expect(window.GOVUK.analyticsGa4.core.sendData()).toEqual(disabledMessage)
// Expect a false return value now when you send an analytics event

expect(analytics.trackEvent()).toEqual(false)
expect(analytics.trackShare()).toEqual(false)
expect(analytics.trackPageview()).toEqual(false)
expect(window.GOVUK.analyticsGa4.core.sendData()).toEqual(false)

expect(window.GOVUK.LUX).toEqual({})
})
Expand Down

0 comments on commit 986bffa

Please sign in to comment.