govuk_publishing_components 40.1.0 → 41.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) 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/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +192 -171
  16. data/app/assets/stylesheets/component_guide/application.scss +10 -11
  17. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +1 -1
  18. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +2 -3
  19. data/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss +3 -3
  20. data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +1 -1
  21. data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +2 -2
  22. data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +47 -22
  23. data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +3 -3
  24. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-guidance.scss +1 -3
  25. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +2 -1
  26. data/app/assets/stylesheets/govuk_publishing_components/components/_cross-service-header.scss +19 -19
  27. data/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +14 -10
  28. data/app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss +3 -3
  29. data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +2 -2
  30. data/app/assets/stylesheets/govuk_publishing_components/components/_error-summary.scss +1 -1
  31. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +8 -8
  32. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +16 -10
  33. data/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss +2 -2
  34. data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +2 -2
  35. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +33 -35
  36. data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +3 -3
  37. data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +1 -1
  38. data/app/assets/stylesheets/govuk_publishing_components/components/_notice.scss +1 -1
  39. data/app/assets/stylesheets/govuk_publishing_components/components/_option-select.scss +3 -3
  40. data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +13 -3
  41. data/app/assets/stylesheets/govuk_publishing_components/components/_panel.scss +1 -1
  42. data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +6 -6
  43. data/app/assets/stylesheets/govuk_publishing_components/components/_reorderable-list.scss +2 -3
  44. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +4 -3
  45. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +2 -3
  46. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +3 -4
  47. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +3 -3
  48. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +10 -10
  49. data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +1 -1
  50. data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +1 -1
  51. data/app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss +3 -3
  52. data/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss +1 -1
  53. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +5 -4
  54. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +1 -1
  55. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_highlight-answer.scss +2 -2
  56. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_stat-headline.scss +2 -2
  57. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +1 -1
  58. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_warning-callout.scss +1 -1
  59. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +5 -5
  60. data/app/views/govuk_publishing_components/components/_accordion.html.erb +1 -8
  61. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -1
  62. data/app/views/govuk_publishing_components/components/_cards.html.erb +6 -11
  63. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +2 -15
  64. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +3 -19
  65. data/app/views/govuk_publishing_components/components/_details.html.erb +9 -11
  66. data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -5
  67. data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -4
  68. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +7 -21
  69. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +1 -26
  70. data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -5
  71. data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -7
  72. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +0 -10
  73. data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +1 -3
  74. data/app/views/govuk_publishing_components/components/_search.html.erb +0 -1
  75. data/app/views/govuk_publishing_components/components/_select.html.erb +1 -2
  76. data/app/views/govuk_publishing_components/components/_share_links.html.erb +1 -10
  77. data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +0 -1
  78. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +1 -1
  79. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +1 -24
  80. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +1 -14
  81. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +1 -4
  82. data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +0 -1
  83. data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +1 -7
  84. data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -60
  85. data/app/views/govuk_publishing_components/components/docs/big_number.yml +2 -6
  86. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +0 -1
  87. data/app/views/govuk_publishing_components/components/docs/button.yml +1 -1
  88. data/app/views/govuk_publishing_components/components/docs/cards.yml +41 -20
  89. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +0 -33
  90. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -2
  91. data/app/views/govuk_publishing_components/components/docs/details.yml +0 -15
  92. data/app/views/govuk_publishing_components/components/docs/document_list.yml +11 -18
  93. data/app/views/govuk_publishing_components/components/docs/error_alert.yml +1 -1
  94. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +0 -11
  95. data/app/views/govuk_publishing_components/components/docs/image_card.yml +0 -31
  96. data/app/views/govuk_publishing_components/components/docs/intervention.yml +0 -26
  97. data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +2 -2
  98. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +0 -2
  99. data/app/views/govuk_publishing_components/components/docs/option_select.yml +4 -16
  100. data/app/views/govuk_publishing_components/components/docs/organisation_logo.yml +0 -15
  101. data/app/views/govuk_publishing_components/components/docs/print_link.yml +2 -9
  102. data/app/views/govuk_publishing_components/components/docs/select.yml +0 -36
  103. data/app/views/govuk_publishing_components/components/docs/share_links.yml +2 -4
  104. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +2 -25
  105. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +0 -23
  106. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +0 -10
  107. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +3 -15
  108. data/app/views/govuk_publishing_components/components/docs/table.yml +1 -1
  109. data/app/views/govuk_publishing_components/components/docs/tabs.yml +1 -1
  110. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +3 -27
  111. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +1 -5
  112. data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +0 -2
  113. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +0 -10
  114. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  115. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +0 -5
  116. data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +0 -7
  117. data/lib/govuk_publishing_components/presenters/breadcrumbs_helper.rb +1 -19
  118. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +1 -15
  119. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +2 -24
  120. data/lib/govuk_publishing_components/presenters/select_helper.rb +0 -4
  121. data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +0 -5
  122. data/lib/govuk_publishing_components/presenters/translation_nav_helper.rb +0 -7
  123. data/lib/govuk_publishing_components/version.rb +1 -1
  124. metadata +4 -26
  125. data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +0 -92
  126. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +0 -221
  127. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +0 -30
  128. data/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js +0 -55
  129. data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +0 -133
  130. data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +0 -46
  131. data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +0 -101
  132. data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +0 -51
  133. data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +0 -88
  134. data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +0 -68
  135. data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +0 -220
  136. data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +0 -60
  137. data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +0 -135
  138. data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +0 -43
  139. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +0 -160
  140. data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +0 -115
  141. data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +0 -39
  142. data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +0 -132
  143. data/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +0 -75
  144. data/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +0 -56
  145. data/app/assets/javascripts/govuk_publishing_components/analytics.js +0 -23
  146. data/app/assets/javascripts/govuk_publishing_components/components/details.js +0 -48
@@ -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)
@@ -1,88 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {};
3
-
4
- (function (Modules) {
5
- function ExplicitCrossDomainLinks ($module) {
6
- this.$module = $module
7
- }
8
-
9
- ExplicitCrossDomainLinks.prototype.init = function () {
10
- this.attribute = 'href'
11
- this.attributeValue = this.$module.getAttribute(this.attribute)
12
- this.eventType = 'click'
13
- if (!this.attributeValue) {
14
- this.attribute = 'action'
15
- this.attributeValue = this.$module.getAttribute(this.attribute)
16
- this.eventType = 'submit'
17
- }
18
-
19
- this.handleEvent = this.handleEvent.bind(this)
20
- this.handleCookiesAccepted = this.handleCookiesAccepted.bind(this)
21
- // Listens for the 'submit' event if the element is a form, and the 'click' event if it is a link
22
- this.$module.addEventListener(this.eventType, this.handleEvent)
23
- }
24
-
25
- ExplicitCrossDomainLinks.prototype.decorate = function (element, param, attribute) {
26
- var attributeValue = element.getAttribute(attribute)
27
-
28
- if (!attributeValue) { return }
29
-
30
- if (attributeValue.indexOf('?') !== -1) {
31
- attributeValue += '&' + param
32
- } else {
33
- attributeValue += '?' + param
34
- }
35
-
36
- element.setAttribute(attribute, attributeValue)
37
- }
38
-
39
- ExplicitCrossDomainLinks.prototype.handleEvent = function (e) {
40
- // prevent default: we want the link href and/or form action to be decorated before we navigate away
41
- e.preventDefault()
42
- var cookieBannerEngaged = window.GOVUK.cookie('cookies_preferences_set')
43
- var cookieConsent = window.GOVUK.getConsentCookie()
44
-
45
- if (cookieBannerEngaged !== 'true') {
46
- // If not engaged, append only ?cookie_consent=not-engaged
47
- this.decorate(this.$module, 'cookie_consent=not-engaged', this.attribute)
48
- } else if (cookieConsent && cookieConsent.usage === true) {
49
- this.handleCookiesAccepted()
50
- } else {
51
- this.decorate(this.$module, 'cookie_consent=reject', this.attribute)
52
- }
53
-
54
- // remove the event listener to avoid an infinite loop
55
- this.$module.removeEventListener(this.eventType, this.handleEvent)
56
-
57
- // if the element is a form, submit it. If it is a link, click it
58
- if (this.eventType === 'submit') {
59
- this.$module.submit()
60
- } else {
61
- this.$module.click()
62
- }
63
- }
64
-
65
- ExplicitCrossDomainLinks.prototype.handleCookiesAccepted = function () {
66
- // If the cookie banner was engaged and usage cookie accepted, append ?_ga=clientid if available and cookie_consent=accept
67
- var element = this.$module
68
- var attribute = this.attribute
69
- this.decorate(element, 'cookie_consent=accept', attribute)
70
-
71
- if (!window.ga) {
72
- return
73
- }
74
-
75
- window.ga(function () {
76
- var trackers = window.ga.getAll()
77
-
78
- if (!trackers.length) { return }
79
-
80
- var linker = new window.gaplugins.Linker(trackers[0])
81
- var attrValue = element.getAttribute(attribute)
82
-
83
- element.setAttribute(attribute, linker.decorate(attrValue))
84
- })
85
- }
86
-
87
- Modules.ExplicitCrossDomainLinks = ExplicitCrossDomainLinks
88
- })(window.GOVUK.Modules)
@@ -1,68 +0,0 @@
1
- // = require ../vendor/polyfills-govuk-frontend-v4/Element/prototype/closest.js
2
- ;(function (global) {
3
- 'use strict'
4
-
5
- var GOVUK = global.GOVUK || {}
6
-
7
- GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
8
- GOVUK.analyticsPlugins.externalLinkTracker = function (options) {
9
- options = options || {}
10
- GOVUK.analyticsPlugins.externalLinkTracker.options = options
11
- document.querySelector('body').addEventListener('click', GOVUK.analyticsPlugins.externalLinkTracker.handleClick)
12
- }
13
-
14
- GOVUK.analyticsPlugins.externalLinkTracker.handleClick = function (event) {
15
- var element = event.target
16
- if (element.tagName !== 'A') {
17
- element = element.closest('a')
18
- }
19
-
20
- if (!element) {
21
- return
22
- }
23
-
24
- if (GOVUK.analyticsPlugins.externalLinkTracker.isExternalLink(element.getAttribute('href'))) {
25
- GOVUK.analyticsPlugins.externalLinkTracker.trackClickEvent(element)
26
- }
27
- }
28
-
29
- GOVUK.analyticsPlugins.externalLinkTracker.isExternalLink = function (href) {
30
- if (!href) {
31
- return false
32
- }
33
-
34
- var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname()
35
- if (href.substring(0, 4) === 'http' && href.indexOf(currentHost) === -1) {
36
- return true
37
- }
38
- }
39
-
40
- GOVUK.analyticsPlugins.externalLinkTracker.trackClickEvent = function (element) {
41
- var options = { transport: 'beacon' }
42
- var href = element.getAttribute('href')
43
- var linkText = element.textContent.trim()
44
-
45
- if (linkText) {
46
- options.label = linkText
47
- }
48
-
49
- var externalLinkUploadCustomDimension = GOVUK.analyticsPlugins.externalLinkTracker.options.externalLinkUploadCustomDimension
50
- if (externalLinkUploadCustomDimension !== undefined) {
51
- // This custom dimension will be used to duplicate the url information
52
- // that we normally send in an "event action". This will be used to join
53
- // up with a scheduled custom upload called "External Link Status".
54
- // We can only join uploads on custom dimensions, not on `event actions`
55
- // where we normally add the url info.
56
- var externalLinkToJoinUploadOn = href
57
-
58
- GOVUK.analytics.setDimension(externalLinkUploadCustomDimension, externalLinkToJoinUploadOn)
59
- }
60
- GOVUK.analytics.trackEvent('External Link Clicked', href, options)
61
- }
62
-
63
- GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function () {
64
- return global.location.hostname
65
- }
66
-
67
- global.GOVUK = GOVUK
68
- })(window)
@@ -1,220 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
- var pii
6
-
7
- var GoogleAnalyticsUniversalTracker = function (trackingId, fieldsObject) {
8
- pii = new GOVUK.Pii()
9
-
10
- function configureProfile () {
11
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#create
12
- sendToGa('create', trackingId, fieldsObject)
13
- }
14
-
15
- function anonymizeIp () {
16
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip
17
- sendToGa('set', 'anonymizeIp', true)
18
- }
19
-
20
- function disableAdFeatures () {
21
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#allowAdFeatures
22
- sendToGa('set', 'allowAdFeatures', false)
23
- }
24
-
25
- function stripTitlePII () {
26
- sendToGa('set', 'title', pii.stripPII(document.title))
27
- }
28
-
29
- function stripLocationPII () {
30
- sendToGa('set', 'location', pii.stripPII(window.location.href))
31
- }
32
-
33
- // Support legacy cookieDomain param
34
- if (typeof fieldsObject === 'string') {
35
- fieldsObject = { cookieDomain: fieldsObject }
36
- }
37
-
38
- function setLinkedDomains () {
39
- var domains = window.GOVUK.analyticsVars.primaryLinkedDomains
40
- if (domains && domains.length > 0) {
41
- sendToGa('require', 'linker')
42
- sendToGa('linker:autoLink', domains)
43
- }
44
- }
45
-
46
- configureProfile()
47
- anonymizeIp()
48
- disableAdFeatures()
49
- stripTitlePII()
50
- stripLocationPII()
51
- setLinkedDomains()
52
- }
53
-
54
- GoogleAnalyticsUniversalTracker.load = function () {
55
- /* eslint-disable */
56
- (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
57
- (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
58
- m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
59
- })(global, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
60
- /* eslint-enable */
61
- }
62
-
63
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
64
- GoogleAnalyticsUniversalTracker.prototype.trackPageview = function (path, title, options) {
65
- var pageviewObject
66
- var trackerName = ''
67
-
68
- if (typeof path === 'string') {
69
- pageviewObject = { page: path }
70
- }
71
-
72
- if (typeof title === 'string') {
73
- pageviewObject = pageviewObject || {}
74
- pageviewObject.title = title
75
- }
76
-
77
- // Set an options object for the pageview (e.g. transport, sessionControl)
78
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
79
- if (typeof options === 'object') {
80
- pageviewObject = GOVUK.extendObject(pageviewObject || {}, options)
81
-
82
- // trackerName is optional
83
- if (typeof options.trackerName === 'string') {
84
- trackerName = options.trackerName + '.'
85
- delete options.trackerName
86
- }
87
- }
88
-
89
- function isEmptyObject (obj) {
90
- if (typeof obj === 'undefined') {
91
- return true
92
- }
93
-
94
- for (var prop in obj) {
95
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
96
- return false
97
- }
98
- }
99
-
100
- return JSON.stringify(obj) === JSON.stringify({})
101
- }
102
-
103
- if (isEmptyObject(pageviewObject)) {
104
- sendToGa(trackerName + 'send', 'pageview')
105
- } else {
106
- sendToGa(trackerName + 'send', 'pageview', pageviewObject)
107
- }
108
- }
109
-
110
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/events
111
- GoogleAnalyticsUniversalTracker.prototype.trackEvent = function (category, action, options) {
112
- options = options || {}
113
- var value
114
- var trackerName = ''
115
- var evt = {
116
- hitType: 'event',
117
- eventCategory: category,
118
- eventAction: action
119
- }
120
-
121
- // Label is optional
122
- if (typeof options.label === 'string') {
123
- evt.eventLabel = options.label
124
- delete options.label
125
- }
126
-
127
- // Value is optional, but when used must be an
128
- // integer, otherwise the event will be invalid
129
- // and not logged
130
- if (options.value || options.value === 0) {
131
- value = parseInt(options.value, 10)
132
- if (typeof value === 'number' && !isNaN(value)) {
133
- options.eventValue = value
134
- }
135
- delete options.value
136
- }
137
-
138
- // trackerName is optional
139
- if (typeof options.trackerName === 'string') {
140
- trackerName = options.trackerName + '.'
141
- delete options.trackerName
142
- }
143
-
144
- // Prevents an event from affecting bounce rate
145
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
146
- if (options.nonInteraction) {
147
- options.nonInteraction = 1
148
- }
149
-
150
- if (typeof options === 'object') {
151
- evt = GOVUK.extendObject(evt, options)
152
- }
153
-
154
- sendToGa(trackerName + 'send', evt)
155
- }
156
-
157
- /*
158
- https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
159
- network – The network on which the action occurs (e.g. Facebook, Twitter)
160
- action – The type of action that happens (e.g. Like, Send, Tweet)
161
- target – Specifies the target of a social interaction.
162
- This value is typically a URL but can be any text.
163
- */
164
- GoogleAnalyticsUniversalTracker.prototype.trackSocial = function (network, action, target, options) {
165
- var trackingOptions = {
166
- hitType: 'social',
167
- socialNetwork: network,
168
- socialAction: action,
169
- socialTarget: target
170
- }
171
-
172
- trackingOptions = GOVUK.extendObject(trackingOptions, options)
173
-
174
- sendToGa('send', trackingOptions)
175
- }
176
-
177
- /*
178
- https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
179
- trackerId - the UA account code to track the domain against
180
- name - name for the tracker
181
- domain - the domain to track (must be an array of strings)
182
- sendPageView - optional argument which controls the legacy behaviour of sending a pageview
183
- on creation of the linked domain.
184
- */
185
- GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain, sendPageView) {
186
- sendToGa('create',
187
- trackerId,
188
- 'auto',
189
- { name: name })
190
- // Load the plugin.
191
- sendToGa(name + '.require', 'linker')
192
-
193
- // Define which domains to autoLink.
194
- sendToGa(name + '.linker:autoLink', domain)
195
-
196
- sendToGa(name + '.set', 'anonymizeIp', true)
197
- sendToGa(name + '.set', 'allowAdFeatures', false)
198
- sendToGa(name + '.set', 'title', pii.stripPII(document.title))
199
- sendToGa(name + '.set', 'location', pii.stripPII(window.location.href))
200
-
201
- if (typeof sendPageView === 'undefined' || sendPageView === true) {
202
- sendToGa(name + '.send', 'pageview')
203
- }
204
- }
205
-
206
- // https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
207
- GoogleAnalyticsUniversalTracker.prototype.setDimension = function (index, value) {
208
- sendToGa('set', 'dimension' + index, String(value))
209
- }
210
-
211
- function sendToGa () {
212
- if (typeof global.ga === 'function') {
213
- global.ga.apply(global, arguments)
214
- }
215
- }
216
-
217
- GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker
218
-
219
- global.GOVUK = GOVUK
220
- })(window)
@@ -1,60 +0,0 @@
1
- var analyticsInit = function () {
2
- 'use strict'
3
-
4
- var analyticsVars = window.GOVUK.analyticsVars || false
5
- if (analyticsVars) {
6
- // the property naming convention here isn't consistent, but used in static and
7
- // govuk-account-manager-prototype, so hard to change
8
- var primaryGaProperty = window.GOVUK.analyticsVars.gaProperty || false
9
-
10
- var crossDomainGaProperty = window.GOVUK.analyticsVars.gaPropertyCrossDomain || false
11
- var crossDomainLinkedDomains = window.GOVUK.analyticsVars.linkedDomains || false
12
- }
13
-
14
- var consentCookie = window.GOVUK.getConsentCookie()
15
- var dummyAnalytics = {
16
- addLinkedTrackerDomain: function () {},
17
- setDimension: function () {},
18
- setOptionsForNextPageView: function () {},
19
- trackEvent: function () {},
20
- trackPageview: function () {},
21
- trackShare: function () {}
22
- }
23
-
24
- // Disable analytics by default
25
- // This will be reversed below, if the consent cookie says usage cookies are allowed
26
- var disabler = 'ga-disable-' + primaryGaProperty
27
- window[disabler] = true
28
-
29
- if (consentCookie && consentCookie.usage) {
30
- window[disabler] = false
31
-
32
- // Load Google Analytics libraries
33
- window.GOVUK.StaticAnalytics.load()
34
-
35
- if (primaryGaProperty) {
36
- // Use document.domain in dev, preview and staging so that tracking works
37
- // Otherwise explicitly set the domain as www.gov.uk (and not gov.uk).
38
- var cookieDomain = (document.domain === 'www.gov.uk') ? '.www.gov.uk' : document.domain
39
-
40
- // Configure profiles, setup custom vars, track initial pageview
41
- var analytics = new window.GOVUK.StaticAnalytics({
42
- universalId: primaryGaProperty,
43
- cookieDomain: cookieDomain,
44
- allowLinker: true
45
- })
46
-
47
- // Make interface public for virtual pageviews and events
48
- window.GOVUK.analytics = analytics
49
-
50
- // set up linking of domains for cross domain ga property
51
- if (crossDomainLinkedDomains && crossDomainLinkedDomains.length > 0) {
52
- window.GOVUK.analytics.addLinkedTrackerDomain(crossDomainGaProperty, 'govuk', crossDomainLinkedDomains)
53
- }
54
- }
55
- } else {
56
- window.GOVUK.analytics = dummyAnalytics
57
- }
58
- }
59
-
60
- window.GOVUK.analyticsInit = analyticsInit