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.
@@ -1,41 +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.downloadLinkTracker = function (options) {
9
- options = options || {}
10
- var downloadLinkSelector = options.selector
11
-
12
- if (downloadLinkSelector) {
13
- $('body').on('click', downloadLinkSelector, trackDownload)
14
- }
15
-
16
- function trackDownload (evt) {
17
- var $link = getLinkFromEvent(evt)
18
- var href = $link.attr('href')
19
- var evtOptions = {transport: 'beacon'}
20
- var linkText = $.trim($link.text())
21
-
22
- if (linkText) {
23
- evtOptions.label = linkText
24
- }
25
-
26
- GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
27
- }
28
-
29
- function getLinkFromEvent (evt) {
30
- var $target = $(evt.target)
31
-
32
- if (!$target.is('a')) {
33
- $target = $target.parents('a')
34
- }
35
-
36
- return $target
37
- }
38
- }
39
-
40
- global.GOVUK = GOVUK
41
- })(window)
@@ -1,51 +0,0 @@
1
- // Extension to track errors using google analytics as a data store.
2
- ;(function (global) {
3
- 'use strict'
4
-
5
- var GOVUK = global.GOVUK || {}
6
-
7
- GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
8
-
9
- GOVUK.analyticsPlugins.error = function (options) {
10
- options = options || {}
11
- var filenameMustMatch = options.filenameMustMatch
12
-
13
- var trackJavaScriptError = function (e) {
14
- var errorFilename = e.filename
15
- var errorSource = errorFilename + ': ' + e.lineno
16
-
17
- if (shouldTrackThisError(errorFilename)) {
18
- GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
19
- label: errorSource,
20
- value: 1,
21
- nonInteraction: true
22
- })
23
- }
24
- }
25
-
26
- function shouldTrackThisError (errorFilename) {
27
- // Errors in page should always be tracked
28
- // If there's no filename filter, everything is tracked
29
- if (!errorFilename || !filenameMustMatch) {
30
- return true
31
- }
32
-
33
- // If there's a filter and the error matches it, track it
34
- if (filenameMustMatch.test(errorFilename)) {
35
- return true
36
- }
37
-
38
- return false
39
- }
40
-
41
- if (global.addEventListener) {
42
- global.addEventListener('error', trackJavaScriptError, false)
43
- } else if (global.attachEvent) {
44
- global.attachEvent('onerror', trackJavaScriptError)
45
- } else {
46
- global.onerror = trackJavaScriptError
47
- }
48
- }
49
-
50
- global.GOVUK = GOVUK
51
- })(window)
@@ -1,56 +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.externalLinkTracker = function (options) {
9
- options = options || {}
10
- var externalLinkUploadCustomDimension = options.externalLinkUploadCustomDimension
11
- var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname()
12
- var externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])'
13
-
14
- $('body').on('click', externalLinkSelector, trackClickEvent)
15
-
16
- function trackClickEvent (evt) {
17
- var $link = getLinkFromEvent(evt)
18
- var options = {transport: 'beacon'}
19
- var href = $link.attr('href')
20
- var linkText = $.trim($link.text())
21
-
22
- if (linkText) {
23
- options.label = linkText
24
- }
25
-
26
- if (externalLinkUploadCustomDimension !== undefined) {
27
- // This custom dimension will be used to duplicate the url information
28
- // that we normally send in an "event action". This will be used to join
29
- // up with a scheduled custom upload called "External Link Status".
30
- // We can only join uploads on custom dimensions, not on `event actions`
31
- // where we normally add the url info.
32
- var externalLinkToJoinUploadOn = href
33
-
34
- GOVUK.analytics.setDimension(externalLinkUploadCustomDimension, externalLinkToJoinUploadOn)
35
- }
36
-
37
- GOVUK.analytics.trackEvent('External Link Clicked', href, options)
38
- }
39
-
40
- function getLinkFromEvent (evt) {
41
- var $target = $(evt.target)
42
-
43
- if (!$target.is('a')) {
44
- $target = $target.parents('a')
45
- }
46
-
47
- return $target
48
- }
49
- }
50
-
51
- GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function () {
52
- return global.location.hostname
53
- }
54
-
55
- global.GOVUK = GOVUK
56
- })(window)
@@ -1,194 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var $ = global.jQuery
5
- var GOVUK = global.GOVUK || {}
6
-
7
- var GoogleAnalyticsUniversalTracker = function (trackingId, fieldsObject) {
8
- function configureProfile () {
9
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#create
10
- sendToGa('create', trackingId, fieldsObject)
11
- }
12
-
13
- function anonymizeIp () {
14
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip
15
- sendToGa('set', 'anonymizeIp', true)
16
- }
17
-
18
- function disableAdTracking () {
19
- // https://support.google.com/analytics/answer/2444872?hl=en
20
- sendToGa('set', 'displayFeaturesTask', null)
21
- }
22
-
23
- function disableAdFeatures () {
24
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#allowAdFeatures
25
- sendToGa('set', 'allowAdFeatures', false)
26
- }
27
-
28
- function stripLocationPII () {
29
- sendToGa('set', 'location', stripEmailAddressesFromString(window.location.href))
30
- }
31
-
32
- // Support legacy cookieDomain param
33
- if (typeof fieldsObject === 'string') {
34
- fieldsObject = { cookieDomain: fieldsObject }
35
- }
36
-
37
- configureProfile()
38
- anonymizeIp()
39
- disableAdTracking()
40
- disableAdFeatures()
41
- stripLocationPII()
42
- }
43
-
44
- GoogleAnalyticsUniversalTracker.load = function () {
45
- /* eslint-disable */
46
- (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
47
- (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
48
- m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
49
- })(global, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
50
- /* eslint-enable */
51
- }
52
-
53
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
54
- GoogleAnalyticsUniversalTracker.prototype.trackPageview = function (path, title, options) {
55
- var pageviewObject
56
-
57
- if (typeof path === 'string') {
58
- pageviewObject = { page: path }
59
- }
60
-
61
- if (typeof title === 'string') {
62
- pageviewObject = pageviewObject || {}
63
- pageviewObject.title = title
64
- }
65
-
66
- // Set an options object for the pageview (e.g. transport, sessionControl)
67
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
68
- if (typeof options === 'object') {
69
- pageviewObject = $.extend(pageviewObject || {}, options)
70
- }
71
-
72
- if (!$.isEmptyObject(pageviewObject)) {
73
- sendToGa('send', 'pageview', pageviewObject)
74
- } else {
75
- sendToGa('send', 'pageview')
76
- }
77
- }
78
-
79
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/events
80
- GoogleAnalyticsUniversalTracker.prototype.trackEvent = function (category, action, options) {
81
- options = options || {}
82
- var value
83
- var trackerName = ''
84
- var evt = {
85
- hitType: 'event',
86
- eventCategory: category,
87
- eventAction: action
88
- }
89
-
90
- // Label is optional
91
- if (typeof options.label === 'string') {
92
- evt.eventLabel = options.label
93
- delete options.label
94
- }
95
-
96
- // Value is optional, but when used must be an
97
- // integer, otherwise the event will be invalid
98
- // and not logged
99
- if (options.value || options.value === 0) {
100
- value = parseInt(options.value, 10)
101
- if (typeof value === 'number' && !isNaN(value)) {
102
- options.eventValue = value
103
- }
104
- delete options.value
105
- }
106
-
107
- // trackerName is optional
108
- if (typeof options.trackerName === 'string') {
109
- trackerName = options.trackerName + '.'
110
- delete options.trackerName
111
- }
112
-
113
- // Prevents an event from affecting bounce rate
114
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
115
- if (options.nonInteraction) {
116
- options.nonInteraction = 1
117
- }
118
-
119
- if (typeof options === 'object') {
120
- $.extend(evt, options)
121
- }
122
-
123
- sendToGa(trackerName + 'send', evt)
124
- }
125
-
126
- /*
127
- https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
128
- network – The network on which the action occurs (e.g. Facebook, Twitter)
129
- action – The type of action that happens (e.g. Like, Send, Tweet)
130
- target – Specifies the target of a social interaction.
131
- This value is typically a URL but can be any text.
132
- */
133
- GoogleAnalyticsUniversalTracker.prototype.trackSocial = function (network, action, target, options) {
134
- var trackingOptions = {
135
- 'hitType': 'social',
136
- 'socialNetwork': network,
137
- 'socialAction': action,
138
- 'socialTarget': target
139
- }
140
-
141
- $.extend(trackingOptions, options)
142
-
143
- sendToGa('send', trackingOptions)
144
- }
145
-
146
- /*
147
- https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
148
- trackerId - the UA account code to track the domain against
149
- name - name for the tracker
150
- domain - the domain to track
151
- sendPageView - optional argument which controls the legacy behaviour of sending a pageview
152
- on creation of the linked domain.
153
- */
154
- GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain, sendPageView) {
155
- sendToGa('create',
156
- trackerId,
157
- 'auto',
158
- {'name': name})
159
- // Load the plugin.
160
- sendToGa('require', 'linker')
161
- sendToGa(name + '.require', 'linker')
162
-
163
- // Define which domains to autoLink.
164
- sendToGa('linker:autoLink', [domain])
165
- sendToGa(name + '.linker:autoLink', [domain])
166
-
167
- sendToGa(name + '.set', 'anonymizeIp', true)
168
- sendToGa(name + '.set', 'displayFeaturesTask', null)
169
-
170
- if (typeof sendPageView === 'undefined' || sendPageView === true) {
171
- sendToGa(name + '.send', 'pageview')
172
- }
173
- }
174
-
175
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
176
- GoogleAnalyticsUniversalTracker.prototype.setDimension = function (index, value) {
177
- sendToGa('set', 'dimension' + index, String(value))
178
- }
179
-
180
- function sendToGa () {
181
- if (typeof global.ga === 'function') {
182
- global.ga.apply(global, arguments)
183
- }
184
- }
185
-
186
- function stripEmailAddressesFromString (string) {
187
- var stripped = string.replace(/[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g, '[email]')
188
- return stripped
189
- }
190
-
191
- GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker
192
-
193
- global.GOVUK = GOVUK
194
- })(window)
@@ -1,134 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var $ = global.jQuery
5
- var GOVUK = global.GOVUK || {}
6
-
7
- var GOVUKTracker = function (gifUrl) {
8
- this.gifUrl = gifUrl
9
- this.dimensions = []
10
- }
11
-
12
- GOVUKTracker.load = function () {}
13
-
14
- GOVUKTracker.prototype.trackPageview = function (path, title, options) {
15
- var pageviewObject
16
-
17
- if (typeof path === 'string') {
18
- pageviewObject = { page: path }
19
- }
20
-
21
- if (typeof title === 'string') {
22
- pageviewObject = pageviewObject || {}
23
- pageviewObject.title = title
24
- }
25
-
26
- // Set an options object for the pageview (e.g. transport, sessionControl)
27
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
28
- if (typeof options === 'object') {
29
- pageviewObject = $.extend(pageviewObject || {}, options)
30
- }
31
-
32
- if (!$.isEmptyObject(pageviewObject)) {
33
- this.sendToTracker('pageview', pageviewObject)
34
- } else {
35
- this.sendToTracker('pageview')
36
- }
37
- }
38
-
39
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/events
40
- GOVUKTracker.prototype.trackEvent = function (category, action, options) {
41
- options = options || {}
42
- var evt = {
43
- eventCategory: category,
44
- eventAction: action
45
- }
46
-
47
- if (options.label) {
48
- evt.eventLabel = options.label
49
- delete options.label
50
- }
51
-
52
- if (options.value) {
53
- evt.eventValue = options.value.toString()
54
- delete options.value
55
- }
56
-
57
- if (typeof options === 'object') {
58
- $.extend(evt, options)
59
- }
60
-
61
- this.sendToTracker('event', evt)
62
- }
63
-
64
- GOVUKTracker.prototype.trackSocial = function (network, action, target, options) {
65
- var trackingOptions = {
66
- 'socialNetwork': network,
67
- 'socialAction': action,
68
- 'socialTarget': target
69
- }
70
-
71
- $.extend(trackingOptions, options)
72
-
73
- this.sendToTracker('social', trackingOptions)
74
- }
75
-
76
- GOVUKTracker.prototype.addLinkedTrackerDomain = function () { /* noop */ }
77
-
78
- GOVUKTracker.prototype.setDimension = function (index, value) {
79
- this.dimensions['dimension' + index] = value
80
- }
81
-
82
- GOVUKTracker.prototype.payloadParams = function (type, payload) {
83
- var data = $.extend({},
84
- payload,
85
- this.dimensions,
86
- {
87
- eventType: type,
88
- referrer: global.document.referrer,
89
- gaClientId: this.gaClientId,
90
- windowWidth: global.innerWidth,
91
- windowHeight: global.innerHeight,
92
- screenWidth: global.screen.width,
93
- screenHeight: global.screen.height,
94
- colorDepth: global.screen.colorDepth
95
- }
96
- )
97
-
98
- if (global.performance) {
99
- data.navigationType = global.performance.navigation.type.toString()
100
- data.redirectCount = global.performance.navigation.redirectCount.toString()
101
-
102
- for (var k in global.performance.timing) {
103
- var v = global.performance.timing[k]
104
- if (typeof v === 'string' || typeof v === 'number') {
105
- data['timing_' + k] = v.toString()
106
- }
107
- }
108
- }
109
-
110
- return data
111
- }
112
-
113
- GOVUKTracker.prototype.sendData = function (params) {
114
- var url = this.gifUrl + '?' + $.param(params)
115
- $.get(url)
116
- }
117
-
118
- GOVUKTracker.prototype.sendToTracker = function (type, payload) {
119
- $(global.document).ready(function () {
120
- if (global.ga) {
121
- global.ga(function (tracker) {
122
- this.gaClientId = tracker.get('clientId')
123
- this.sendData(this.payloadParams(type, payload))
124
- }.bind(this))
125
- } else {
126
- this.sendData(this.payloadParams(type, payload))
127
- }
128
- }.bind(this))
129
- }
130
-
131
- GOVUK.GOVUKTracker = GOVUKTracker
132
-
133
- global.GOVUK = GOVUK
134
- })(window)