govuk_frontend_toolkit 8.2.0 → 9.0.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: 41a650d1adb77d5eb1547247e9f5c69cda8d9e4a44b1b98a2ac73c06b63345d4
4
- data.tar.gz: 596d8827ed81c3734241fce99b404b134f6be687ebbc9431b976c22654bcd27e
3
+ metadata.gz: 0c47a2989f71a0862a233cfee1ef2c356a4c94c366678dad02fe500fa087453d
4
+ data.tar.gz: 2e51fbd6caa9cdf690bf3a4333ddc9e3bbf7556cd254d535846c80ef6a5198b7
5
5
  SHA512:
6
- metadata.gz: f8818b4019d0ccf02b2e1cdc73a9c2728d58722bfd415b90c8eb4a93c45b605d8d85c140558280211a480ade167ad7bc79507d7f60febe5df6ebc57fbeb73b75
7
- data.tar.gz: f20924c85fe0ffb62f87e53d2d2cee748c92d42cd73d247950b5a6e06047777b028ce09f9d6f1ed51f032d28e68a2237398c1c3a635868774db34a761d1c4ad3
6
+ metadata.gz: 362d1d4226741022130958cbdc4dfc3b9fb009fe7928e6730acefc6d88f07f5dd1c17bb66f2f46574ce43b0989f96399d1b49694b6b78e79f49c6b4408f1e8bd
7
+ data.tar.gz: eec6ea10885dff2e942471c963b1fd4c16e46f984e01e17516d43663d39793502bb13bed92ebbb8368d84f7fc1d07af60dd1eedcd922998756eb746a49ce3ad7
data/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ The GOV.UK Design System launched on 22 June 2018
2
+ ===============
3
+
4
+ GOV.UK Frontend Toolkit has now been replaced by the GOV.UK Design System. The Toolkit will remain available in case you are currently using it, but is no longer maintained. The Government Digital Service will only carry out major bug fixes and security patches.
5
+
6
+ The GOV.UK Design System will be updated to ensure the things it contains meet level AA of WCAG 2.1, but GOV.UK Frontend Toolkit will not. [Read more about accessibility of the GOV.UK Design System](https://design-system.service.gov.uk/accessibility/).
7
+
8
+ ---
9
+
1
10
  # GOV.UK Frontend Toolkit
2
11
 
3
12
  A gem wrapper around the [govuk_frontend_toolkit](http://github.com/alphagov/govuk_frontend_toolkit).
@@ -1,4 +1,10 @@
1
- # Unreleased
1
+ # 9.0.0
2
+
3
+ - Breaking change: Remove Google Analytics code (migrated to static)
4
+
5
+ As this library has been deprecated the code has been [migrated to static](https://github.com/alphagov/static/pull/1795) for use in GOV.UK Publishing.
6
+
7
+ Note that any code that explicitly relies upon the analytics code in toolkit will no longer work. If you require this code, do not update from v8.2.0, or make a copy of it in your application.
2
8
 
3
9
  # 8.2.0
4
10
 
@@ -31,9 +31,6 @@ module.exports = function (grunt) {
31
31
  javascripts: {
32
32
  src: [
33
33
  'node_modules/jquery/dist/jquery.js',
34
- 'javascripts/govuk/analytics/google-analytics-universal-tracker.js',
35
- 'javascripts/govuk/analytics/govuk-tracker.js',
36
- 'javascripts/govuk/analytics/analytics.js',
37
34
  'javascripts/**/*.js'
38
35
  ],
39
36
  options: {
@@ -1,9 +1,9 @@
1
1
  The GOV.UK Design System launched on 22 June 2018
2
2
  ===============
3
3
 
4
- The Government Digital Service (GDS) is retiring GOV.UK Frontend Toolkit following the launch of the GOV.UK Design System. GOV.UK Frontend Toolkit will remain available to you if you are currently using it but will no longer be maintained. GDS will only roll out major bug fixes and security patches.
4
+ GOV.UK Frontend Toolkit has now been replaced by the GOV.UK Design System. The Toolkit will remain available in case you are currently using it, but is no longer maintained. The Government Digital Service will only carry out major bug fixes and security patches.
5
5
 
6
- For new projects, you can get all of the information about GOV.UK styles, components and patterns in the [GOV.UK Design System](https://www.gov.uk/design-system).
6
+ The GOV.UK Design System will be updated to ensure the things it contains meet level AA of WCAG 2.1, but GOV.UK Frontend Toolkit will not. [Read more about accessibility of the GOV.UK Design System](https://design-system.service.gov.uk/accessibility/).
7
7
 
8
8
  # GOV.UK frontend toolkit
9
9
 
@@ -44,7 +44,7 @@ compatible versions include `node-sass` 1.0.0, `grunt-sass` 0.16.0,
44
44
 
45
45
  Requirement: [NodeJS](https://nodejs.org/en/) installed. This gives you [Node Package Manager](https://docs.npmjs.com/getting-started/installing-node)(NPM) which is required to install npm packages.
46
46
 
47
- The easiest way to integrate it would be to create a `package.json` file in your application with `npm init`
47
+ The easiest way to integrate it would be to create a `package.json` file in your application with `npm init`
48
48
 
49
49
  You then install the toolkit with `npm install --save govuk_frontend_toolkit`.
50
50
  If you need javascript files, they will live in (`node_modules/govuk_frontend_toolkit/javascripts`).
@@ -153,16 +153,6 @@ In production:
153
153
  * [Selection buttons](/docs/javascript.md#selection-buttons)
154
154
  * [Shim links with button role](/docs/javascript.md#shim-links-with-button-role)
155
155
  * [Show/Hide content](/docs/javascript.md#showhide-content)
156
- * [Analytics](/docs/analytics.md)
157
- * [Create an analytics tracker](/docs/analytics.md#create-an-analytics-tracker)
158
- * [Virtual pageviews](/docs/analytics.md#virtual-pageviews)
159
- * [Custom events](/docs/analytics.md#custom-events)
160
- * [Custom dimensions and custom variables](/docs/analytics.md#custom-dimensions-and-custom-variables)
161
- * [Print tracking](/docs/analytics.md#print-tracking-print-intentjs)
162
- * [Error tracking](/docs/analytics.md#error-tracking-error-trackingjs)
163
- * [External link tracking](/docs/analytics.md#external-link-tracking-external-link-trackerjs)
164
- * [Download link tracking](/docs/analytics.md#download-link-tracking-download-link-trackerjs)
165
- * [Mailto link tracking](/docs/analytics.md#mailto-link-tracking-mailto-link-trackerjs)
166
156
 
167
157
  ## Licence
168
158
 
@@ -1 +1 @@
1
- 8.2.0
1
+ 9.0.0
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: 8.2.0
4
+ version: 9.0.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: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2019-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -85,7 +85,6 @@ files:
85
85
  - app/assets/README.md
86
86
  - app/assets/VERSION.txt
87
87
  - app/assets/create-release.sh
88
- - app/assets/docs/analytics.md
89
88
  - app/assets/docs/functions.md
90
89
  - app/assets/docs/javascript.md
91
90
  - app/assets/docs/mixins.md
@@ -217,14 +216,6 @@ files:
217
216
  - app/assets/images/player-icon-volume.png
218
217
  - app/assets/images/separator-2x.png
219
218
  - app/assets/images/separator.png
220
- - app/assets/javascripts/govuk/analytics/analytics.js
221
- - app/assets/javascripts/govuk/analytics/download-link-tracker.js
222
- - app/assets/javascripts/govuk/analytics/error-tracking.js
223
- - app/assets/javascripts/govuk/analytics/external-link-tracker.js
224
- - app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js
225
- - app/assets/javascripts/govuk/analytics/govuk-tracker.js
226
- - app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
227
- - app/assets/javascripts/govuk/analytics/print-intent.js
228
219
  - app/assets/javascripts/govuk/details.polyfill.js
229
220
  - app/assets/javascripts/govuk/modules.js
230
221
  - app/assets/javascripts/govuk/modules/auto-track-event.js
@@ -246,13 +237,6 @@ files:
246
237
  - app/assets/spec/support/console-runner.js
247
238
  - app/assets/spec/support/load.js
248
239
  - app/assets/spec/support/run_jasmine_test.js
249
- - app/assets/spec/unit/analytics/analytics.spec.js
250
- - app/assets/spec/unit/analytics/download-link-tracker.spec.js
251
- - app/assets/spec/unit/analytics/error-tracking.spec.js
252
- - app/assets/spec/unit/analytics/external-link-tracker.spec.js
253
- - app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js
254
- - app/assets/spec/unit/analytics/govuk-tracker.spec.js
255
- - app/assets/spec/unit/analytics/mailto-link-tracker.spec.js
256
240
  - app/assets/spec/unit/details.polyfill.spec.js
257
241
  - app/assets/spec/unit/modules.spec.js
258
242
  - app/assets/spec/unit/modules/auto-track-event.spec.js
@@ -306,7 +290,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
290
  - !ruby/object:Gem::Version
307
291
  version: '0'
308
292
  requirements: []
309
- rubygems_version: 3.0.3
293
+ rubyforge_project:
294
+ rubygems_version: 2.7.7
310
295
  signing_key:
311
296
  specification_version: 4
312
297
  summary: Tools for building frontend applications
@@ -1,272 +0,0 @@
1
- # Analytics
2
-
3
- The toolkit provides an abstraction around analytics to make tracking pageviews, events and dimensions across multiple analytics providers easier. Specifically it was created to ease the migration from Google’s Classic Analytics to Universal Analytics. It includes:
4
-
5
- * a Google Analytics universal tracker wrapper
6
- * code to asynchronously load universal analytics
7
- * a generic Analytics wrapper that allows multiple trackers to be configured
8
- * sensible defaults such as anonymising IPs
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 dates and UK postcodes)
11
-
12
- ## Create an analytics tracker
13
-
14
- The minimum you need to use the analytics function is:
15
-
16
- 1. Include the following files from /javascripts/govuk/analytics in your project:
17
- * google-analytics-universal-tracker.js
18
- * analytics.js
19
- 2. Copy the following `init` script into your own project and replace the dummy IDs with your own (they begin with `UA-`).
20
- * This initialisation can occur immediately as this API has no dependencies.
21
- * Load and create the analytics tracker at the earliest opportunity so that:
22
- * the time until the first pageview is tracked is kept small and pageviews aren’t missed
23
- * javascript that depends on `GOVUK.analytics` runs after the tracker has been created
24
-
25
- ```js
26
- (function() {
27
- "use strict";
28
-
29
- // Load Google Analytics libraries
30
- GOVUK.Analytics.load();
31
-
32
- // Use document.domain in dev, preview and staging so that tracking works
33
- // Otherwise explicitly set the domain as www.gov.uk (and not gov.uk).
34
- var cookieDomain = (document.domain === 'www.gov.uk') ? '.www.gov.uk' : document.domain;
35
-
36
- // Configure profiles and make interface public
37
- // for custom dimensions, virtual pageviews and events
38
- GOVUK.analytics = new GOVUK.Analytics({
39
- universalId: 'UA-XXXXXXXX-X',
40
- cookieDomain: cookieDomain
41
- });
42
-
43
- // Set custom dimensions before tracking pageviews
44
- // GOVUK.analytics.setDimension(…)
45
-
46
- // Activate any event plugins eg. print intent, error tracking
47
- // GOVUK.analyticsPlugins.error();
48
- // GOVUK.analyticsPlugins.printIntent();
49
-
50
- // Track initial pageview
51
- GOVUK.analytics.trackPageview();
52
- })();
53
- ```
54
-
55
- Once instantiated, the `GOVUK.analytics` object can be used to track virtual pageviews, custom events and custom dimensions.
56
-
57
- ## Virtual pageviews
58
-
59
- > Page tracking allows you to measure the number of views you had of a particular page on your web site.
60
-
61
- * [Universal Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/pages)
62
-
63
- Argument | Description
64
- ---------|------------
65
- `path` (optional) | Custom path, eg `/path`
66
- `title` (optional) | Custom page title, Universal only
67
-
68
-
69
- ```js
70
- // Track current page
71
- GOVUK.analytics.trackPageview();
72
-
73
- // Track a custom path
74
- GOVUK.analytics.trackPageview('/path');
75
-
76
- // Track a custom path and custom page title
77
- GOVUK.analytics.trackPageview('/path', 'Title');
78
-
79
- // As above, plus additional options passed into the `pageview` call
80
- GOVUK.analytics.trackPageview('/path', 'Title', {
81
- sessionControl: 'start'
82
- });
83
- ```
84
-
85
- ## Custom events
86
-
87
- > Event tracking allows you to measure how users interact with the content of your website. For example, you might want to measure how many times a button was pressed, or how many times a particular item was used.
88
-
89
- * [Universal Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/events)
90
-
91
- Argument | Description
92
- ---------|------------
93
- `category` (required) | Typically the object that was interacted with, eg "JavaScript error"
94
- `action` (required) | The type of interaction, eg a Javascript error message
95
- `options` (optional) | Optional parameters to further describe event
96
-
97
- Option | Description
98
- -------|------------
99
- `page` | Useful for sending the URL when `window.location` has been updated using JavaScript since the Analytics tracking object was created
100
- `label` | Useful for categorising events, eg Javascript error source
101
- `value` | Values must be non-negative. Useful to pass counts, eg error happened 5 times
102
- `nonInteraction` | Defaults to false. When set the event will not affect bounce rate
103
-
104
- ```js
105
- // Track a custom event with required category and action fields
106
- GOVUK.analytics.trackEvent('category', 'action');
107
-
108
- // Track a custom event with optional page, label, value and nonInteraction options
109
- GOVUK.analytics.trackEvent('category', 'action', {
110
- page: '/path/to/page',
111
- label: 'label',
112
- value: 1,
113
- nonInteraction: true // event will not affect bounce rate
114
- });
115
- ```
116
-
117
- ## Custom dimensions
118
-
119
- > Custom dimensions and metrics are a powerful way to send custom data to Google Analytics. Use custom dimensions and metrics to segment and measure differences between: logged in and logged out users, authors of pages, or any other business data you have on a page.
120
-
121
- * [Universal Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets)
122
-
123
- Universal custom dimensions are configured within analytics.
124
-
125
- ### Set custom dimensions before tracking pageviews
126
-
127
- Many page level custom dimensions must be set before the initial pageview is tracked. Calls to `setDimension` should typically be made before the initial `trackPageview` is sent to analytics.
128
-
129
- Argument | Description
130
- ---------|------------
131
- `index` (required) | The Universal dimension’s index as configured in the profile.
132
- `value` (required) | Value of the custom dimension
133
-
134
- ```js
135
- // Set a custom dimension at index 1 with value and name
136
- GOVUK.analytics.setDimension(1, 'value');
137
- ```
138
-
139
- ### Create custom dimension helpers
140
-
141
- Because dimensions rely on the correct index and that index doesn’t indicate its purpose, it’s helpful to create methods that abstract away the details. For example:
142
-
143
- ```js
144
- function setPixelDensityDimension(pixelDensity) {
145
- GOVUK.analytics.setDimension(1, pixelDensity);
146
- }
147
- ```
148
-
149
- ## Tracking across domains
150
-
151
- Once an Analytics instance has been created, tracking across domains can be set up
152
- for pages like:
153
-
154
- ```js
155
- GOVUK.analytics.addLinkedTrackerDomain(trackerIdHere, nameForTracker, domainToLinkTo);
156
- ```
157
-
158
- Once this is done hits to that page will be tracked in both your local and the
159
- named tracker, and sessions will persist to the other domain.
160
-
161
- ## Plugins
162
-
163
- Plugins are namespaced to `GOVUK.analyticsPlugins`. They should be pulled in by your project and initialised after `GOVUK.analytics` (see [Create an analytics tracker, above](#create-an-analytics-tracker)).
164
-
165
- ### Print tracking (`print-intent.js`)
166
-
167
- Track when users are attempting to print content. The plugin sends a `Print intent` event and a `/print` prefixed pageview:
168
-
169
- Example event:
170
-
171
- Category | Action
172
- ---------|-------
173
- Print Intent | `/current/page`
174
-
175
- Example pageview:
176
-
177
- `/print/current/page`
178
-
179
- ### Error tracking (`error-tracking.js`)
180
-
181
- Track JavaScript errors, capturing the error message, file and line number. These events don’t affect bounce rate. Errors can be filtered to include only files of interest by passing in an options argument with a regexp matcher (to avoid tracking errors generated by browser plugins):
182
-
183
- ```js
184
- GOVUK.analyticsPlugins.error({filenameMustMatch: /gov\.uk/});
185
- ```
186
-
187
- Category | Action | Label | Value
188
- ---------|--------|-------|-------
189
- JavaScript Error | The error message | file.js: line number | 1
190
-
191
- ### External link tracking (`external-link-tracker.js`)
192
-
193
- The tracker will send an event for clicks on links beginning, `http` and linking outside of the current host. By default the plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
194
-
195
- Category | Action | Label
196
- ---------|--------|-------
197
- External Link Clicked | http://www.some-external-website.com | Link text
198
-
199
-
200
- ### Download link tracking (`download-link-tracker.js`)
201
-
202
- The tracker will send an event for clicks on any link that matches the selector passed in. A selector must be provided. By default the plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
203
-
204
- ```js
205
- GOVUK.analyticsPlugins.downloadTracker({selector: 'a[rel="download"]'});
206
- ```
207
-
208
- Category | Action | Label
209
- ---------|--------|-------
210
- Download Link Clicked | `/some/upload/attachment/file.pdf` | Link text
211
-
212
- ### Mailto link tracking (`mailto-link-tracker.js`)
213
-
214
- The tracker will send events for clicks on links beginning with `mailto`. By default the
215
- plugin uses Google Analytics’ `transport: beacon` method so that events are tracked even if the page unloads.
216
-
217
- Category | Action | Label
218
- ---------|--------|-------
219
- Mailto Link Clicked | mailto:name@email.com | Link text
220
-
221
- ### Stripping Personally Identifiable Information (PII)
222
-
223
- The tracker will strip any PII it detects from all arguments sent to the
224
- tracker. If a PII is detected in the arguments it is replaced with a
225
- placeholder value of `[<type of PII removed>]`; for example: `[email]` if an
226
- email address was removed, `[date]` if a date was removed, or `[postcode]`
227
- if a postcode was removed.
228
-
229
- We have to parse all arguments which means that if you don't pass a path to
230
- `trackPageview` to track the current page we have to extract the current page
231
- and parse it, turning all `trackPageview` calls into ones with a path argument.
232
- We use `window.location.href.split('#')[0]` as the default path when one is
233
- not provided. The original behaviour would have been to ignore the anchor
234
- part of the URL anyway so this doesn't change the behaviour other than to make
235
- the path explicit.
236
-
237
- By default we strip email addresses, but it can also be configured to strip
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:
242
-
243
- ```js
244
- GOVUK.analytics = new GOVUK.Analytics({
245
- universalId: 'UA-XXXXXXXX-X',
246
- cookieDomain: cookieDomain,
247
- stripDatePII: true,
248
- stripPostcodePII: true
249
- });
250
- ````
251
-
252
- Any value other than the JS literal `true` will leave the analytics module
253
- configured not to strip.
254
-
255
- #### Avoding false positives
256
-
257
- Sometimes you will have data you want to send to analytics that looks like PII
258
- and would be stripped out. For example on GOV.UK the content_ids that belong
259
- to every document can sometimes contain a string of characters that look like a
260
- UK postcode: in `eed5b92e-8279-4ca9-a141-5c35ed22fcf1` the substring `c35ed` in
261
- the final portion looks like a postcode, `C3 5ED`, and will be transformed into
262
- `eed5b92e-8279-4ca9-a141-5[postcode]22fcf1` which breaks the `content_id`. To
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`
265
- object. If any argument to an analytics function is an instance of one of these
266
- objects the value contained within will be extracted and sent directly to the
267
- analytics tracker without attempting to strip PII from it. For example:
268
-
269
- ```js
270
- GOVUK.analytics.setDimension(1, new GOVUK.Analytics.PIISafe('this-is-not-an@email-address-but-it-looks-like-one'));
271
- GOVUK.analytics.trackEvent('report title clicked', new GOVUK.Analytics.PIISafe('this report title looks like it contains a P0 5TC ode but it does not really'));
272
- ````
@@ -1,153 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
- var EMAIL_PATTERN = /[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g
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
8
-
9
- // For usage and initialisation see:
10
- // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
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
- }
20
- this.stripPostcodePII = false
21
- if (typeof config.stripPostcodePII !== 'undefined') {
22
- this.stripPostcodePII = (config.stripPostcodePII === true)
23
- // remove the option so we don't pass it to other trackers - it's not
24
- // their concern
25
- delete config.stripPostcodePII
26
- }
27
- this.trackers = []
28
- if (typeof config.universalId !== 'undefined') {
29
- var universalId = config.universalId
30
- delete config.universalId
31
- this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
32
- }
33
- if (typeof config.govukTrackerUrl !== 'undefined') {
34
- var govukTrackerUrl = config.govukTrackerUrl
35
- delete config.govukTrackerUrl
36
- this.trackers.push(new GOVUK.GOVUKTracker(govukTrackerUrl))
37
- }
38
- }
39
-
40
- var PIISafe = function (value) {
41
- this.value = value
42
- }
43
- Analytics.PIISafe = PIISafe
44
-
45
- Analytics.prototype.stripPII = function (value) {
46
- if (typeof value === 'string') {
47
- return this.stripPIIFromString(value)
48
- } else if (Object.prototype.toString.call(value) === '[object Array]' || Object.prototype.toString.call(value) === '[object Arguments]') {
49
- return this.stripPIIFromArray(value)
50
- } else if (typeof value === 'object') {
51
- return this.stripPIIFromObject(value)
52
- } else {
53
- return value
54
- }
55
- }
56
-
57
- Analytics.prototype.stripPIIFromString = function (string) {
58
- var stripped = string.replace(EMAIL_PATTERN, '[email]')
59
- if (this.stripDatePII === true) {
60
- stripped = stripped.replace(DATE_PATTERN, '[date]')
61
- }
62
- if (this.stripPostcodePII === true) {
63
- stripped = stripped.replace(POSTCODE_PATTERN, '[postcode]')
64
- }
65
- return stripped
66
- }
67
-
68
- Analytics.prototype.stripPIIFromObject = function (object) {
69
- if (object instanceof Analytics.PIISafe) {
70
- return object.value
71
- } else {
72
- for (var property in object) {
73
- var value = object[property]
74
-
75
- object[property] = this.stripPII(value)
76
- }
77
- return object
78
- }
79
- }
80
-
81
- Analytics.prototype.stripPIIFromArray = function (array) {
82
- for (var i = 0, l = array.length; i < l; i++) {
83
- var elem = array[i]
84
-
85
- array[i] = this.stripPII(elem)
86
- }
87
- return array
88
- }
89
-
90
- Analytics.prototype.sendToTrackers = function (method, args) {
91
- for (var i = 0, l = this.trackers.length; i < l; i++) {
92
- var tracker = this.trackers[i]
93
- var fn = tracker[method]
94
-
95
- if (typeof fn === 'function') {
96
- fn.apply(tracker, args)
97
- }
98
- }
99
- }
100
-
101
- Analytics.load = function () {
102
- GOVUK.GoogleAnalyticsUniversalTracker.load()
103
- GOVUK.GOVUKTracker.load()
104
- }
105
-
106
- Analytics.prototype.defaultPathForTrackPageview = function (location) {
107
- // Get the page path including querystring, but ignoring the anchor
108
- // as per default behaviour of GA (see: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages#overview)
109
- // we ignore the possibility of there being campaign variables in the
110
- // anchor because we wouldn't know how to detect and parse them if they
111
- // were present
112
- return this.stripPIIFromString(location.href.substring(location.origin.length).split('#')[0])
113
- }
114
-
115
- Analytics.prototype.trackPageview = function (path, title, options) {
116
- arguments[0] = arguments[0] || this.defaultPathForTrackPageview(window.location)
117
- if (arguments.length === 0) { arguments.length = 1 }
118
- this.sendToTrackers('trackPageview', this.stripPII(arguments))
119
- }
120
-
121
- /*
122
- https://developers.google.com/analytics/devguides/collection/analyticsjs/events
123
- options.label – Useful for categorizing events (eg nav buttons)
124
- options.value – Values must be non-negative. Useful to pass counts
125
- options.nonInteraction – Prevent event from impacting bounce rate
126
- */
127
- Analytics.prototype.trackEvent = function (category, action, options) {
128
- this.sendToTrackers('trackEvent', this.stripPII(arguments))
129
- }
130
-
131
- Analytics.prototype.trackShare = function (network, options) {
132
- this.sendToTrackers('trackSocial', this.stripPII([network, 'share', global.location.pathname, options]))
133
- }
134
-
135
- /*
136
- The custom dimension index must be configured within the
137
- Universal Analytics profile
138
- */
139
- Analytics.prototype.setDimension = function (index, value) {
140
- this.sendToTrackers('setDimension', this.stripPII(arguments))
141
- }
142
-
143
- /*
144
- Add a beacon to track a page in another GA account on another domain.
145
- */
146
- Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
147
- this.sendToTrackers('addLinkedTrackerDomain', arguments)
148
- }
149
-
150
- GOVUK.Analytics = Analytics
151
-
152
- global.GOVUK = GOVUK
153
- })(window)