govuk_publishing_components 37.2.3 → 37.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +4 -3
  3. data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +0 -19
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js +4 -3
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +1 -1
  6. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +4 -3
  7. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-form-tracker.js +5 -4
  8. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +16 -5
  9. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +17 -9
  10. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-scroll-tracker.js +4 -3
  11. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.js +4 -3
  12. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +1 -0
  13. data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +1 -8
  14. data/app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js +4 -4
  15. data/app/assets/javascripts/govuk_publishing_components/dependencies.js +1 -0
  16. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +3 -3
  17. data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +20 -12
  18. data/app/assets/javascripts/govuk_publishing_components/modules.js +1 -1
  19. data/app/assets/javascripts/govuk_publishing_components/rum-loader.js +2 -3
  20. data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +5 -16
  21. data/app/assets/stylesheets/govuk_publishing_components/components/_cross-service-header.scss +2 -2
  22. data/app/models/govuk_publishing_components/audit_comparer.rb +0 -1
  23. data/app/views/govuk_publishing_components/components/_attachment.html.erb +3 -1
  24. data/app/views/govuk_publishing_components/components/_back_link.html.erb +17 -7
  25. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +1 -1
  26. data/app/views/govuk_publishing_components/components/_govspeak.html.erb +17 -2
  27. data/app/views/govuk_publishing_components/components/_warning_text.html.erb +10 -1
  28. data/app/views/govuk_publishing_components/components/docs/attachment.yml +13 -0
  29. data/app/views/govuk_publishing_components/components/docs/back_link.yml +5 -3
  30. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -2
  31. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +9 -0
  32. data/app/views/govuk_publishing_components/components/docs/warning_text.yml +7 -0
  33. data/lib/govuk_publishing_components/version.rb +1 -1
  34. data/node_modules/sortablejs/Sortable.js +23 -26
  35. data/node_modules/sortablejs/Sortable.min.js +2 -2
  36. data/node_modules/sortablejs/modular/sortable.complete.esm.js +23 -26
  37. data/node_modules/sortablejs/modular/sortable.core.esm.js +23 -26
  38. data/node_modules/sortablejs/modular/sortable.esm.js +23 -26
  39. data/node_modules/sortablejs/package.json +1 -1
  40. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2a0a4e155482dc364e89cbd2e7cadcbb47a03517188b2e10442369d3c0fe66e
4
- data.tar.gz: ce994348af71283342f29d6ec33a8637c3a0297afb15b5ce80773b2d70008ef9
3
+ metadata.gz: 2555b277de08ff265823e6d39f556e5b11914ce143737ad5e8cd2d41dce344ff
4
+ data.tar.gz: 193200e4d2a872523f728817a8ad078f3fbf915a99b0986e10fa6fe1e51b6b5e
5
5
  SHA512:
6
- metadata.gz: 18179699f08bed1942305e6e81f3a1c5c6a7e580a2cd81746725e7d5a8e150f9147ac976fa7952c2d93ed32ec30bd815870620d7f9cc4c06a4b4a2f6950a4ae1
7
- data.tar.gz: e6076a4100b1d371b0701960cbf7c78a0ae6593cfd6ab8011d7e1494d07925a64083e93d01f7cae1c8aa074e2f72357a9fe80348cf5b4da3e79a9edf0b8d7d04
6
+ metadata.gz: 926c1dbb856d7e056a3bb230ddf74ef83c3a1684287e2ce10133c0d8c869500f7a8124b6dfdbb1d399c415358e34909bcc3ad69b98661f7d39509e4bafa9bfba
7
+ data.tar.gz: 1c0bd5a48a1d14bcc5850a2be305b5fb2890dc51c6fbe45b02d6adcda587599f6cf4070f02183635083d1224c774543ec138dab23aae6276c133319f6cb09ad1
@@ -19,15 +19,16 @@ window.GOVUK.analyticsVars = window.GOVUK.analyticsVars || {};
19
19
  AutoScrollTracker.prototype.init = function () {
20
20
  var consentCookie = window.GOVUK.getConsentCookie()
21
21
 
22
- if (consentCookie && consentCookie.settings) {
22
+ if (consentCookie && consentCookie.usage) {
23
23
  this.startModule()
24
24
  } else {
25
- this.startModule = this.startModule.bind(this)
26
- window.addEventListener('cookie-consent', this.startModule)
25
+ this.start = this.startModule.bind(this)
26
+ window.addEventListener('cookie-consent', this.start)
27
27
  }
28
28
  }
29
29
 
30
30
  AutoScrollTracker.prototype.startModule = function () {
31
+ window.removeEventListener('cookie-consent', this.start)
31
32
  if (window.GOVUK.analyticsVars.scrollTrackerStarted) {
32
33
  return
33
34
  }
@@ -11,25 +11,6 @@ var analyticsInit = function () {
11
11
  var crossDomainLinkedDomains = window.GOVUK.analyticsVars.linkedDomains || false
12
12
  }
13
13
 
14
- window.GOVUK.Analytics.checkDigitalIdentityConsent = function (location) {
15
- if (!location || !location.search) return
16
- // this checks for the presence of the Digital Identity cookie consent query parameter and updates our consent cookie accordingly
17
- // This is so that users don't see multiple cookie banners when they move between the different account management pages, as some will be on GOV.UK and others will be on the DI domain.
18
- var digitalIdentityConsent = /([?&]cookie_consent=)(accept|reject)/.exec(location.search)
19
- if (digitalIdentityConsent) {
20
- if (digitalIdentityConsent[2] === 'accept') {
21
- window.GOVUK.setConsentCookie({ usage: true })
22
- // set cookies_preferences_set to true to prevent cookie banner showing
23
- window.GOVUK.cookie('cookies_preferences_set', 'true')
24
- } else if (digitalIdentityConsent[2] === 'reject') {
25
- window.GOVUK.setConsentCookie({ usage: false })
26
- window.GOVUK.cookie('cookies_preferences_set', 'true')
27
- }
28
- }
29
- }
30
-
31
- window.GOVUK.Analytics.checkDigitalIdentityConsent(window.location)
32
-
33
14
  var consentCookie = window.GOVUK.getConsentCookie()
34
15
  var dummyAnalytics = {
35
16
  addLinkedTrackerDomain: function () {},
@@ -13,11 +13,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
13
13
  Ga4AutoTracker.prototype.init = function () {
14
14
  var consentCookie = window.GOVUK.getConsentCookie()
15
15
 
16
- if (consentCookie && consentCookie.settings) {
16
+ if (consentCookie && consentCookie.usage) {
17
17
  this.startModule()
18
18
  } else {
19
- this.startModule = this.startModule.bind(this)
20
- window.addEventListener('cookie-consent', this.startModule)
19
+ this.start = this.startModule.bind(this)
20
+ window.addEventListener('cookie-consent', this.start)
21
21
  }
22
22
  }
23
23
 
@@ -27,6 +27,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
27
27
 
28
28
  Ga4AutoTracker.prototype.sendEvent = function () {
29
29
  if (window.dataLayer) {
30
+ window.removeEventListener('cookie-consent', this.start)
30
31
  try {
31
32
  var data = this.module.getAttribute(this.trackingTrigger)
32
33
  data = JSON.parse(data) || {}
@@ -268,7 +268,7 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
268
268
  module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
269
269
  } catch (e) {
270
270
  // if there's a problem with the config, don't start the tracker
271
- console.error('Unable to JSON.parse or JSON.stringify index: ' + e.message, window.location)
271
+ console.error('Unable to JSON.parse or JSON.stringify index: ', e, window.location)
272
272
  }
273
273
  },
274
274
 
@@ -13,17 +13,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
13
13
  Ga4EventTracker.prototype.init = function () {
14
14
  var consentCookie = window.GOVUK.getConsentCookie()
15
15
 
16
- if (consentCookie && consentCookie.settings) {
16
+ if (consentCookie && consentCookie.usage) {
17
17
  this.startModule()
18
18
  } else {
19
- this.startModule = this.startModule.bind(this)
20
- window.addEventListener('cookie-consent', this.startModule)
19
+ this.start = this.startModule.bind(this)
20
+ window.addEventListener('cookie-consent', this.start)
21
21
  }
22
22
  }
23
23
 
24
24
  // triggered by cookie-consent event, which happens when users consent to cookies
25
25
  Ga4EventTracker.prototype.startModule = function () {
26
26
  if (window.dataLayer) {
27
+ window.removeEventListener('cookie-consent', this.start)
27
28
  this.module.addEventListener('click', this.trackClick.bind(this), true) // useCapture must be true
28
29
  }
29
30
  }
@@ -15,17 +15,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
15
15
  Ga4FormTracker.prototype.init = function () {
16
16
  var consentCookie = window.GOVUK.getConsentCookie()
17
17
 
18
- if (consentCookie && consentCookie.settings) {
18
+ if (consentCookie && consentCookie.usage) {
19
19
  this.startModule()
20
20
  } else {
21
- this.startModule = this.startModule.bind(this)
22
- window.addEventListener('cookie-consent', this.startModule)
21
+ this.start = this.startModule.bind(this)
22
+ window.addEventListener('cookie-consent', this.start)
23
23
  }
24
24
  }
25
25
 
26
26
  // triggered by cookie-consent event, which happens when users consent to cookies
27
27
  Ga4FormTracker.prototype.startModule = function () {
28
28
  if (window.dataLayer) {
29
+ window.removeEventListener('cookie-consent', this.start)
29
30
  this.module.addEventListener('submit', this.trackFormSubmit.bind(this))
30
31
  }
31
32
  }
@@ -88,7 +89,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
88
89
  } else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex].value) {
89
90
  input.answer = elem.options[elem.selectedIndex].text
90
91
  } else if (inputTypes.indexOf(inputType) !== -1 && elem.value) {
91
- if (this.includeTextInputValues) {
92
+ if (this.includeTextInputValues || elem.hasAttribute('data-ga4-form-include-input')) {
92
93
  var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
93
94
  input.answer = PIIRemover.stripPIIWithOverride(elem.value, true, true)
94
95
  } else {
@@ -16,17 +16,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
16
16
  Ga4LinkTracker.prototype.init = function () {
17
17
  var consentCookie = window.GOVUK.getConsentCookie()
18
18
 
19
- if (consentCookie && consentCookie.settings) {
19
+ if (consentCookie && consentCookie.usage) {
20
20
  this.startModule()
21
21
  } else {
22
- this.startModule = this.startModule.bind(this)
23
- window.addEventListener('cookie-consent', this.startModule)
22
+ this.start = this.startModule.bind(this)
23
+ window.addEventListener('cookie-consent', this.start)
24
24
  }
25
25
  }
26
26
 
27
27
  // triggered by cookie-consent event, which happens when users consent to cookies
28
28
  Ga4LinkTracker.prototype.startModule = function () {
29
29
  if (window.dataLayer) {
30
+ window.removeEventListener('cookie-consent', this.start)
30
31
  this.handleClick = this.handleClick.bind(this)
31
32
  this.handleMousedown = this.handleMousedown.bind(this)
32
33
 
@@ -47,8 +48,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
47
48
  } else if (this.trackLinksOnly && target.closest('a')) {
48
49
  if (!this.limitToElementClass) {
49
50
  this.trackClick(event)
50
- } else if (target.closest('.' + this.limitToElementClass)) {
51
- this.trackClick(event)
51
+ } else {
52
+ var classes = this.limitToElementClass.split(',')
53
+
54
+ for (var i = 0; i < classes.length; i++) {
55
+ if (target.closest('.' + classes[i].trim())) {
56
+ // Stops the link tracker firing twice if the link itself has data-ga4-link, and the parent element does as well.
57
+ if (target.closest('[data-ga4-link]') !== target.closest('[data-ga4-limit-to-element-class]')) {
58
+ return
59
+ }
60
+ this.trackClick(event)
61
+ }
62
+ }
52
63
  }
53
64
  }
54
65
  }
@@ -80,18 +80,26 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
80
80
  },
81
81
 
82
82
  getSearchTerm: function () {
83
- var queryString = window.GOVUK.analyticsGa4.core.trackFunctions.getSearch()
84
-
85
- if (!queryString) {
86
- return undefined
87
- }
88
-
89
- var searchTerm = queryString.match(/keywords=([^&]*)/)
83
+ // Using the data-attribute has the benefit that none of the characters are URI encoded i.e. [] remains [] instead of %5B%5D.
84
+ var searchTerm = this.getElementAttribute('data-ga4-search-query')
85
+
86
+ /*
87
+ Fallback to the keywords URL parameter if the attribute does not exist.
88
+ There is a small downside to this method. If the user uses an & in their search term, it breaks as we can't determine
89
+ if this & is a part of their search term or the start of another query parameter.
90
+ The potential solution may be to URL encode the keywords parameter in finder-frontend.
91
+ */
90
92
  if (!searchTerm) {
91
- return undefined
93
+ var queryString = window.GOVUK.analyticsGa4.core.trackFunctions.getSearch()
94
+
95
+ searchTerm = queryString.match(/keywords=([^&]*)/)
96
+ if (!searchTerm) {
97
+ return undefined
98
+ }
99
+ searchTerm = searchTerm[0].replace('keywords=', '')
100
+ searchTerm = decodeURIComponent(searchTerm).replace(/'&quot;'/g, '"')
92
101
  }
93
102
 
94
- searchTerm = searchTerm[0].replace('keywords=', '')
95
103
  searchTerm = window.GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(searchTerm)
96
104
 
97
105
  return searchTerm
@@ -19,15 +19,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
19
19
  Ga4ScrollTracker.prototype.init = function () {
20
20
  var consentCookie = window.GOVUK.getConsentCookie()
21
21
 
22
- if (consentCookie && consentCookie.settings) {
22
+ if (consentCookie && consentCookie.usage) {
23
23
  this.startModule()
24
24
  } else {
25
- this.startModule = this.startModule.bind(this)
26
- window.addEventListener('cookie-consent', this.startModule)
25
+ this.start = this.startModule.bind(this)
26
+ window.addEventListener('cookie-consent', this.start)
27
27
  }
28
28
  }
29
29
 
30
30
  Ga4ScrollTracker.prototype.startModule = function () {
31
+ window.removeEventListener('cookie-consent', this.start)
31
32
  if (window.GOVUK.analyticsGa4.vars.scrollTrackerStarted) {
32
33
  return
33
34
  }
@@ -12,11 +12,11 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
12
12
  Ga4SmartAnswerResultsTracker.prototype.init = function () {
13
13
  var consentCookie = window.GOVUK.getConsentCookie()
14
14
 
15
- if (consentCookie && consentCookie.settings) {
15
+ if (consentCookie && consentCookie.usage) {
16
16
  this.startModule()
17
17
  } else {
18
- this.startModule = this.startModule.bind(this)
19
- window.addEventListener('cookie-consent', this.startModule)
18
+ this.start = this.startModule.bind(this)
19
+ window.addEventListener('cookie-consent', this.start)
20
20
  }
21
21
  }
22
22
 
@@ -25,6 +25,7 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
25
25
  // only run this code if the dataLayer exists and an element with a data-ga4-ecommerce-path
26
26
  // attribute exists as this indicates that ecommerce tracking is required
27
27
  if (window.dataLayer && this.module.querySelector('[data-ga4-ecommerce-path]')) {
28
+ window.removeEventListener('cookie-consent', this.start)
28
29
  this.trackResults()
29
30
  this.module.addEventListener('click', this.handleClick.bind(this))
30
31
  }
@@ -2,6 +2,7 @@ window.GOVUK = window.GOVUK || {}
2
2
  window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
3
3
 
4
4
  var initFunction = function () {
5
+ window.removeEventListener('cookie-consent', window.GOVUK.analyticsGa4.init)
5
6
  var consentCookie = window.GOVUK.getConsentCookie()
6
7
 
7
8
  if (consentCookie && consentCookie.usage) {
@@ -26,13 +26,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
26
26
 
27
27
  this.$acceptCookiesButton = this.$module.querySelector('button[data-accept-cookies]')
28
28
  if (this.$acceptCookiesButton) {
29
- this.$acceptCookiesButton.style.display = 'block'
30
29
  this.$acceptCookiesButton.addEventListener('click', this.$module.setCookieConsent)
31
30
  }
32
31
 
33
32
  this.$rejectCookiesButton = this.$module.querySelector('button[data-reject-cookies]')
34
33
  if (this.$rejectCookiesButton) {
35
- this.$rejectCookiesButton.style.display = 'block'
36
34
  this.$rejectCookiesButton.addEventListener('click', this.$module.rejectCookieConsent)
37
35
  }
38
36
 
@@ -45,7 +43,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
45
43
  var shouldHaveCookieMessage = (this.$module && window.GOVUK.cookie('cookies_preferences_set') !== 'true')
46
44
 
47
45
  if (shouldHaveCookieMessage) {
48
- this.$module.style.display = 'block'
46
+ this.$module.removeAttribute('hidden')
49
47
 
50
48
  // Set the default consent cookie if it isn't already present
51
49
  if (!window.GOVUK.cookie('cookies_policy')) {
@@ -53,18 +51,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
53
51
  }
54
52
 
55
53
  window.GOVUK.deleteUnconsentedCookies()
56
- } else {
57
- this.$module.style.display = 'none'
58
54
  }
59
- } else {
60
- this.$module.style.display = 'none'
61
55
  }
62
56
  }
63
57
 
64
58
  CookieBanner.prototype.hideCookieMessage = function (event) {
65
59
  if (this.$module) {
66
60
  this.$module.hidden = true
67
- this.$module.style.display = 'none'
68
61
  window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
69
62
  }
70
63
 
@@ -11,9 +11,6 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
11
11
  this.$header = $module
12
12
  this.$navigation = $module && $module.querySelectorAll('[data-one-login-header-nav]')
13
13
  this.$numberOfNavs = this.$navigation && this.$navigation.length
14
- if (this.$header) {
15
- this.$header.classList.add('js-enabled')
16
- }
17
14
  }
18
15
  /**
19
16
  * Initialise header
@@ -40,9 +37,12 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
40
37
  $nav.$menu = $nav.$menuButton && $nav.querySelector(
41
38
  '#' + $nav.$menuButton.getAttribute('aria-controls')
42
39
  )
43
- if (!$nav.$menuButton || !$nav.$menu) {
40
+ $nav.menuItems = $nav.$menu && $nav.$menu.querySelectorAll('li')
41
+ if (!$nav.$menuButton || !$nav.$menu || $nav.menuItems.length < 2) {
44
42
  return
45
43
  }
44
+
45
+ $nav.classList.add('toggle-enabled')
46
46
  $nav.$menuOpenClass = $nav.$menu && $nav.$menu.dataset.openClass
47
47
  $nav.$menuButtonOpenClass = $nav.$menuButton && $nav.$menuButton.dataset.openClass
48
48
  $nav.$menuButtonOpenLabel = $nav.$menuButton && $nav.$menuButton.dataset.labelForShow
@@ -10,6 +10,7 @@ document.addEventListener('DOMContentLoaded', function () {
10
10
 
11
11
  // if statements ensure these functions don't execute during testing
12
12
  if (typeof window.GOVUK.loadAnalytics !== 'undefined') {
13
+ window.GOVUK.loadAnalytics.loadExtraDomains()
13
14
  if (typeof window.GOVUK.analyticsGa4.vars === 'undefined') {
14
15
  window.GOVUK.loadAnalytics.loadGa4()
15
16
  }
@@ -10,15 +10,15 @@
10
10
 
11
11
  YoutubeLinkEnhancement.prototype.init = function () {
12
12
  if (!this.campaignCookiesAllowed()) {
13
- this.startModule = this.startModule.bind(this)
14
- window.addEventListener('cookie-consent', this.startModule)
13
+ this.start = this.startModule.bind(this)
14
+ window.addEventListener('cookie-consent', this.start)
15
15
  return
16
16
  }
17
17
  this.startModule()
18
18
  }
19
19
 
20
20
  YoutubeLinkEnhancement.prototype.startModule = function () {
21
- window.removeEventListener('cookie-consent', this.startModule)
21
+ window.removeEventListener('cookie-consent', this.start)
22
22
  var $youtubeLinks = this.$element.querySelectorAll('a[href*="youtube.com"], a[href*="youtu.be"]')
23
23
 
24
24
  if ($youtubeLinks.length > 0) {
@@ -70,6 +70,12 @@ window.GOVUK.loadAnalytics = {
70
70
  }
71
71
  ],
72
72
 
73
+ loadExtraDomains: function () {
74
+ if (Array.isArray(window.GOVUK.analyticsGa4Domains)) {
75
+ this.domains = this.domains.concat(window.GOVUK.analyticsGa4Domains)
76
+ }
77
+ },
78
+
73
79
  // For Universal Analytics' cross domain tracking. linkedDomains is defined by the require statement at the top of the file.
74
80
  linkedDomains: window.GOVUK.analytics.linkedDomains,
75
81
 
@@ -99,18 +105,7 @@ window.GOVUK.loadAnalytics = {
99
105
 
100
106
  loadGa4: function (currentDomain) {
101
107
  currentDomain = currentDomain || window.location.hostname
102
- var environment = false
103
- // lots of dev domains, so simplify the matching process
104
- if (currentDomain.match(/\/{2}[a-zA-Z0-9.]+dev\.gov\.uk/)) {
105
- environment = this.domains[0]
106
- } else {
107
- for (var i = 0; i < this.domains.length; i++) {
108
- if (this.arrayContains(currentDomain, this.domains[i].domains)) {
109
- environment = this.domains[i]
110
- break
111
- }
112
- }
113
- }
108
+ var environment = this.getEnvironment(currentDomain)
114
109
 
115
110
  // If we recognise the environment (i.e. the string isn't empty), load in GA4
116
111
  if (environment) {
@@ -135,5 +130,18 @@ window.GOVUK.loadAnalytics = {
135
130
 
136
131
  arrayContains: function (valueToFind, array) {
137
132
  return array.indexOf(valueToFind) !== -1
133
+ },
134
+
135
+ getEnvironment: function (currentDomain) {
136
+ // lots of dev domains, so simplify the matching process
137
+ if (currentDomain.match(/[a-zA-Z0-9.-]+dev\.gov\.uk/)) {
138
+ return this.domains[0]
139
+ } else {
140
+ for (var i = 0; i < this.domains.length; i++) {
141
+ if (this.arrayContains(currentDomain, this.domains[i].domains)) {
142
+ return this.domains[i]
143
+ }
144
+ }
145
+ }
138
146
  }
139
147
  }
@@ -43,7 +43,7 @@
43
43
  element.setAttribute('data-' + moduleNames[j] + '-module-started', true)
44
44
  } catch (e) {
45
45
  // if there's a problem with the module, catch the error to allow other modules to start
46
- console.error('Error starting ' + moduleName + ' component JS: ' + e.message, window.location)
46
+ console.error('Error starting ' + moduleName + ' component JS: ', e, window.location)
47
47
  }
48
48
  }
49
49
  }
@@ -19,6 +19,7 @@
19
19
  })()
20
20
 
21
21
  var insertScript = function () {
22
+ window.removeEventListener('cookie-consent', insertScript)
22
23
  var marker = document.querySelector('script[data-lux-reporter-script]')
23
24
 
24
25
  if (!marker) {
@@ -37,8 +38,6 @@
37
38
  if (parsedCookie.usage === true) {
38
39
  insertScript()
39
40
  } else {
40
- window.addEventListener('cookie-consent', function () {
41
- insertScript()
42
- })
41
+ window.addEventListener('cookie-consent', insertScript)
43
42
  }
44
43
  })()
@@ -1,25 +1,14 @@
1
1
  @import "govuk_publishing_components/individual_component_support";
2
2
  @import "govuk/components/cookie-banner/cookie-banner";
3
3
 
4
- .gem-c-cookie-banner .govuk-button-group[hidden] {
5
- display: none;
6
- }
7
-
8
- .govuk-cookie-banner .govuk-cookie-banner__heading[hidden] {
9
- display: none;
10
- }
11
-
12
- .js-enabled {
13
- .gem-c-cookie-banner {
14
- display: none; // shown with JS, always on for non-JS
4
+ .gem-c-cookie-banner {
5
+ [hidden],
6
+ .govuk-button-group[hidden],
7
+ .govuk-cookie-banner__heading[hidden] {
8
+ display: none;
15
9
  }
16
10
  }
17
11
 
18
- // can't be used without js so implement there
19
- .gem-c-cookie-banner .gem-c-button {
20
- display: none;
21
- }
22
-
23
12
  .gem-c-cookie-banner__confirmation {
24
13
  // This element is focused using JavaScript so that it's being read out by screen readers
25
14
  // for this reason we don't want to show the default outline or emphasise it visually using `govuk-focused-text`
@@ -27,7 +27,7 @@ $govuk-header-link-underline-thickness: 3px;
27
27
  @mixin nav-style($nav-open-class) {
28
28
  display: block;
29
29
  // if JS is unavailable, the nav links are expanded and the toggle button is hidden
30
- .gem-c-cross-service-header.js-enabled & {
30
+ .toggle-enabled & {
31
31
  display: none;
32
32
 
33
33
  &#{$nav-open-class} {
@@ -48,7 +48,7 @@ $govuk-header-link-underline-thickness: 3px;
48
48
  .gem-c-cross-service-header__button {
49
49
  display: none;
50
50
 
51
- .gem-c-cross-service-header.js-enabled & {
51
+ .toggle-enabled & {
52
52
  display: inline;
53
53
  display: flex;
54
54
 
@@ -14,7 +14,6 @@ module GovukPublishingComponents
14
14
  info-frontend
15
15
  service-manual-frontend
16
16
  smart-answers
17
- whitehall
18
17
  ]
19
18
 
20
19
  @static_data = find_static(results)
@@ -7,6 +7,7 @@
7
7
  hide_order_copy_link ||= false
8
8
  attributes = []
9
9
  data_attributes ||= {}
10
+ details_ga4_attributes ||= {}
10
11
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
11
12
 
12
13
  container_class_names = %w[gem-c-attachment govuk-!-display-none-print]
@@ -118,7 +119,8 @@
118
119
  <% if attachment.alternative_format_contact_email %>
119
120
  <%= tag.p t("components.attachment.request_format_text"), class: "gem-c-attachment__metadata" %>
120
121
  <%= render "govuk_publishing_components/components/details", {
121
- title: t("components.attachment.request_format_cta")
122
+ title: t("components.attachment.request_format_cta"),
123
+ ga4_attributes: details_ga4_attributes,
122
124
  } do %>
123
125
  <%= t("components.attachment.request_format_details_html", alternative_format_contact_email: attachment.alternative_format_contact_email) %>
124
126
  <% end %>
@@ -2,11 +2,21 @@
2
2
  add_gem_component_stylesheet("back-link")
3
3
 
4
4
  text ||= t('components.back_link.back')
5
- data_attributes ||= nil
5
+ data_attributes ||= {}
6
+ disable_ga4 ||= false
7
+
8
+ component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
9
+ component_helper.add_class("gem-c-back-link govuk-back-link govuk-!-display-none-print")
10
+ unless disable_ga4
11
+ ga4_link = {
12
+ event_name: "navigation",
13
+ type: "back",
14
+ url: href,
15
+ }
16
+ component_helper.add_data_attribute({ module: "ga4-link-tracker" })
17
+ component_helper.add_data_attribute({ ga4_link: ga4_link })
18
+ end
6
19
  %>
7
- <%= link_to(
8
- text,
9
- href,
10
- class: %w(gem-c-back-link govuk-back-link govuk-!-display-none-print),
11
- data: data_attributes
12
- ) %>
20
+ <%= tag.a(**component_helper.all_attributes.merge!({ href: href })) do %>
21
+ <%= text %>
22
+ <% end %>
@@ -34,7 +34,7 @@
34
34
  disable_ga4 ||= false
35
35
  %>
36
36
 
37
- <div id="<%= id %>" class="<%= css_classes.join(' ') %>" data-module="cookie-banner" data-nosnippet role="region" aria-label="<%= title %>">
37
+ <div id="<%= id %>" class="<%= css_classes.join(' ') %>" data-module="cookie-banner" data-nosnippet role="region" aria-label="<%= title %>" hidden>
38
38
  <div class="govuk-cookie-banner__message govuk-width-container">
39
39
  <div class="govuk-grid-row">
40
40
  <div class="govuk-grid-column-two-thirds">
@@ -9,9 +9,24 @@
9
9
  classes << direction_class if direction_class
10
10
  classes << "disable-youtube" if disable_youtube_expansions
11
11
  classes << "gem-c-govspeak--inverse" if inverse
12
+
13
+ disable_ga4 ||= false
14
+
15
+ data_modules = "govspeak"
16
+ data_modules << " ga4-link-tracker" unless disable_ga4
17
+ data_attributes = { module: data_modules }
18
+
19
+ unless disable_ga4
20
+ data_attributes.merge!({
21
+ ga4_track_links_only: "",
22
+ ga4_limit_to_element_class: "call-to-action, info-notice, help-notice, advisory",
23
+ ga4_link: { "event_name": "navigation", "type": "callout" }.to_json,
24
+ })
25
+ end
26
+
12
27
  %>
13
28
 
14
- <div class="gem-c-govspeak govuk-govspeak <%= classes.join(" ") %>" data-module="govspeak">
29
+ <%= tag.div(class: "gem-c-govspeak govuk-govspeak " + classes.join(" "), data: data_attributes) do %>
15
30
  <% if local_assigns.include?(:content) %>
16
31
  <% if content.html_safe? %>
17
32
  <%= content %>
@@ -32,4 +47,4 @@
32
47
  <% elsif block_given? %>
33
48
  <%= yield %>
34
49
  <% end %>
35
- </div>
50
+ <% end %>
@@ -14,9 +14,18 @@
14
14
  text_classes << "gem-c-warning-text__text--no-indent" if text_icon.empty?
15
15
  text_classes << "gem-c-warning-text__text--large" if large_font
16
16
  text_classes << "gem-c-warning-text__text--highlight" if highlight_text
17
+
18
+ disable_ga4 ||= false
19
+
20
+ ga4_data_attributes = {
21
+ "module": "ga4-link-tracker",
22
+ "ga4-track-links-only": "",
23
+ "ga4-link": { "event_name": "navigation", "type": "callout" }.to_json
24
+ } unless disable_ga4
25
+
17
26
  %>
18
27
 
19
- <%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text" do %>
28
+ <%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text", data: ga4_data_attributes do %>
20
29
  <% unless text_icon.empty? %>
21
30
  <%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %>
22
31
  <% end %>