govuk_publishing_components 40.0.0 → 41.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +1 -79
  3. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +1 -34
  4. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +0 -17
  5. data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +0 -6
  6. data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +0 -7
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +8 -74
  8. data/app/assets/javascripts/govuk_publishing_components/dependencies.js +0 -4
  9. data/app/assets/javascripts/govuk_publishing_components/domain-config.js +0 -8
  10. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +0 -4
  11. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js +0 -14
  12. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +0 -20
  13. data/app/assets/javascripts/govuk_publishing_components/lib/toggle.js +0 -33
  14. data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +0 -25
  15. data/app/views/govuk_publishing_components/components/_accordion.html.erb +1 -8
  16. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -1
  17. data/app/views/govuk_publishing_components/components/_cards.html.erb +3 -11
  18. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +2 -15
  19. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +3 -19
  20. data/app/views/govuk_publishing_components/components/_details.html.erb +9 -11
  21. data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -5
  22. data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -4
  23. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +7 -21
  24. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +2 -26
  25. data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -5
  26. data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -7
  27. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +0 -10
  28. data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +1 -3
  29. data/app/views/govuk_publishing_components/components/_search.html.erb +3 -1
  30. data/app/views/govuk_publishing_components/components/_select.html.erb +1 -2
  31. data/app/views/govuk_publishing_components/components/_share_links.html.erb +1 -10
  32. data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +0 -1
  33. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +1 -1
  34. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +1 -24
  35. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +1 -14
  36. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +1 -4
  37. data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +0 -1
  38. data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +1 -7
  39. data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -60
  40. data/app/views/govuk_publishing_components/components/docs/big_number.yml +2 -6
  41. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +0 -1
  42. data/app/views/govuk_publishing_components/components/docs/button.yml +1 -1
  43. data/app/views/govuk_publishing_components/components/docs/cards.yml +3 -13
  44. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +0 -33
  45. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -2
  46. data/app/views/govuk_publishing_components/components/docs/details.yml +0 -15
  47. data/app/views/govuk_publishing_components/components/docs/document_list.yml +11 -18
  48. data/app/views/govuk_publishing_components/components/docs/error_alert.yml +1 -1
  49. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +0 -11
  50. data/app/views/govuk_publishing_components/components/docs/image_card.yml +0 -31
  51. data/app/views/govuk_publishing_components/components/docs/intervention.yml +0 -26
  52. data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +2 -2
  53. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +0 -2
  54. data/app/views/govuk_publishing_components/components/docs/option_select.yml +4 -16
  55. data/app/views/govuk_publishing_components/components/docs/organisation_logo.yml +0 -15
  56. data/app/views/govuk_publishing_components/components/docs/print_link.yml +2 -9
  57. data/app/views/govuk_publishing_components/components/docs/search.yml +12 -0
  58. data/app/views/govuk_publishing_components/components/docs/select.yml +0 -36
  59. data/app/views/govuk_publishing_components/components/docs/share_links.yml +2 -4
  60. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +2 -25
  61. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +0 -23
  62. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +0 -10
  63. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +3 -15
  64. data/app/views/govuk_publishing_components/components/docs/table.yml +1 -1
  65. data/app/views/govuk_publishing_components/components/docs/tabs.yml +1 -1
  66. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +3 -27
  67. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +1 -5
  68. data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +0 -2
  69. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +0 -10
  70. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  71. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +1 -5
  72. data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +0 -7
  73. data/lib/govuk_publishing_components/presenters/breadcrumbs_helper.rb +1 -19
  74. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +1 -15
  75. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +2 -24
  76. data/lib/govuk_publishing_components/presenters/select_helper.rb +0 -4
  77. data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +0 -5
  78. data/lib/govuk_publishing_components/presenters/translation_nav_helper.rb +0 -7
  79. data/lib/govuk_publishing_components/version.rb +1 -1
  80. metadata +3 -25
  81. data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +0 -92
  82. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +0 -221
  83. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +0 -30
  84. data/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js +0 -55
  85. data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +0 -133
  86. data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +0 -46
  87. data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +0 -101
  88. data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +0 -51
  89. data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +0 -88
  90. data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +0 -68
  91. data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +0 -220
  92. data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +0 -60
  93. data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +0 -135
  94. data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +0 -43
  95. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +0 -160
  96. data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +0 -115
  97. data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +0 -39
  98. data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +0 -132
  99. data/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +0 -75
  100. data/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +0 -56
  101. data/app/assets/javascripts/govuk_publishing_components/analytics.js +0 -23
  102. data/app/assets/javascripts/govuk_publishing_components/components/details.js +0 -48
@@ -1,221 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {}
3
- window.GOVUK.analyticsVars = window.GOVUK.analyticsVars || {};
4
-
5
- (function (Modules) {
6
- function AutoScrollTracker ($module) {
7
- this.$module = $module
8
- this.pageHeight = document.querySelector('body').clientHeight
9
- this.trackedNodes = []
10
- this.config = {
11
- allowHeadingsInside: ['main'],
12
- percentages: [20, 40, 60, 80, 100],
13
- scrollTimeoutDelay: 20,
14
- resizeTimeoutDelay: 100,
15
- pageHeightTimeoutDelay: 500
16
- }
17
- }
18
-
19
- AutoScrollTracker.prototype.init = function () {
20
- var consentCookie = window.GOVUK.getConsentCookie()
21
-
22
- if (consentCookie && consentCookie.usage) {
23
- this.startModule()
24
- } else {
25
- this.start = this.startModule.bind(this)
26
- window.addEventListener('cookie-consent', this.start)
27
- }
28
- }
29
-
30
- AutoScrollTracker.prototype.startModule = function () {
31
- window.removeEventListener('cookie-consent', this.start)
32
- if (window.GOVUK.analyticsVars.scrollTrackerStarted) {
33
- return
34
- }
35
-
36
- this.trackType = this.$module.getAttribute('data-track-type')
37
- var trackHeadings = this.$module.getAttribute('data-track-headings')
38
- if (trackHeadings) {
39
- try {
40
- this.config.trackHeadings = JSON.parse(trackHeadings)
41
- } catch (e) {
42
- // if there's a problem with the config, don't start the tracker
43
- console.error('Scroll tracker configuration error: ' + e.message, window.location)
44
- window.GOVUK.analyticsVars.scrollTrackerStarted = false
45
- return
46
- }
47
- }
48
-
49
- window.GOVUK.analyticsVars.scrollTrackerStarted = true
50
-
51
- if (this.trackType === 'headings') {
52
- this.track = new AutoScrollTracker.Heading(this.config)
53
- } else {
54
- this.track = new AutoScrollTracker.Percentage(this.config)
55
- }
56
-
57
- this.getWindowDetails()
58
- // if the URL has a hash we want to prevent tracking on initial page load
59
- // until the browser jumps down the page, at which point a scroll event
60
- // will happen and tracking will continue normally
61
- var windowHash = window.location.hash
62
- var dontTrackOnLoad = windowHash && document.getElementById(windowHash.substring(1))
63
- if (!dontTrackOnLoad) {
64
- this.trackVisibleNodes()
65
- }
66
-
67
- if (this.trackedNodes.length) {
68
- // store event listener functions as variables so they can be removed if needed
69
- this.scrollEvent = this.onScroll.bind(this)
70
- window.addEventListener('scroll', this.scrollEvent)
71
- this.resizeEvent = this.onResize.bind(this)
72
- window.addEventListener('resize', this.resizeEvent)
73
-
74
- // check if the page height changes e.g. accordion opened
75
- this.interval = window.setInterval(function () {
76
- var pageHeight = document.querySelector('body').clientHeight
77
- if (pageHeight !== this.pageHeight) {
78
- this.pageHeight = pageHeight
79
- this.getWindowDetails()
80
- this.trackVisibleNodes()
81
- }
82
- }.bind(this), this.config.pageHeightTimeoutDelay)
83
- }
84
- }
85
-
86
- AutoScrollTracker.prototype.onScroll = function () {
87
- clearTimeout(this.scrollTimeout)
88
- this.scrollTimeout = setTimeout(function () {
89
- this.trackVisibleNodes()
90
- }.bind(this), this.config.scrollTimeoutDelay)
91
- }
92
-
93
- AutoScrollTracker.prototype.onResize = function () {
94
- clearTimeout(this.resizeTimeout)
95
- this.resizeTimeout = setTimeout(function () {
96
- this.getWindowDetails()
97
- this.trackVisibleNodes()
98
- }.bind(this), this.config.resizeTimeoutDelay)
99
- }
100
-
101
- AutoScrollTracker.prototype.getWindowDetails = function () {
102
- this.pageHeight = document.querySelector('body').clientHeight
103
- this.windowHeight = window.innerHeight
104
- this.trackedNodes = this.track.getTrackingNodes(this.trackedNodes)
105
- }
106
-
107
- AutoScrollTracker.prototype.trackVisibleNodes = function () {
108
- for (var i = 0; i < this.trackedNodes.length; i++) {
109
- var node = this.trackedNodes[i]
110
- if (this.isVisible(node.top, node.bottom) && !node.alreadySeen) {
111
- node.alreadySeen = true
112
- // we store whether a heading has been tracked or not on the heading
113
- // because if headings appear/disapper (e.g. inside an accordion)
114
- // the order changes, so we can't refer to the previous trackedNodes
115
- // as we do with percentages
116
- if (node.node) {
117
- node.node.setAttribute('data-autoscrolltracker-already-seen', true)
118
- }
119
-
120
- var action = node.eventData.action
121
- var label = node.eventData.label
122
-
123
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
124
- window.GOVUK.analytics.trackEvent('ScrollTo', action, { label: label, nonInteraction: true })
125
- }
126
- }
127
- }
128
- }
129
-
130
- AutoScrollTracker.prototype.isVisible = function (top, bottom) {
131
- var scroll = window.scrollY || document.documentElement.scrollTop // IE fallback
132
- return scroll <= top && (scroll + this.windowHeight) >= bottom
133
- }
134
-
135
- AutoScrollTracker.Heading = function (config) {
136
- this.config = config
137
- }
138
-
139
- AutoScrollTracker.Heading.prototype.getTrackingNodes = function () {
140
- var headingsDetails = []
141
- var headingsFound = this.findAllowedHeadings()
142
-
143
- for (var i = 0; i < headingsFound.length; i++) {
144
- var heading = headingsFound[i]
145
- // only track headings that are visible i.e. not inside display: none
146
- if (this.visible(heading)) {
147
- var pos = heading.getBoundingClientRect()
148
- headingsDetails.push({
149
- node: heading,
150
- alreadySeen: heading.getAttribute('data-autoscrolltracker-already-seen'),
151
- top: pos.top + document.documentElement.scrollTop,
152
- bottom: pos.bottom + document.documentElement.scrollTop,
153
- eventData: { action: 'Heading', label: heading.textContent.replace(/\s+/g, ' ').trim() }
154
- })
155
- }
156
- }
157
- return headingsDetails
158
- }
159
-
160
- // check heading is inside allowed elements, generally ignores everything outside of page content
161
- AutoScrollTracker.Heading.prototype.findAllowedHeadings = function () {
162
- var headingsFound = []
163
- var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
164
- var trackHeadings = this.config.trackHeadings
165
-
166
- // this is a loop that only happens once as we currently only have one
167
- // allowed element for headings to be in - 'main'
168
- for (var h = 0; h < this.config.allowHeadingsInside.length; h++) {
169
- var insideElements = document.querySelectorAll(this.config.allowHeadingsInside[h])
170
- for (var e = 0; e < insideElements.length; e++) {
171
- var found = insideElements[e].querySelectorAll(headings)
172
- for (var f = 0; f < found.length; f++) {
173
- if (trackHeadings) {
174
- if (trackHeadings.includes(found[f].textContent.trim())) {
175
- headingsFound.push(found[f])
176
- }
177
- } else {
178
- headingsFound.push(found[f])
179
- }
180
- }
181
- }
182
- }
183
- return headingsFound
184
- }
185
-
186
- // this is bit more verbose than checking offsetParent !== null but more reliable for IE10+
187
- AutoScrollTracker.Heading.prototype.visible = function (el) {
188
- return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length)
189
- }
190
-
191
- AutoScrollTracker.Percentage = function (config) {
192
- this.config = config
193
- }
194
-
195
- AutoScrollTracker.Percentage.prototype.getTrackingNodes = function (trackedNodes) {
196
- var body = document.body
197
- var html = document.documentElement
198
- var pageHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight)
199
-
200
- var percentDetails = []
201
-
202
- for (var i = 0; i < this.config.percentages.length; i++) {
203
- var percent = this.config.percentages[i]
204
- // subtract 1 pixel to solve a bug where 100% can't be reached in some cases
205
- var pos = ((pageHeight / 100) * percent) - 1
206
- var alreadySeen = false
207
- if (trackedNodes.length) {
208
- alreadySeen = trackedNodes[i].alreadySeen
209
- }
210
- percentDetails.push({
211
- alreadySeen: alreadySeen,
212
- top: pos,
213
- bottom: pos,
214
- eventData: { action: 'Percent', label: String(percent) }
215
- })
216
- }
217
- return percentDetails
218
- }
219
-
220
- Modules.AutoScrollTracker = AutoScrollTracker
221
- })(window.GOVUK.Modules)
@@ -1,30 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {};
3
-
4
- (function (Modules) {
5
- function AutoTrackEvent ($module) {
6
- this.$module = $module
7
- }
8
-
9
- AutoTrackEvent.prototype.init = function () {
10
- var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
11
- var category = this.$module.getAttribute('data-track-category')
12
- var action = this.$module.getAttribute('data-track-action')
13
- var label = this.$module.getAttribute('data-track-label')
14
- var value = parseInt(this.$module.getAttribute('data-track-value'))
15
-
16
- if (typeof label === 'string') {
17
- options.label = label
18
- }
19
-
20
- if (value || value === 0) {
21
- options.value = value
22
- }
23
-
24
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
25
- window.GOVUK.analytics.trackEvent(category, action, options)
26
- }
27
- }
28
-
29
- Modules.AutoTrackEvent = AutoTrackEvent
30
- })(window.GOVUK.Modules)
@@ -1,55 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {};
3
-
4
- (function (Modules) {
5
- function CrossDomainTracking ($module) {
6
- this.$module = $module
7
- Modules.crossDomainLinkedTrackers = Modules.crossDomainLinkedTrackers || []
8
- }
9
-
10
- CrossDomainTracking.prototype.init = function () {
11
- if (this.isTrackable(this.$module)) {
12
- this.addLinkedTrackerDomain(this.$module)
13
- } else {
14
- this.findTrackableElements()
15
- }
16
- }
17
-
18
- CrossDomainTracking.prototype.isTrackable = function (element) {
19
- if (element.getAttribute('href') && element.getAttribute('data-tracking-code') && element.getAttribute('data-tracking-name')) {
20
- return true
21
- }
22
- }
23
-
24
- CrossDomainTracking.prototype.findTrackableElements = function () {
25
- var links = this.$module.querySelectorAll('a')
26
- for (var i = 0; i < links.length; i++) {
27
- if (this.isTrackable(links[i])) {
28
- this.addLinkedTrackerDomain(links[i])
29
- }
30
- }
31
- }
32
-
33
- CrossDomainTracking.prototype.addLinkedTrackerDomain = function (element) {
34
- var name = element.getAttribute('data-tracking-name')
35
- var code = element.getAttribute('data-tracking-code')
36
- var trackEvent = (element.getAttribute('data-tracking-track-event') === 'true')
37
-
38
- if (window.GOVUK.analytics !== 'undefined') {
39
- if (Modules.crossDomainLinkedTrackers.indexOf(name) === -1) {
40
- var hostname = element.hostname
41
- window.GOVUK.analytics.addLinkedTrackerDomain(code, name, hostname)
42
- Modules.crossDomainLinkedTrackers.push(name)
43
- }
44
-
45
- if (trackEvent) {
46
- element.addEventListener('click', function (e) {
47
- var target = e.target
48
- window.GOVUK.analytics.trackEvent('External Link Clicked', target.textContent, { trackerName: name })
49
- })
50
- }
51
- }
52
- }
53
-
54
- Modules.CrossDomainTracking = CrossDomainTracking
55
- })(window.GOVUK.Modules)
@@ -1,133 +0,0 @@
1
- /* global GOVUK */
2
-
3
- (function () {
4
- 'use strict'
5
- window.GOVUK = window.GOVUK || {}
6
- var CustomDimensions = function () { }
7
-
8
- CustomDimensions.getAndExtendDefaultTrackingOptions = function (extraOptions) {
9
- var trackingOptions = this.customDimensions()
10
- return GOVUK.extendObject(trackingOptions, extraOptions)
11
- }
12
-
13
- CustomDimensions.customDimensions = function () {
14
- var dimensions = GOVUK.extendObject(
15
- {},
16
- customDimensionsFromBrowser(),
17
- customDimensionsFromMetaTags(),
18
- customDimensionsFromDom(),
19
- abTestCustomDimensions()
20
- )
21
-
22
- for (var key in dimensions) {
23
- dimensions[key] = new GOVUK.Analytics.PIISafe(String(dimensions[key]))
24
- }
25
- return dimensions
26
- }
27
-
28
- function customDimensionsFromBrowser () {
29
- var customDimensions = {
30
- dimension15: window.httpStatusCode || 200,
31
- dimension16: GOVUK.cookie('TLSversion') || 'unknown',
32
- dimension95: GOVUK.analytics.gaClientId
33
- }
34
-
35
- if (window.devicePixelRatio) {
36
- customDimensions.dimension11 = window.devicePixelRatio
37
- } else {
38
- customDimensions.dimension11 = window.screen.deviceXDPI / window.screen.logicalXDPI
39
- }
40
-
41
- return customDimensions
42
- }
43
-
44
- function customDimensionsFromMetaTags () {
45
- var dimensionMappings = {
46
- section: { dimension: 1 },
47
- format: { dimension: 2 },
48
- themes: { dimension: 3, defaultValue: 'other' },
49
- 'content-id': { dimension: 4, defaultValue: '00000000-0000-0000-0000-000000000000' },
50
- 'search-result-count': { dimension: 5 },
51
- 'publishing-government': { dimension: 6 },
52
- 'political-status': { dimension: 7 },
53
- 'analytics:organisations': { dimension: 9 },
54
- 'analytics:world-locations': { dimension: 10 },
55
- withdrawn: { dimension: 12, defaultValue: 'not withdrawn' },
56
- 'schema-name': { dimension: 17 },
57
- 'rendering-application': { dimension: 20 },
58
- 'search-autocomplete-status': { dimension: 21 },
59
- 'navigation-legacy': { dimension: 30, defaultValue: 'none' },
60
- 'navigation-list-type': { dimension: 31, defaultValue: 'none' },
61
- 'navigation-page-type': { dimension: 32, defaultValue: 'none' },
62
- 'taxon-slug': { dimension: 56, defaultValue: 'other' },
63
- 'taxon-id': { dimension: 57, defaultValue: 'other' },
64
- 'taxon-slugs': { dimension: 58, defaultValue: 'other' },
65
- 'taxon-ids': { dimension: 59, defaultValue: 'other' },
66
- 'content-has-history': { dimension: 39, defaultValue: 'false' },
67
- 'publishing-app': { dimension: 89 },
68
- 'brexit-audience': { dimension: 112 },
69
- 'brexit-superbreadcrumb': { dimension: 111 },
70
- stepnavs: { dimension: 96 },
71
- 'relevant-result-shown': { dimension: 83 },
72
- 'spelling-suggestion': { dimension: 81 }
73
- }
74
-
75
- var metas = document.querySelectorAll("meta[name^='govuk']")
76
- var customDimensions = {}
77
- var tags = {}
78
-
79
- for (var i = 0; i < metas.length; i++) {
80
- var meta = metas[i]
81
- var metaKey = meta.getAttribute('name').split('govuk:')[1]
82
- var dimension = dimensionMappings[metaKey]
83
- if (dimension) {
84
- tags[metaKey] = meta.getAttribute('content')
85
- }
86
- }
87
-
88
- for (var key in dimensionMappings) {
89
- var value = tags[key] || dimensionMappings[key].defaultValue
90
- if (typeof value !== 'undefined') {
91
- customDimensions['dimension' + dimensionMappings[key].dimension] = value
92
- }
93
- }
94
-
95
- return customDimensions
96
- }
97
-
98
- function customDimensionsFromDom () {
99
- var mainLang = document.getElementById('content')
100
- if (mainLang) {
101
- mainLang = mainLang.getAttribute('lang')
102
- }
103
- var globalBar = document.querySelector('[data-module="global-bar"]') || false
104
- if (globalBar) {
105
- globalBar = globalBar.style.display !== 'none'
106
- }
107
- return {
108
- dimension26: GOVUK.PageContent.getNumberOfSections(),
109
- dimension27: GOVUK.PageContent.getNumberOfLinks(),
110
- dimension23: mainLang || 'unknown',
111
- dimension38: globalBar && 'Global Banner viewed'
112
- }
113
- }
114
-
115
- function abTestCustomDimensions () {
116
- var abMetas = document.querySelectorAll("meta[name^='govuk:ab-test']")
117
- var customDimensions = {}
118
-
119
- for (var i = 0; i < abMetas.length; i++) {
120
- var meta = abMetas[i]
121
- var dimension = parseInt(meta.getAttribute('data-analytics-dimension'))
122
- var testNameAndBucket = meta.getAttribute('content')
123
-
124
- if (dimension) {
125
- customDimensions['dimension' + dimension] = testNameAndBucket
126
- }
127
- }
128
-
129
- return customDimensions
130
- }
131
-
132
- GOVUK.CustomDimensions = CustomDimensions
133
- })()
@@ -1,46 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
-
6
- GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
7
- GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
8
- options = options || {}
9
- var downloadLinkSelector = options.selector
10
- var selectors = downloadLinkSelector.split(',')
11
-
12
- if (downloadLinkSelector) {
13
- document.querySelector('body').addEventListener('click', function (event) {
14
- var element = event.target
15
- if (element.tagName !== 'A') {
16
- element = element.closest('a')
17
- }
18
-
19
- if (!element) {
20
- return
21
- }
22
-
23
- for (var i = 0; i < selectors.length; i++) {
24
- if (element.matches(selectors[i].trim())) {
25
- trackDownload(element)
26
- break
27
- }
28
- }
29
- })
30
- }
31
-
32
- function trackDownload (element) {
33
- var href = element.getAttribute('href')
34
- var evtOptions = { transport: 'beacon' }
35
- var linkText = element.textContent.trim()
36
-
37
- if (linkText) {
38
- evtOptions.label = linkText
39
- }
40
-
41
- GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
42
- }
43
- }
44
-
45
- global.GOVUK = GOVUK
46
- })(window)
@@ -1,101 +0,0 @@
1
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
2
- /* global GOVUK, ga */
3
-
4
- (function () {
5
- 'use strict'
6
- window.GOVUK = window.GOVUK || {}
7
-
8
- var DEFAULT_LIST_TITLE = 'Site search results'
9
- var DEFAULT_TRACK_CLICK_LABEL = 'Results'
10
-
11
- var Ecommerce = function (config) {
12
- this.init = function (element) {
13
- // Limiting to 100 characters to avoid noise from extra longs search queries
14
- // and to stop the size of the payload going over 8k limit.
15
- var searchQuery = GOVUK.analytics.stripPII(element.getAttribute('data-search-query')).substring(0, 100).toLowerCase()
16
- var ecommerceRows = element.querySelectorAll('[data-ecommerce-row]')
17
- var startPosition = parseInt(element.getAttribute('data-ecommerce-start-index'), 10)
18
- var listTitle = element.getAttribute('data-list-title') || DEFAULT_LIST_TITLE
19
- var variant = element.getAttribute('data-ecommerce-variant') || undefined
20
- var trackClickLabel = element.getAttribute('data-track-click-label') || DEFAULT_TRACK_CLICK_LABEL
21
-
22
- for (var i = 0; i < ecommerceRows.length; i++) {
23
- var ecommerceRow = ecommerceRows[i]
24
- var listSubheading = ecommerceRow.getAttribute('data-ecommerce-subheading') || undefined
25
- var contentId = ecommerceRow.getAttribute('data-ecommerce-content-id') || undefined
26
- var path = ecommerceRow.getAttribute('data-ecommerce-path')
27
-
28
- var indexOverride = ecommerceRow.getAttribute('data-ecommerce-index')
29
- var index = indexOverride ? parseInt(indexOverride, 10) - 1 : i
30
-
31
- addImpression(contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant)
32
- trackProductOnClick(ecommerceRow, contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant, trackClickLabel)
33
- }
34
- }
35
-
36
- function constructData (contentId, path, position, listTitle, listSubheading, searchQuery, variant) {
37
- var data = {
38
- position: position,
39
- list: listTitle,
40
- dimension71: searchQuery
41
- }
42
-
43
- if (listSubheading !== undefined) {
44
- data.dimension94 = listSubheading
45
- }
46
-
47
- if (contentId !== undefined) {
48
- data.id = contentId
49
- }
50
-
51
- if (path !== undefined) {
52
- data.name = path
53
- }
54
-
55
- if (variant !== undefined) {
56
- data.variant = variant
57
- }
58
-
59
- return data
60
- }
61
-
62
- function addImpression (contentId, path, position, searchQuery, listTitle, listSubheading, variant) {
63
- if (contentId || path) {
64
- var impressionData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
65
- ga('ec:addImpression', impressionData)
66
- }
67
- }
68
-
69
- function trackProductOnClick (row, contentId, path, position, searchQuery, listTitle, listSubheading, variant, trackClickLabel) {
70
- row.addEventListener('click', function () {
71
- if (contentId || path) {
72
- var clickData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
73
- ga('ec:addProduct', clickData)
74
- }
75
-
76
- ga('ec:setAction', 'click', { list: listTitle })
77
- GOVUK.analytics.trackEvent('UX', 'click',
78
- GOVUK.CustomDimensions.getAndExtendDefaultTrackingOptions({ label: trackClickLabel })
79
- )
80
- })
81
- }
82
- }
83
-
84
- Ecommerce.ecLoaded = false
85
- Ecommerce.start = function (elements) {
86
- if (!window.ga) { return }
87
- elements = elements || document.querySelectorAll('[data-analytics-ecommerce]')
88
- if (elements.length > 0) {
89
- if (!Ecommerce.ecLoaded) {
90
- ga('require', 'ec')
91
- Ecommerce.ecLoaded = true
92
- }
93
- for (var i = 0; i < elements.length; i++) {
94
- var ecommerce = new Ecommerce()
95
- ecommerce.init(elements[i])
96
- }
97
- }
98
- }
99
-
100
- GOVUK.Ecommerce = Ecommerce
101
- })()
@@ -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)