Skip to content

Commit

Permalink
Merge pull request #1857 from alphagov/revert-1856-improve-linker-code
Browse files Browse the repository at this point in the history
Revert "Call ga set location prior to page view in linker"
  • Loading branch information
andysellick authored Sep 13, 2019
2 parents d5184cc + 33fe761 commit 911e54a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
}

function sendToGa () {
global.ga('set', 'location', pii.stripPII(window.location.href))
if (typeof global.ga === 'function') {
global.ga.apply(global, arguments)
}
Expand Down
7 changes: 1 addition & 6 deletions spec/javascripts/analytics/static-analytics-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe("GOVUK.StaticAnalytics", function() {
var analytics;
var pii;

beforeEach(function() {
window.GOVUK.setConsentCookie({'usage': true});
Expand All @@ -22,14 +21,10 @@ describe("GOVUK.StaticAnalytics", function() {

beforeEach(function() {
pageViewObject = getPageViewObject();
pii = new GOVUK.pii()
pii.stripDatePII = true
pii.stripPostcodePII = true
});

it('configures a universal tracker', function() {
expect(window.ga.calls.allArgs()).toContain(['set', 'location', pii.stripPII(window.location.href)]);
expect(window.ga.calls.allArgs()).toContain(['create', 'universal-id', {'cookieDomain': '.www.gov.uk'}]);
expect(window.ga).toHaveBeenCalledWith('create', 'universal-id', {'cookieDomain': '.www.gov.uk'});
});

it('sets the device pixel ratio', function() {
Expand Down
6 changes: 3 additions & 3 deletions spec/javascripts/analytics_toolkit/analytics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('GOVUK.Analytics', function () {
})

it('configures a universal tracker', function () {
expect(universalSetupArguments).toContain(['create', 'universal-id', {cookieDomain: '.www.gov.uk', siteSpeedSampleRate: 100}])
expect(universalSetupArguments).toContain(['set', 'anonymizeIp', true])
expect(universalSetupArguments).toContain(['set', 'displayFeaturesTask', null])
expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {cookieDomain: '.www.gov.uk', siteSpeedSampleRate: 100}])
expect(universalSetupArguments[1]).toEqual(['set', 'anonymizeIp', true])
expect(universalSetupArguments[2]).toEqual(['set', 'displayFeaturesTask', null])
})

it('is configured not to strip date data from GA calls', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
})

it('configures a Google tracker using the provided profile ID and config', function () {
expect(setupArguments[1]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com', siteSpeedSampleRate: 100}])
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com', siteSpeedSampleRate: 100}])
})

it('anonymises the IP', function () {
expect(setupArguments[3]).toEqual(['set', 'anonymizeIp', true])
expect(setupArguments[1]).toEqual(['set', 'anonymizeIp', true])
})

it('disables Ad features', function () {
expect(setupArguments[7]).toEqual(['set', 'allowAdFeatures', false])
expect(setupArguments[3]).toEqual(['set', 'allowAdFeatures', false])
})
})

Expand All @@ -61,7 +61,7 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
})

it('configures a Google tracker using the provided profile ID and cookie domain', function () {
expect(setupArguments[1]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com'}])
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com'}])
})
})

Expand Down Expand Up @@ -207,15 +207,15 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
universal.addLinkedTrackerDomain('UA-123456', 'testTracker', ['some.service.gov.uk'])
})
it('creates a tracker for the ID', function () {
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['create', 'UA-123456', 'auto', Object({ name: 'testTracker' })])
expect(window.ga.calls.argsFor(callIndex)).toEqual(['create', 'UA-123456', 'auto', Object({ name: 'testTracker' })])
})
it('requires and configures the linker plugin', function () {
expect(window.ga.calls.allArgs()).toContain(['require', 'linker'])
expect(window.ga.calls.allArgs()).toContain(['testTracker.require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 2)).toEqual(['testTracker.require', 'linker'])
})
it('configures the domain', function () {
expect(window.ga.calls.allArgs()).toContain(['linker:autoLink', ['some.service.gov.uk']])
expect(window.ga.calls.allArgs()).toContain(['testTracker.linker:autoLink', ['some.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 3)).toEqual(['linker:autoLink', ['some.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 4)).toEqual(['testTracker.linker:autoLink', ['some.service.gov.uk']])
})
it('sends a pageview', function () {
expect(window.ga.calls.mostRecent().args).toEqual(['testTracker.send', 'pageview'])
Expand All @@ -234,15 +234,15 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
universal.addLinkedTrackerDomain('UA-789', 'multiple', ['some.service.gov.uk', 'another.service.gov.uk'])
})
it('creates a tracker for the ID', function () {
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['create', 'UA-789', 'auto', Object({ name: 'multiple' })])
expect(window.ga.calls.argsFor(callIndex)).toEqual(['create', 'UA-789', 'auto', Object({ name: 'multiple' })])
})
it('requires and configures the linker plugin', function () {
expect(window.ga.calls.allArgs()).toContain(['require', 'linker'])
expect(window.ga.calls.allArgs()).toContain(['multiple.require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 2)).toEqual(['multiple.require', 'linker'])
})
it('configures the domains', function () {
expect(window.ga.calls.allArgs()).toContain(['linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk']])
expect(window.ga.calls.allArgs()).toContain(['multiple.linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 3)).toEqual(['linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 4)).toEqual(['multiple.linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk']])
})
it('sends a pageview', function () {
expect(window.ga.calls.mostRecent().args).toEqual(['multiple.send', 'pageview'])
Expand All @@ -257,15 +257,15 @@ describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
universal.addLinkedTrackerDomain('UA-987', 'multiple', ['some.service.gov.uk', 'another.service.gov.uk', 'third.service.gov.uk', 'fourth.service.gov.uk'])
})
it('creates a tracker for the ID', function () {
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['create', 'UA-987', 'auto', Object({ name: 'multiple' })])
expect(window.ga.calls.argsFor(callIndex)).toEqual(['create', 'UA-987', 'auto', Object({ name: 'multiple' })])
})
it('requires and configures the linker plugin', function () {
expect(window.ga.calls.allArgs()).toContain(['require', 'linker'])
expect(window.ga.calls.allArgs()).toContain(['multiple.require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 1)).toEqual(['require', 'linker'])
expect(window.ga.calls.argsFor(callIndex + 2)).toEqual(['multiple.require', 'linker'])
})
it('configures the domains', function () {
expect(window.ga.calls.allArgs()).toContain(['linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk', 'third.service.gov.uk', 'fourth.service.gov.uk']])
expect(window.ga.calls.allArgs()).toContain(['multiple.linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk', 'third.service.gov.uk', 'fourth.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 3)).toEqual(['linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk', 'third.service.gov.uk', 'fourth.service.gov.uk']])
expect(window.ga.calls.argsFor(callIndex + 4)).toEqual(['multiple.linker:autoLink', ['some.service.gov.uk', 'another.service.gov.uk', 'third.service.gov.uk', 'fourth.service.gov.uk']])
})
it('sends a pageview', function () {
expect(window.ga.calls.mostRecent().args).toEqual(['multiple.send', 'pageview'])
Expand Down

0 comments on commit 911e54a

Please sign in to comment.