govuk_frontend_toolkit 8.2.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/assets/CHANGELOG.md +7 -1
- data/app/assets/Gruntfile.js +0 -3
- data/app/assets/README.md +3 -13
- data/app/assets/VERSION.txt +1 -1
- metadata +4 -19
- data/app/assets/docs/analytics.md +0 -272
- data/app/assets/javascripts/govuk/analytics/analytics.js +0 -153
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +0 -41
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +0 -51
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +0 -56
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +0 -194
- data/app/assets/javascripts/govuk/analytics/govuk-tracker.js +0 -134
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +0 -38
- data/app/assets/javascripts/govuk/analytics/print-intent.js +0 -39
- data/app/assets/spec/unit/analytics/analytics.spec.js +0 -403
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +0 -72
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +0 -65
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +0 -109
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +0 -221
- data/app/assets/spec/unit/analytics/govuk-tracker.spec.js +0 -171
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +0 -62
@@ -1,38 +0,0 @@
|
|
1
|
-
;(function (global) {
|
2
|
-
'use strict'
|
3
|
-
|
4
|
-
var $ = global.jQuery
|
5
|
-
var GOVUK = global.GOVUK || {}
|
6
|
-
|
7
|
-
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
|
-
GOVUK.analyticsPlugins.mailtoLinkTracker = function () {
|
9
|
-
var mailtoLinkSelector = 'a[href^="mailto:"]'
|
10
|
-
|
11
|
-
$('body').on('click', mailtoLinkSelector, trackClickEvent)
|
12
|
-
|
13
|
-
function trackClickEvent (evt) {
|
14
|
-
var $link = getLinkFromEvent(evt)
|
15
|
-
var options = { transport: 'beacon' }
|
16
|
-
var href = $link.attr('href')
|
17
|
-
var linkText = $.trim($link.text())
|
18
|
-
|
19
|
-
if (linkText) {
|
20
|
-
options.label = linkText
|
21
|
-
}
|
22
|
-
|
23
|
-
GOVUK.analytics.trackEvent('Mailto Link Clicked', href, options)
|
24
|
-
}
|
25
|
-
|
26
|
-
function getLinkFromEvent (evt) {
|
27
|
-
var $target = $(evt.target)
|
28
|
-
|
29
|
-
if (!$target.is('a')) {
|
30
|
-
$target = $target.parents('a')
|
31
|
-
}
|
32
|
-
|
33
|
-
return $target
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
global.GOVUK = GOVUK
|
38
|
-
})(window)
|
@@ -1,39 +0,0 @@
|
|
1
|
-
// Extension to monitor attempts to print pages.
|
2
|
-
;(function (global) {
|
3
|
-
'use strict'
|
4
|
-
|
5
|
-
var GOVUK = global.GOVUK || {}
|
6
|
-
|
7
|
-
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
|
-
|
9
|
-
GOVUK.analyticsPlugins.printIntent = function () {
|
10
|
-
var printAttempt = function () {
|
11
|
-
GOVUK.analytics.trackEvent('Print Intent', document.location.pathname)
|
12
|
-
GOVUK.analytics.trackPageview('/print' + document.location.pathname)
|
13
|
-
}
|
14
|
-
|
15
|
-
// Most browsers
|
16
|
-
if (global.matchMedia) {
|
17
|
-
var mediaQueryList = global.matchMedia('print')
|
18
|
-
var mqlListenerCount = 0
|
19
|
-
mediaQueryList.addListener(function (mql) {
|
20
|
-
if (!mql.matches && mqlListenerCount === 0) {
|
21
|
-
printAttempt()
|
22
|
-
mqlListenerCount++
|
23
|
-
// If we try and print again within 3 seconds, don't log it
|
24
|
-
setTimeout(function () {
|
25
|
-
mqlListenerCount = 0
|
26
|
-
// printing will be tracked again now
|
27
|
-
}, 3000)
|
28
|
-
}
|
29
|
-
})
|
30
|
-
}
|
31
|
-
|
32
|
-
// IE < 10
|
33
|
-
if (global.onafterprint) {
|
34
|
-
global.onafterprint = printAttempt
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
global.GOVUK = GOVUK
|
39
|
-
})(window)
|
@@ -1,403 +0,0 @@
|
|
1
|
-
/* global describe it expect beforeEach jasmine spyOn */
|
2
|
-
|
3
|
-
describe('GOVUK.Analytics', function () {
|
4
|
-
'use strict'
|
5
|
-
var GOVUK = window.GOVUK
|
6
|
-
|
7
|
-
function addGoogleAnalyticsSpy () {
|
8
|
-
window.ga = function () {}
|
9
|
-
spyOn(window, 'ga')
|
10
|
-
}
|
11
|
-
|
12
|
-
var analytics
|
13
|
-
var universalSetupArguments
|
14
|
-
|
15
|
-
beforeEach(function () {
|
16
|
-
addGoogleAnalyticsSpy()
|
17
|
-
|
18
|
-
analytics = new GOVUK.Analytics({
|
19
|
-
universalId: 'universal-id',
|
20
|
-
cookieDomain: '.www.gov.uk',
|
21
|
-
siteSpeedSampleRate: 100
|
22
|
-
})
|
23
|
-
})
|
24
|
-
|
25
|
-
describe('when created', function () {
|
26
|
-
beforeEach(function () {
|
27
|
-
universalSetupArguments = window.ga.calls.allArgs()
|
28
|
-
})
|
29
|
-
|
30
|
-
it('configures a universal tracker', function () {
|
31
|
-
expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {cookieDomain: '.www.gov.uk', siteSpeedSampleRate: 100}])
|
32
|
-
expect(universalSetupArguments[1]).toEqual(['set', 'anonymizeIp', true])
|
33
|
-
expect(universalSetupArguments[2]).toEqual(['set', 'displayFeaturesTask', null])
|
34
|
-
})
|
35
|
-
|
36
|
-
it('is configured not to strip date data from GA calls', function () {
|
37
|
-
expect(analytics.stripDatePII).toEqual(false)
|
38
|
-
})
|
39
|
-
|
40
|
-
it('can be told to strip date data from GA calls', function () {
|
41
|
-
analytics = new GOVUK.Analytics({
|
42
|
-
universalId: 'universal-id',
|
43
|
-
cookieDomain: '.www.gov.uk',
|
44
|
-
siteSpeedSampleRate: 100,
|
45
|
-
stripDatePII: true
|
46
|
-
})
|
47
|
-
|
48
|
-
expect(analytics.stripDatePII).toEqual(true)
|
49
|
-
})
|
50
|
-
|
51
|
-
it('is configured not to strip postcode data from GA calls', function () {
|
52
|
-
expect(analytics.stripPostcodePII).toEqual(false)
|
53
|
-
})
|
54
|
-
|
55
|
-
it('can be told to strip postcode data from GA calls', function () {
|
56
|
-
analytics = new GOVUK.Analytics({
|
57
|
-
universalId: 'universal-id',
|
58
|
-
cookieDomain: '.www.gov.uk',
|
59
|
-
siteSpeedSampleRate: 100,
|
60
|
-
stripPostcodePII: true
|
61
|
-
})
|
62
|
-
|
63
|
-
expect(analytics.stripPostcodePII).toEqual(true)
|
64
|
-
})
|
65
|
-
})
|
66
|
-
|
67
|
-
describe('extracting the default path for a page view', function () {
|
68
|
-
it('returns a path extracted from the location', function () {
|
69
|
-
var location = {
|
70
|
-
href: 'https://govuk-frontend-toolkit.example.com/a/path',
|
71
|
-
origin: 'https://govuk-frontend-toolkit.example.com'
|
72
|
-
}
|
73
|
-
expect(analytics.defaultPathForTrackPageview(location)).toEqual('/a/path')
|
74
|
-
})
|
75
|
-
|
76
|
-
it('includes the querystring in the path extracted from the location', function () {
|
77
|
-
var location = {
|
78
|
-
href: 'https://govuk-frontend-toolkit.example.com/a/path?with=a&query=string',
|
79
|
-
origin: 'https://govuk-frontend-toolkit.example.com'
|
80
|
-
}
|
81
|
-
expect(analytics.defaultPathForTrackPageview(location)).toEqual('/a/path?with=a&query=string')
|
82
|
-
})
|
83
|
-
|
84
|
-
it('removes any anchor from the path extracted from the location', function () {
|
85
|
-
var location = {
|
86
|
-
href: 'https://govuk-frontend-toolkit.example.com/a/path#with-an-anchor',
|
87
|
-
origin: 'https://govuk-frontend-toolkit.example.com'
|
88
|
-
}
|
89
|
-
expect(analytics.defaultPathForTrackPageview(location)).toEqual('/a/path')
|
90
|
-
location.href = 'https://govuk-frontend-toolkit.example.com/a/path?with=a&query=string#with-an-anchor'
|
91
|
-
expect(analytics.defaultPathForTrackPageview(location)).toEqual('/a/path?with=a&query=string')
|
92
|
-
})
|
93
|
-
})
|
94
|
-
|
95
|
-
describe('tracking pageviews', function () {
|
96
|
-
beforeEach(function () {
|
97
|
-
spyOn(analytics, 'defaultPathForTrackPageview').and.returnValue('/a/page?with=a&query=string')
|
98
|
-
})
|
99
|
-
|
100
|
-
it('injects a default path if no args are supplied', function () {
|
101
|
-
analytics.trackPageview()
|
102
|
-
console.log(window.ga.calls.mostRecent().args)
|
103
|
-
expect(window.ga.calls.mostRecent().args[2].page).toEqual('/a/page?with=a&query=string')
|
104
|
-
})
|
105
|
-
|
106
|
-
it('injects a default path if args are supplied, but the path arg is blank', function () {
|
107
|
-
analytics.trackPageview(null)
|
108
|
-
console.log(window.ga.calls.mostRecent().args)
|
109
|
-
expect(window.ga.calls.mostRecent().args[2].page).toEqual('/a/page?with=a&query=string')
|
110
|
-
|
111
|
-
analytics.trackPageview(undefined)
|
112
|
-
console.log(window.ga.calls.mostRecent().args)
|
113
|
-
expect(window.ga.calls.mostRecent().args[2].page).toEqual('/a/page?with=a&query=string')
|
114
|
-
})
|
115
|
-
|
116
|
-
it('uses the supplied path', function () {
|
117
|
-
analytics.trackPageview('/foo')
|
118
|
-
console.log(window.ga.calls.mostRecent().args)
|
119
|
-
expect(window.ga.calls.mostRecent().args[2].page).toEqual('/foo')
|
120
|
-
})
|
121
|
-
|
122
|
-
it('does not inject a default title if no args are supplied', function () {
|
123
|
-
analytics.trackPageview()
|
124
|
-
console.log(window.ga.calls.mostRecent().args)
|
125
|
-
expect(window.ga.calls.mostRecent().args[2].title).toEqual(undefined)
|
126
|
-
})
|
127
|
-
|
128
|
-
it('does not inject a default title if args are supplied, but the title arg is blank', function () {
|
129
|
-
analytics.trackPageview('/foo', null)
|
130
|
-
console.log(window.ga.calls.mostRecent().args)
|
131
|
-
expect(window.ga.calls.mostRecent().args[2].title).toEqual(undefined)
|
132
|
-
|
133
|
-
analytics.trackPageview('/foo', undefined)
|
134
|
-
console.log(window.ga.calls.mostRecent().args)
|
135
|
-
expect(window.ga.calls.mostRecent().args[2].title).toEqual(undefined)
|
136
|
-
})
|
137
|
-
|
138
|
-
it('uses the supplied title', function () {
|
139
|
-
analytics.trackPageview('/foo', 'A page')
|
140
|
-
console.log(window.ga.calls.mostRecent().args)
|
141
|
-
expect(window.ga.calls.mostRecent().args[2].title).toEqual('A page')
|
142
|
-
})
|
143
|
-
})
|
144
|
-
|
145
|
-
describe('when tracking pageviews, events and custom dimensions', function () {
|
146
|
-
it('tracks them in universal analytics', function () {
|
147
|
-
analytics.trackPageview('/path', 'Title')
|
148
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/path', title: 'Title'}])
|
149
|
-
|
150
|
-
analytics.trackEvent('category', 'action')
|
151
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action'}])
|
152
|
-
|
153
|
-
analytics.setDimension(1, 'value', 'name')
|
154
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'value'])
|
155
|
-
})
|
156
|
-
|
157
|
-
it('strips email addresses embedded in arguments', function () {
|
158
|
-
analytics.trackPageview('/path/to/an/embedded.email@example.com/address/?with=an&email=in.it@example.com', 'an.email@example.com', { label: 'another.email@example.com', value: ['data', 'data', 'someone has added their personal.email@example.com address'] })
|
159
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/[email]/address/?with=an&email=[email]', title: '[email]', label: '[email]', value: ['data', 'data', 'someone has added their [email] address'] }])
|
160
|
-
|
161
|
-
analytics.trackEvent('an_email@example.com_address-category', 'an.email@example.com-action', { label: 'another.email@example.com', value: ['data', 'data', 'someone has added their personal.email@example.com address'] })
|
162
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: '[email]', eventAction: '[email]', eventLabel: '[email]' }]) // trackEvent ignores options other than label or integer values for value
|
163
|
-
|
164
|
-
analytics.setDimension(1, 'an_email@example.com_address-value', { label: 'another.email@example.com', value: ['data', 'data', 'someone has added their personal.email@example.com address'] })
|
165
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '[email]']) // set dimension ignores extra options
|
166
|
-
})
|
167
|
-
|
168
|
-
it('leaves dates embedded in arguments by default', function () {
|
169
|
-
analytics.trackPageview('/path/to/an/embedded/2018-01-01/postcode/?with=an&postcode=2017-01-01', '20192217', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
170
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/embedded/2018-01-01/postcode/?with=an&postcode=2017-01-01', title: '20192217', label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] }])
|
171
|
-
|
172
|
-
analytics.trackEvent('2017-01-01-category', '20192217-action', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
173
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: '2017-01-01-category', eventAction: '20192217-action', eventLabel: '12345678' }]) // trackEvent ignores options other than label or integer values for value
|
174
|
-
|
175
|
-
analytics.setDimension(1, '2017-01-01-value', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
176
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '2017-01-01-value']) // set dimension ignores extra options
|
177
|
-
})
|
178
|
-
|
179
|
-
it('strips dates embedded in arguments if configured to do so', function () {
|
180
|
-
analytics = new GOVUK.Analytics({
|
181
|
-
universalId: 'universal-id',
|
182
|
-
cookieDomain: '.www.gov.uk',
|
183
|
-
siteSpeedSampleRate: 100,
|
184
|
-
stripDatePII: true
|
185
|
-
})
|
186
|
-
|
187
|
-
analytics.trackPageview('/path/to/an/embedded/2018-01-01/postcode/?with=an&postcode=2017-01-01', '20192217', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
188
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/embedded/[date]/postcode/?with=an&postcode=[date]', title: '[date]', label: '[date]', value: ['data', 'data', 'someone has added their personal[date] postcode'] }])
|
189
|
-
|
190
|
-
analytics.trackEvent('2017-01-01-category', '20192217-action', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
191
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: '[date]-category', eventAction: '[date]-action', eventLabel: '[date]' }]) // trackEvent ignores options other than label or integer values for value
|
192
|
-
|
193
|
-
analytics.setDimension(1, '2017-01-01-value', { label: '12345678', value: ['data', 'data', 'someone has added their personal9999-9999 postcode'] })
|
194
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '[date]-value']) // set dimension ignores extra options
|
195
|
-
})
|
196
|
-
|
197
|
-
it('leaves postcodes embedded in arguments by default', function () {
|
198
|
-
analytics.trackPageview('/path/to/an/embedded/SW1+1AA/postcode/?with=an&postcode=SP4%207DE', 'TD15 2SE', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
199
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/embedded/SW1+1AA/postcode/?with=an&postcode=SP4%207DE', title: 'TD15 2SE', label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] }])
|
200
|
-
|
201
|
-
analytics.trackEvent('SW1+1AA-category', 'SP4%207DE-action', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
202
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: 'SW1+1AA-category', eventAction: 'SP4%207DE-action', eventLabel: 'RG209NJ' }]) // trackEvent ignores options other than label or integer values for value
|
203
|
-
|
204
|
-
analytics.setDimension(1, 'SW1+1AA-value', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
205
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'SW1+1AA-value']) // set dimension ignores extra options
|
206
|
-
})
|
207
|
-
|
208
|
-
it('strips postcodes embedded in arguments if configured to do so', function () {
|
209
|
-
analytics = new GOVUK.Analytics({
|
210
|
-
universalId: 'universal-id',
|
211
|
-
cookieDomain: '.www.gov.uk',
|
212
|
-
siteSpeedSampleRate: 100,
|
213
|
-
stripPostcodePII: true
|
214
|
-
})
|
215
|
-
|
216
|
-
analytics.trackPageview('/path/to/an/embedded/SW1+1AA/postcode/?with=an&postcode=SP4%207DE', 'TD15 2SE', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
217
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/embedded/[postcode]/postcode/?with=an&postcode=[postcode]', title: '[postcode]', label: '[postcode]', value: ['data', 'data', 'someone has added their personal[postcode] postcode'] }])
|
218
|
-
|
219
|
-
analytics.trackEvent('SW1+1AA-category', 'SP4%207DE-action', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
220
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: '[postcode]-category', eventAction: '[postcode]-action', eventLabel: '[postcode]' }]) // trackEvent ignores options other than label or integer values for value
|
221
|
-
|
222
|
-
analytics.setDimension(1, 'SW1+1AA-value', { label: 'RG209NJ', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
223
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '[postcode]-value']) // set dimension ignores extra options
|
224
|
-
})
|
225
|
-
|
226
|
-
it('ignores any PIISafe arguments even if they look like emails, dates, or postcodes', function () {
|
227
|
-
analytics = new GOVUK.Analytics({
|
228
|
-
universalId: 'universal-id',
|
229
|
-
cookieDomain: '.www.gov.uk',
|
230
|
-
siteSpeedSampleRate: 100,
|
231
|
-
stripDatePII: true,
|
232
|
-
stripPostcodePII: true
|
233
|
-
})
|
234
|
-
|
235
|
-
analytics.trackPageview(new GOVUK.Analytics.PIISafe('/path/to/an/embedded/SW1+1AA/postcode/?with=an&postcode=SP4%207DE'), new GOVUK.Analytics.PIISafe('an.email@example.com 2017-01-01'), { label: new GOVUK.Analytics.PIISafe('another.email@example.com'), value: ['data', 'data', new GOVUK.Analytics.PIISafe('someone has added their personalIV63 6TU postcode')] })
|
236
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', { page: '/path/to/an/embedded/SW1+1AA/postcode/?with=an&postcode=SP4%207DE', title: 'an.email@example.com 2017-01-01', label: 'another.email@example.com', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] }])
|
237
|
-
|
238
|
-
analytics.trackEvent(new GOVUK.Analytics.PIISafe('SW1+1AA-category'), new GOVUK.Analytics.PIISafe('an.email@example.com-action 2017-01-01'), { label: new GOVUK.Analytics.PIISafe('RG209NJ'), value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
|
239
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: 'SW1+1AA-category', eventAction: 'an.email@example.com-action 2017-01-01', eventLabel: 'RG209NJ' }]) // trackEvent ignores options other than label or integer values for value
|
240
|
-
|
241
|
-
analytics.setDimension(1, new GOVUK.Analytics.PIISafe('an.email@SW1+1AA-value.com 2017-01-01'), { label: new GOVUK.Analytics.PIISafe('RG209NJ'), value: ['data', 'data', new GOVUK.Analytics.PIISafe('someone has added their personalIV63 6TU postcode')] })
|
242
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'an.email@SW1+1AA-value.com 2017-01-01']) // set dimension ignores extra options
|
243
|
-
})
|
244
|
-
})
|
245
|
-
|
246
|
-
describe('when tracking social media shares', function () {
|
247
|
-
it('tracks in universal', function () {
|
248
|
-
analytics.trackShare('network')
|
249
|
-
|
250
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
251
|
-
hitType: 'social',
|
252
|
-
socialNetwork: 'network',
|
253
|
-
socialAction: 'share',
|
254
|
-
socialTarget: jasmine.any(String)
|
255
|
-
}])
|
256
|
-
})
|
257
|
-
|
258
|
-
it('strips email addresses embedded in arguments', function () {
|
259
|
-
analytics.trackShare('email', {
|
260
|
-
to: 'myfriend@example.com',
|
261
|
-
label: 'another.email@example.com',
|
262
|
-
value: ['data', 'data', 'someone has added their personal.email@example.com address']
|
263
|
-
})
|
264
|
-
|
265
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
266
|
-
hitType: 'social',
|
267
|
-
socialNetwork: 'email',
|
268
|
-
socialAction: 'share',
|
269
|
-
socialTarget: jasmine.any(String),
|
270
|
-
to: '[email]',
|
271
|
-
label: '[email]',
|
272
|
-
value: ['data', 'data', 'someone has added their [email] address']
|
273
|
-
}])
|
274
|
-
})
|
275
|
-
|
276
|
-
it('leaves dates embedded in arguments by default', function () {
|
277
|
-
analytics.trackShare('email', {
|
278
|
-
to: '2017-01-01',
|
279
|
-
label: '20170101',
|
280
|
-
value: ['data', 'data', 'someone has added their personal29990303 postcode']
|
281
|
-
})
|
282
|
-
|
283
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
284
|
-
hitType: 'social',
|
285
|
-
socialNetwork: 'email',
|
286
|
-
socialAction: 'share',
|
287
|
-
socialTarget: jasmine.any(String),
|
288
|
-
to: '2017-01-01',
|
289
|
-
label: '20170101',
|
290
|
-
value: ['data', 'data', 'someone has added their personal29990303 postcode']
|
291
|
-
}])
|
292
|
-
})
|
293
|
-
|
294
|
-
it('strips dates embedded in arguments if configured to do so', function () {
|
295
|
-
analytics = new GOVUK.Analytics({
|
296
|
-
universalId: 'universal-id',
|
297
|
-
cookieDomain: '.www.gov.uk',
|
298
|
-
siteSpeedSampleRate: 100,
|
299
|
-
stripDatePII: true
|
300
|
-
})
|
301
|
-
|
302
|
-
analytics.trackShare('email', {
|
303
|
-
to: '2017-01-01',
|
304
|
-
label: '20170101',
|
305
|
-
value: ['data', 'data', 'someone has added their personal29990303 postcode']
|
306
|
-
})
|
307
|
-
|
308
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
309
|
-
hitType: 'social',
|
310
|
-
socialNetwork: 'email',
|
311
|
-
socialAction: 'share',
|
312
|
-
socialTarget: jasmine.any(String),
|
313
|
-
to: '[date]',
|
314
|
-
label: '[date]',
|
315
|
-
value: ['data', 'data', 'someone has added their personal[date] postcode']
|
316
|
-
}])
|
317
|
-
})
|
318
|
-
|
319
|
-
it('leaves postcodes embedded in arguments by default', function () {
|
320
|
-
analytics.trackShare('email', {
|
321
|
-
to: 'IV63 6TU',
|
322
|
-
label: 'SP4%207DE',
|
323
|
-
value: ['data', 'data', 'someone has added their personalTD15 2SE postcode']
|
324
|
-
})
|
325
|
-
|
326
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
327
|
-
hitType: 'social',
|
328
|
-
socialNetwork: 'email',
|
329
|
-
socialAction: 'share',
|
330
|
-
socialTarget: jasmine.any(String),
|
331
|
-
to: 'IV63 6TU',
|
332
|
-
label: 'SP4%207DE',
|
333
|
-
value: ['data', 'data', 'someone has added their personalTD15 2SE postcode']
|
334
|
-
}])
|
335
|
-
})
|
336
|
-
|
337
|
-
it('strips postcodes embedded in arguments if configured to do so', function () {
|
338
|
-
analytics = new GOVUK.Analytics({
|
339
|
-
universalId: 'universal-id',
|
340
|
-
cookieDomain: '.www.gov.uk',
|
341
|
-
siteSpeedSampleRate: 100,
|
342
|
-
stripPostcodePII: true
|
343
|
-
})
|
344
|
-
|
345
|
-
analytics.trackShare('email', {
|
346
|
-
to: 'IV63 6TU',
|
347
|
-
label: 'SP4%207DE',
|
348
|
-
value: ['data', 'data', 'someone has added their personalTD15 2SE postcode']
|
349
|
-
})
|
350
|
-
|
351
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
352
|
-
hitType: 'social',
|
353
|
-
socialNetwork: 'email',
|
354
|
-
socialAction: 'share',
|
355
|
-
socialTarget: jasmine.any(String),
|
356
|
-
to: '[postcode]',
|
357
|
-
label: '[postcode]',
|
358
|
-
value: ['data', 'data', 'someone has added their personal[postcode] postcode']
|
359
|
-
}])
|
360
|
-
})
|
361
|
-
|
362
|
-
it('ignores any PIISafe arguments even if they look like emails, dates, or postcodes', function () {
|
363
|
-
analytics = new GOVUK.Analytics({
|
364
|
-
universalId: 'universal-id',
|
365
|
-
cookieDomain: '.www.gov.uk',
|
366
|
-
siteSpeedSampleRate: 100,
|
367
|
-
stripPostcodePII: true
|
368
|
-
})
|
369
|
-
|
370
|
-
analytics.trackShare('email', {
|
371
|
-
to: new GOVUK.Analytics.PIISafe('IV63 6TU'),
|
372
|
-
label: new GOVUK.Analytics.PIISafe('an.email@example.com 2017-01-01'),
|
373
|
-
value: new GOVUK.Analytics.PIISafe(['data', 'another.email@example.com', 'someone has added their personalTD15 2SE postcode'])
|
374
|
-
})
|
375
|
-
|
376
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
377
|
-
hitType: 'social',
|
378
|
-
socialNetwork: 'email',
|
379
|
-
socialAction: 'share',
|
380
|
-
socialTarget: jasmine.any(String),
|
381
|
-
to: 'IV63 6TU',
|
382
|
-
label: 'an.email@example.com 2017-01-01',
|
383
|
-
value: ['data', 'another.email@example.com', 'someone has added their personalTD15 2SE postcode']
|
384
|
-
}])
|
385
|
-
})
|
386
|
-
})
|
387
|
-
|
388
|
-
describe('when adding a linked domain', function () {
|
389
|
-
it('adds a linked domain to universal analytics', function () {
|
390
|
-
analytics.addLinkedTrackerDomain('1234', 'test', 'www.example.com')
|
391
|
-
|
392
|
-
var allArgs = window.ga.calls.allArgs()
|
393
|
-
expect(allArgs).toContain(['create', '1234', 'auto', {'name': 'test'}])
|
394
|
-
expect(allArgs).toContain(['require', 'linker'])
|
395
|
-
expect(allArgs).toContain(['test.require', 'linker'])
|
396
|
-
expect(allArgs).toContain(['linker:autoLink', ['www.example.com']])
|
397
|
-
expect(allArgs).toContain(['test.linker:autoLink', ['www.example.com']])
|
398
|
-
expect(allArgs).toContain(['test.set', 'anonymizeIp', true])
|
399
|
-
expect(allArgs).toContain(['test.set', 'displayFeaturesTask', null])
|
400
|
-
expect(allArgs).toContain(['test.send', 'pageview'])
|
401
|
-
})
|
402
|
-
})
|
403
|
-
})
|