govuk_frontend_toolkit 7.6.0 → 9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/assets/.ruby-version +1 -1
- data/app/assets/CHANGELOG.md +37 -0
- data/app/assets/Gemfile +0 -1
- data/app/assets/Gruntfile.js +0 -3
- data/app/assets/README.md +7 -21
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/mixins.md +1 -1
- data/app/assets/javascripts/govuk/show-hide-content.js +1 -7
- data/app/assets/javascripts/stageprompt.js +7 -1
- data/app/assets/package-lock.json +2471 -0
- data/app/assets/spec/unit/show-hide-content.spec.js +57 -0
- data/app/assets/spec/unit/stageprompt.spec.js +170 -0
- data/app/assets/stylesheets/colours/_organisation.scss +1 -1
- data/govuk_frontend_toolkit.gemspec +0 -3
- data/publish.sh +1 -2
- metadata +5 -49
- data/Rakefile +0 -10
- 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 -176
- 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 -187
- 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,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,176 +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 stripLocationPII () {
|
24
|
-
sendToGa('set', 'location', stripEmailAddressesFromString(window.location.href))
|
25
|
-
}
|
26
|
-
|
27
|
-
// Support legacy cookieDomain param
|
28
|
-
if (typeof fieldsObject === 'string') {
|
29
|
-
fieldsObject = { cookieDomain: fieldsObject }
|
30
|
-
}
|
31
|
-
|
32
|
-
configureProfile()
|
33
|
-
anonymizeIp()
|
34
|
-
disableAdTracking()
|
35
|
-
stripLocationPII()
|
36
|
-
}
|
37
|
-
|
38
|
-
GoogleAnalyticsUniversalTracker.load = function () {
|
39
|
-
/* eslint-disable */
|
40
|
-
(function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
|
41
|
-
(i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
|
42
|
-
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
|
43
|
-
})(global, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
|
44
|
-
/* eslint-enable */
|
45
|
-
}
|
46
|
-
|
47
|
-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
|
48
|
-
GoogleAnalyticsUniversalTracker.prototype.trackPageview = function (path, title, options) {
|
49
|
-
var pageviewObject
|
50
|
-
|
51
|
-
if (typeof path === 'string') {
|
52
|
-
pageviewObject = { page: path }
|
53
|
-
}
|
54
|
-
|
55
|
-
if (typeof title === 'string') {
|
56
|
-
pageviewObject = pageviewObject || {}
|
57
|
-
pageviewObject.title = title
|
58
|
-
}
|
59
|
-
|
60
|
-
// Set an options object for the pageview (e.g. transport, sessionControl)
|
61
|
-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
|
62
|
-
if (typeof options === 'object') {
|
63
|
-
pageviewObject = $.extend(pageviewObject || {}, options)
|
64
|
-
}
|
65
|
-
|
66
|
-
if (!$.isEmptyObject(pageviewObject)) {
|
67
|
-
sendToGa('send', 'pageview', pageviewObject)
|
68
|
-
} else {
|
69
|
-
sendToGa('send', 'pageview')
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/events
|
74
|
-
GoogleAnalyticsUniversalTracker.prototype.trackEvent = function (category, action, options) {
|
75
|
-
options = options || {}
|
76
|
-
var value
|
77
|
-
var evt = {
|
78
|
-
hitType: 'event',
|
79
|
-
eventCategory: category,
|
80
|
-
eventAction: action
|
81
|
-
}
|
82
|
-
|
83
|
-
// Label is optional
|
84
|
-
if (typeof options.label === 'string') {
|
85
|
-
evt.eventLabel = options.label
|
86
|
-
delete options.label
|
87
|
-
}
|
88
|
-
|
89
|
-
// Value is optional, but when used must be an
|
90
|
-
// integer, otherwise the event will be invalid
|
91
|
-
// and not logged
|
92
|
-
if (options.value || options.value === 0) {
|
93
|
-
value = parseInt(options.value, 10)
|
94
|
-
if (typeof value === 'number' && !isNaN(value)) {
|
95
|
-
options.eventValue = value
|
96
|
-
}
|
97
|
-
delete options.value
|
98
|
-
}
|
99
|
-
|
100
|
-
// Prevents an event from affecting bounce rate
|
101
|
-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
|
102
|
-
if (options.nonInteraction) {
|
103
|
-
options.nonInteraction = 1
|
104
|
-
}
|
105
|
-
|
106
|
-
if (typeof options === 'object') {
|
107
|
-
$.extend(evt, options)
|
108
|
-
}
|
109
|
-
|
110
|
-
sendToGa('send', evt)
|
111
|
-
}
|
112
|
-
|
113
|
-
/*
|
114
|
-
https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
|
115
|
-
network – The network on which the action occurs (e.g. Facebook, Twitter)
|
116
|
-
action – The type of action that happens (e.g. Like, Send, Tweet)
|
117
|
-
target – Specifies the target of a social interaction.
|
118
|
-
This value is typically a URL but can be any text.
|
119
|
-
*/
|
120
|
-
GoogleAnalyticsUniversalTracker.prototype.trackSocial = function (network, action, target, options) {
|
121
|
-
var trackingOptions = {
|
122
|
-
'hitType': 'social',
|
123
|
-
'socialNetwork': network,
|
124
|
-
'socialAction': action,
|
125
|
-
'socialTarget': target
|
126
|
-
}
|
127
|
-
|
128
|
-
$.extend(trackingOptions, options)
|
129
|
-
|
130
|
-
sendToGa('send', trackingOptions)
|
131
|
-
}
|
132
|
-
|
133
|
-
/*
|
134
|
-
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
|
135
|
-
trackerId - the UA account code to track the domain against
|
136
|
-
name - name for the tracker
|
137
|
-
domain - the domain to track
|
138
|
-
*/
|
139
|
-
GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
|
140
|
-
sendToGa('create',
|
141
|
-
trackerId,
|
142
|
-
'auto',
|
143
|
-
{'name': name})
|
144
|
-
// Load the plugin.
|
145
|
-
sendToGa('require', 'linker')
|
146
|
-
sendToGa(name + '.require', 'linker')
|
147
|
-
|
148
|
-
// Define which domains to autoLink.
|
149
|
-
sendToGa('linker:autoLink', [domain])
|
150
|
-
sendToGa(name + '.linker:autoLink', [domain])
|
151
|
-
|
152
|
-
sendToGa(name + '.set', 'anonymizeIp', true)
|
153
|
-
sendToGa(name + '.set', 'displayFeaturesTask', null)
|
154
|
-
sendToGa(name + '.send', 'pageview')
|
155
|
-
}
|
156
|
-
|
157
|
-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
|
158
|
-
GoogleAnalyticsUniversalTracker.prototype.setDimension = function (index, value) {
|
159
|
-
sendToGa('set', 'dimension' + index, String(value))
|
160
|
-
}
|
161
|
-
|
162
|
-
function sendToGa () {
|
163
|
-
if (typeof global.ga === 'function') {
|
164
|
-
global.ga.apply(global, arguments)
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
function stripEmailAddressesFromString (string) {
|
169
|
-
var stripped = string.replace(/[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g, '[email]')
|
170
|
-
return stripped
|
171
|
-
}
|
172
|
-
|
173
|
-
GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker
|
174
|
-
|
175
|
-
global.GOVUK = GOVUK
|
176
|
-
})(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)
|
@@ -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)
|