govuk_frontend_toolkit 7.4.2 → 7.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7898fa496cc37c7a25080a47fb956210dfc4f1292e3c11592f9f11d99560a23c
4
- data.tar.gz: beed11c44d8b2b0edc9c8512d8e23bfbd3992c84f077f92706bb0d735c056166
3
+ metadata.gz: eff63e0599f9da09739df587ffd34308b7eb485e94d1cceb8a86c1d44f67ccbc
4
+ data.tar.gz: 9abe419f1eea6dc31ed054d7028cf2057a4d4a7e2e3969116c3510e1b39205ea
5
5
  SHA512:
6
- metadata.gz: ee08d53b41087e42eb948a397f34384eefb3f168e1a7898633e5e7d669230e6b72197851ff622d9727e8809cd71c2187a135e031358e21a70c7debc48da48acd
7
- data.tar.gz: 23f0bfc93d48f66458369638ea3b785987290399c88a4e2d692b66cdb43e029e3f0a764a7cc4b559b256eb1552d6bf89b527cbfa1f339ec4899d28d3a16c0a83
6
+ metadata.gz: d813921775ca00d88421a4b46102acae335295bf45f7655fc7b9ced2c1ebc212eb25c83e1932aa90453834392fff2fd791d50f200fef96c1b9a3f0d4f1edb859
7
+ data.tar.gz: 12516e2bfe55aa4d1eceafa8ea9a346020174570edbd83235fc3f2c5d4433095d79acdd4159724b8fa8b4c3bf94218fe00d29d8485fa124232e253a61937c534
@@ -1,3 +1,7 @@
1
+ # 7.5.0
2
+
3
+ - Implement optional stripping of dates for arguments passed to GA: ([PR #459](https://github.com/alphagov/govuk_frontend_toolkit/pull/459))
4
+
1
5
  # 7.4.2
2
6
 
3
7
  - Remove the deprecation warning in javascripts/govuk/selection-buttons.js as it is coupled to a different project which is not always used with this gem.
@@ -1 +1 @@
1
- 7.4.2
1
+ 7.5.0
@@ -7,7 +7,7 @@ The toolkit provides an abstraction around analytics to make tracking pageviews,
7
7
  * a generic Analytics wrapper that allows multiple trackers to be configured
8
8
  * sensible defaults such as anonymising IPs
9
9
  * data coercion into the format required by Google Analytics (eg a custom dimension’s value must be a string)
10
- * stripping of PII from data sent to the tracker (strips email by default, can be configured to also strip UK postcodes)
10
+ * stripping of PII from data sent to the tracker (strips email by default, can be configured to also strip dates and UK postcodes)
11
11
 
12
12
  ## Create an analytics tracker
13
13
 
@@ -223,7 +223,8 @@ Mailto Link Clicked | mailto:name@email.com | Link text
223
223
  The tracker will strip any PII it detects from all arguments sent to the
224
224
  tracker. If a PII is detected in the arguments it is replaced with a
225
225
  placeholder value of `[<type of PII removed>]`; for example: `[email]` if an
226
- email address was removed, or `[postcode]` if a postcode was removed.
226
+ email address was removed, `[date]` if a date was removed, or `[postcode]`
227
+ if a postcode was removed.
227
228
 
228
229
  We have to parse all arguments which means that if you don't pass a path to
229
230
  `trackPageView` to track the current page we have to extract the current page
@@ -234,21 +235,22 @@ part of the URL anyway so this doesn't change the behaviour other than to make
234
235
  the path explicit.
235
236
 
236
237
  By default we strip email addresses, but it can also be configured to strip
237
- postcodes too. Postcodes are off by default because they're more likely to
238
- cause false positives. If you know you are likely to include postcodes in
239
- the data you send to the tracker you can configure to strip postcodes at
240
- initialize time as follows:
238
+ dates and postcodes too. Dates and postcodes are off by default because
239
+ they're more likely to cause false positives. If you know you are likely to
240
+ include dates or postcodes in the data you send to the tracker you can configure
241
+ to strip postcodes at initialize time as follows:
241
242
 
242
243
  ```js
243
244
  GOVUK.analytics = new GOVUK.Analytics({
244
245
  universalId: 'UA-XXXXXXXX-X',
245
246
  cookieDomain: cookieDomain,
247
+ stripDatePII: true,
246
248
  stripPostcodePII: true
247
249
  });
248
250
  ````
249
251
 
250
- Any value other than the JS literal `true` for `stripPostcodePII` will leave
251
- the analytics module configured not to strip postcodes.
252
+ Any value other than the JS literal `true` will leave the analytics module
253
+ configured not to strip.
252
254
 
253
255
  #### Avoding false positives
254
256
 
@@ -258,8 +260,8 @@ to every document can sometimes contain a string of characters that look like a
258
260
  UK postcode: in `eed5b92e-8279-4ca9-a141-5c35ed22fcf1` the substring `c35ed` in
259
261
  the final portion looks like a postcode, `C3 5ED`, and will be transformed into
260
262
  `eed5b92e-8279-4ca9-a141-5[postcode]22fcf1` which breaks the `content_id`. To
261
- send data that you know is not PII, but it looks like an email address or a UK
262
- postcode you can provide your arguments wrapped in a `GOVUK.Analytics.PIISafe`
263
+ send data that you know is not PII, but it looks like an email address, a date,
264
+ or a UK postcode you can provide your arguments wrapped in a `GOVUK.Analytics.PIISafe`
263
265
  object. If any argument to an analytics function is an instance of one of these
264
266
  objects the value contained within will be extracted and sent directly to the
265
267
  analytics tracker without attempting to strip PII from it. For example:
@@ -4,11 +4,19 @@
4
4
  var GOVUK = global.GOVUK || {}
5
5
  var EMAIL_PATTERN = /[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g
6
6
  var POSTCODE_PATTERN = /[A-PR-UWYZ][A-HJ-Z]?[0-9][0-9A-HJKMNPR-Y]?(?:[\s+]|%20)*[0-9][ABD-HJLNPQ-Z]{2}/gi
7
+ var DATE_PATTERN = /\d{4}(-?)\d{2}(-?)\d{2}/g
7
8
 
8
9
  // For usage and initialisation see:
9
10
  // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
10
11
 
11
12
  var Analytics = function (config) {
13
+ this.stripDatePII = false
14
+ if (typeof config.stripDatePII !== 'undefined') {
15
+ this.stripDatePII = (config.stripDatePII === true)
16
+ // remove the option so we don't pass it to other trackers - it's not
17
+ // their concern
18
+ delete config.stripDatePII
19
+ }
12
20
  this.stripPostcodePII = false
13
21
  if (typeof config.stripPostcodePII !== 'undefined') {
14
22
  this.stripPostcodePII = (config.stripPostcodePII === true)
@@ -47,12 +55,14 @@
47
55
  }
48
56
 
49
57
  Analytics.prototype.stripPIIFromString = function (string) {
50
- var emailStripped = string.replace(EMAIL_PATTERN, '[email]')
58
+ var stripped = string.replace(EMAIL_PATTERN, '[email]')
59
+ if (this.stripDatePII === true) {
60
+ stripped = stripped.replace(DATE_PATTERN, '[date]')
61
+ }
51
62
  if (this.stripPostcodePII === true) {
52
- return emailStripped.replace(POSTCODE_PATTERN, '[postcode]')
53
- } else {
54
- return emailStripped
63
+ stripped = stripped.replace(POSTCODE_PATTERN, '[postcode]')
55
64
  }
65
+ return stripped
56
66
  }
57
67
 
58
68
  Analytics.prototype.stripPIIFromObject = function (object) {
@@ -33,6 +33,21 @@ describe('GOVUK.Analytics', function () {
33
33
  expect(universalSetupArguments[2]).toEqual(['set', 'displayFeaturesTask', null])
34
34
  })
35
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
+
36
51
  it('is configured not to strip postcode data from GA calls', function () {
37
52
  expect(analytics.stripPostcodePII).toEqual(false)
38
53
  })
@@ -150,6 +165,35 @@ describe('GOVUK.Analytics', function () {
150
165
  expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '[email]']) // set dimension ignores extra options
151
166
  })
152
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
+
153
197
  it('leaves postcodes embedded in arguments by default', function () {
154
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'] })
155
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'] }])
@@ -179,22 +223,23 @@ describe('GOVUK.Analytics', function () {
179
223
  expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '[postcode]-value']) // set dimension ignores extra options
180
224
  })
181
225
 
182
- it('ignores any PIISafe arguments even if they look like emails or postcodes', function () {
226
+ it('ignores any PIISafe arguments even if they look like emails, dates, or postcodes', function () {
183
227
  analytics = new GOVUK.Analytics({
184
228
  universalId: 'universal-id',
185
229
  cookieDomain: '.www.gov.uk',
186
230
  siteSpeedSampleRate: 100,
231
+ stripDatePII: true,
187
232
  stripPostcodePII: true
188
233
  })
189
234
 
190
- 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'), { label: new GOVUK.Analytics.PIISafe('another.email@example.com'), value: ['data', 'data', new GOVUK.Analytics.PIISafe('someone has added their personalIV63 6TU postcode')] })
191
- 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', label: 'another.email@example.com', value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] }])
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'] }])
192
237
 
193
- analytics.trackEvent(new GOVUK.Analytics.PIISafe('SW1+1AA-category'), new GOVUK.Analytics.PIISafe('an.email@example.com-action'), { label: new GOVUK.Analytics.PIISafe('RG209NJ'), value: ['data', 'data', 'someone has added their personalIV63 6TU postcode'] })
194
- expect(window.ga.calls.mostRecent().args).toEqual(['send', { hitType: 'event', eventCategory: 'SW1+1AA-category', eventAction: 'an.email@example.com-action', eventLabel: 'RG209NJ' }]) // trackEvent ignores options other than label or integer values for value
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
195
240
 
196
- analytics.setDimension(1, new GOVUK.Analytics.PIISafe('an.email@SW1+1AA-value.com'), { label: new GOVUK.Analytics.PIISafe('RG209NJ'), value: ['data', 'data', new GOVUK.Analytics.PIISafe('someone has added their personalIV63 6TU postcode')] })
197
- expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'an.email@SW1+1AA-value.com']) // set dimension ignores extra options
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
198
243
  })
199
244
  })
200
245
 
@@ -228,6 +273,49 @@ describe('GOVUK.Analytics', function () {
228
273
  }])
229
274
  })
230
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
+
231
319
  it('leaves postcodes embedded in arguments by default', function () {
232
320
  analytics.trackShare('email', {
233
321
  to: 'IV63 6TU',
@@ -271,7 +359,7 @@ describe('GOVUK.Analytics', function () {
271
359
  }])
272
360
  })
273
361
 
274
- it('ignores any PIISafe arguments even if they look like emails or postcodes', function () {
362
+ it('ignores any PIISafe arguments even if they look like emails, dates, or postcodes', function () {
275
363
  analytics = new GOVUK.Analytics({
276
364
  universalId: 'universal-id',
277
365
  cookieDomain: '.www.gov.uk',
@@ -281,7 +369,7 @@ describe('GOVUK.Analytics', function () {
281
369
 
282
370
  analytics.trackShare('email', {
283
371
  to: new GOVUK.Analytics.PIISafe('IV63 6TU'),
284
- label: new GOVUK.Analytics.PIISafe('an.email@example.com'),
372
+ label: new GOVUK.Analytics.PIISafe('an.email@example.com 2017-01-01'),
285
373
  value: new GOVUK.Analytics.PIISafe(['data', 'another.email@example.com', 'someone has added their personalTD15 2SE postcode'])
286
374
  })
287
375
 
@@ -291,7 +379,7 @@ describe('GOVUK.Analytics', function () {
291
379
  socialAction: 'share',
292
380
  socialTarget: jasmine.any(String),
293
381
  to: 'IV63 6TU',
294
- label: 'an.email@example.com',
382
+ label: 'an.email@example.com 2017-01-01',
295
383
  value: ['data', 'another.email@example.com', 'someone has added their personalTD15 2SE postcode']
296
384
  }])
297
385
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.2
4
+ version: 7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties