govuk_publishing_components 29.7.0 → 29.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +72 -73
  3. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +13 -2
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-click-tracking.js +49 -0
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -0
  6. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +0 -1
  7. data/app/assets/javascripts/govuk_publishing_components/modules.js +0 -1
  8. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-measurer.js +37 -0
  9. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +166 -142
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +11 -4
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +20 -0
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +3 -8
  13. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +8 -2
  14. data/app/controllers/govuk_publishing_components/audit_controller.rb +3 -2
  15. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +0 -9
  16. data/app/models/govuk_publishing_components/audit_comparer.rb +92 -34
  17. data/app/views/govuk_publishing_components/audit/_applications.html.erb +20 -9
  18. data/app/views/govuk_publishing_components/component_guide/index.html.erb +3 -21
  19. data/app/views/govuk_publishing_components/component_guide/show.html.erb +1 -1
  20. data/app/views/govuk_publishing_components/components/_cards.html.erb +13 -11
  21. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +20 -2
  22. data/app/views/govuk_publishing_components/components/_summary_list.html.erb +4 -5
  23. data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +18 -19
  24. data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -1
  25. data/app/views/govuk_publishing_components/components/docs/document_list.yml +4 -4
  26. data/app/views/govuk_publishing_components/components/docs/heading.yml +1 -1
  27. data/app/views/govuk_publishing_components/components/docs/image_card.yml +1 -1
  28. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +4 -4
  29. data/app/views/govuk_publishing_components/components/docs/metadata.yml +1 -1
  30. data/app/views/govuk_publishing_components/components/docs/share_links.yml +1 -1
  31. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +1 -1
  32. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +1 -2
  33. data/config/locales/ar.yml +1 -2
  34. data/config/locales/az.yml +1 -2
  35. data/config/locales/be.yml +1 -2
  36. data/config/locales/bg.yml +1 -2
  37. data/config/locales/bn.yml +1 -2
  38. data/config/locales/cs.yml +1 -2
  39. data/config/locales/cy.yml +1 -2
  40. data/config/locales/da.yml +1 -2
  41. data/config/locales/de.yml +1 -2
  42. data/config/locales/dr.yml +1 -2
  43. data/config/locales/el.yml +1 -2
  44. data/config/locales/en.yml +9 -2
  45. data/config/locales/es-419.yml +1 -2
  46. data/config/locales/es.yml +1 -2
  47. data/config/locales/et.yml +1 -2
  48. data/config/locales/fa.yml +1 -2
  49. data/config/locales/fi.yml +1 -2
  50. data/config/locales/fr.yml +1 -2
  51. data/config/locales/gd.yml +1 -2
  52. data/config/locales/gu.yml +1 -2
  53. data/config/locales/he.yml +1 -2
  54. data/config/locales/hi.yml +1 -2
  55. data/config/locales/hr.yml +1 -2
  56. data/config/locales/hu.yml +1 -2
  57. data/config/locales/hy.yml +1 -2
  58. data/config/locales/id.yml +1 -2
  59. data/config/locales/is.yml +1 -2
  60. data/config/locales/it.yml +1 -2
  61. data/config/locales/ja.yml +1 -2
  62. data/config/locales/ka.yml +1 -2
  63. data/config/locales/kk.yml +1 -2
  64. data/config/locales/ko.yml +1 -2
  65. data/config/locales/lt.yml +1 -2
  66. data/config/locales/lv.yml +1 -2
  67. data/config/locales/ms.yml +1 -2
  68. data/config/locales/mt.yml +1 -2
  69. data/config/locales/nl.yml +1 -2
  70. data/config/locales/no.yml +1 -2
  71. data/config/locales/pa-pk.yml +1 -2
  72. data/config/locales/pa.yml +1 -2
  73. data/config/locales/pl.yml +1 -2
  74. data/config/locales/ps.yml +1 -2
  75. data/config/locales/pt.yml +1 -2
  76. data/config/locales/ro.yml +1 -2
  77. data/config/locales/ru.yml +1 -2
  78. data/config/locales/si.yml +1 -2
  79. data/config/locales/sk.yml +1 -2
  80. data/config/locales/sl.yml +1 -2
  81. data/config/locales/so.yml +1 -2
  82. data/config/locales/sq.yml +1 -2
  83. data/config/locales/sr.yml +1 -2
  84. data/config/locales/sv.yml +1 -2
  85. data/config/locales/sw.yml +1 -2
  86. data/config/locales/ta.yml +1 -2
  87. data/config/locales/th.yml +1 -2
  88. data/config/locales/tk.yml +1 -2
  89. data/config/locales/tr.yml +1 -2
  90. data/config/locales/uk.yml +1 -2
  91. data/config/locales/ur.yml +1 -2
  92. data/config/locales/uz.yml +1 -2
  93. data/config/locales/vi.yml +1 -2
  94. data/config/locales/zh-hk.yml +1 -2
  95. data/config/locales/zh-tw.yml +1 -2
  96. data/config/locales/zh.yml +1 -2
  97. data/lib/generators/govuk_publishing_components/templates/_component.html.erb +1 -1
  98. data/lib/govuk_publishing_components/app_helpers/brand_helper.rb +1 -1
  99. data/lib/govuk_publishing_components/presenters/attachment_helper.rb +1 -3
  100. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +35 -16
  101. data/lib/govuk_publishing_components/version.rb +1 -1
  102. data/node_modules/govuk-frontend/govuk/all.js +120 -49
  103. data/node_modules/govuk-frontend/govuk/components/back-link/macro-options.json +2 -2
  104. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +0 -2
  105. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/macro-options.json +2 -2
  106. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +6 -16
  107. data/node_modules/govuk-frontend/govuk/components/button/macro-options.json +2 -2
  108. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +120 -49
  109. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +33 -17
  110. data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +2 -2
  111. data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +1 -4
  112. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +3 -2
  113. data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +22 -10
  114. data/node_modules/govuk-frontend/govuk/components/checkboxes/macro-options.json +2 -2
  115. data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +23 -23
  116. data/node_modules/govuk-frontend/govuk/components/date-input/template.njk +1 -1
  117. data/node_modules/govuk-frontend/govuk/components/details/macro-options.json +4 -4
  118. data/node_modules/govuk-frontend/govuk/components/error-message/macro-options.json +2 -2
  119. data/node_modules/govuk-frontend/govuk/components/error-summary/macro-options.json +3 -3
  120. data/node_modules/govuk-frontend/govuk/components/fieldset/macro-options.json +2 -2
  121. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +12 -22
  122. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +13 -3
  123. data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +2 -2
  124. data/node_modules/govuk-frontend/govuk/components/hint/macro-options.json +2 -2
  125. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +4 -13
  126. data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +5 -5
  127. data/node_modules/govuk-frontend/govuk/components/inset-text/macro-options.json +2 -2
  128. data/node_modules/govuk-frontend/govuk/components/label/macro-options.json +2 -2
  129. data/node_modules/govuk-frontend/govuk/components/panel/_index.scss +1 -1
  130. data/node_modules/govuk-frontend/govuk/components/panel/macro-options.json +4 -4
  131. data/node_modules/govuk-frontend/govuk/components/phase-banner/macro-options.json +2 -2
  132. data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +5 -4
  133. data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +17 -12
  134. data/node_modules/govuk-frontend/govuk/components/radios/macro-options.json +2 -2
  135. data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +1 -3
  136. data/node_modules/govuk-frontend/govuk/components/skip-link/macro-options.json +2 -2
  137. data/node_modules/govuk-frontend/govuk/components/summary-list/macro-options.json +5 -5
  138. data/node_modules/govuk-frontend/govuk/components/table/macro-options.json +4 -4
  139. data/node_modules/govuk-frontend/govuk/components/tabs/macro-options.json +2 -2
  140. data/node_modules/govuk-frontend/govuk/components/tag/macro-options.json +2 -2
  141. data/node_modules/govuk-frontend/govuk/components/warning-text/macro-options.json +2 -2
  142. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +3 -3
  143. data/node_modules/govuk-frontend/govuk/helpers/_links.scss +7 -5
  144. data/node_modules/govuk-frontend/govuk/helpers/_media-queries.scss +2 -2
  145. data/node_modules/govuk-frontend/govuk/helpers/_shape-arrow.scss +1 -1
  146. data/node_modules/govuk-frontend/govuk/helpers/_spacing.scss +3 -3
  147. data/node_modules/govuk-frontend/govuk/helpers/_typography.scss +2 -2
  148. data/node_modules/govuk-frontend/govuk/objects/_button-group.scss +10 -26
  149. data/node_modules/govuk-frontend/govuk/objects/_template.scss +1 -1
  150. data/node_modules/govuk-frontend/govuk/objects/_width-container.scss +0 -4
  151. data/node_modules/govuk-frontend/govuk/tools/_exports.scss +1 -1
  152. data/node_modules/govuk-frontend/govuk/tools/_font-url.scss +1 -1
  153. data/node_modules/govuk-frontend/govuk/tools/_image-url.scss +1 -1
  154. data/node_modules/govuk-frontend/govuk/tools/_px-to-em.scss +2 -2
  155. data/node_modules/govuk-frontend/govuk/tools/_px-to-rem.scss +1 -1
  156. data/node_modules/govuk-frontend/govuk-esm/all.mjs +88 -0
  157. data/node_modules/govuk-frontend/govuk-esm/common.mjs +28 -0
  158. data/node_modules/govuk-frontend/govuk-esm/components/accordion/accordion.mjs +374 -0
  159. data/node_modules/govuk-frontend/govuk-esm/components/button/button.mjs +64 -0
  160. data/node_modules/govuk-frontend/govuk-esm/components/character-count/character-count.mjs +251 -0
  161. data/node_modules/govuk-frontend/govuk-esm/components/checkboxes/checkboxes.mjs +164 -0
  162. data/node_modules/govuk-frontend/govuk-esm/components/details/details.mjs +147 -0
  163. data/node_modules/govuk-frontend/govuk-esm/components/error-summary/error-summary.mjs +168 -0
  164. data/node_modules/govuk-frontend/govuk-esm/components/header/header.mjs +52 -0
  165. data/node_modules/govuk-frontend/govuk-esm/components/notification-banner/notification-banner.mjs +55 -0
  166. data/node_modules/govuk-frontend/govuk-esm/components/radios/radios.mjs +122 -0
  167. data/node_modules/govuk-frontend/govuk-esm/components/skip-link/skip-link.mjs +94 -0
  168. data/node_modules/govuk-frontend/govuk-esm/components/tabs/tabs.mjs +282 -0
  169. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/DOMTokenList.js +264 -0
  170. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Document.js +26 -0
  171. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/classList.js +93 -0
  172. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/closest.js +24 -0
  173. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/matches.js +23 -0
  174. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/nextElementSibling.js +22 -0
  175. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/previousElementSibling.js +22 -0
  176. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element.js +114 -0
  177. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Event.js +252 -0
  178. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Function/prototype/bind.js +159 -0
  179. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Object/defineProperty.js +86 -0
  180. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Window.js +20 -0
  181. data/node_modules/govuk-frontend/package.json +8 -1
  182. metadata +30 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b74221682d0047e390f314e968edf8acd3b89efebfe41d833239d9ca44413c86
4
- data.tar.gz: 1f87c5a4288b2a69da1e32598422162bc5017f2dab4ac577b326b582cbd9e8e9
3
+ metadata.gz: c90f6280f1c3ce88606be0f030883575971e8fd8447cac1b353b2e1163221b63
4
+ data.tar.gz: 79e9a7c4d8f262fd3dd65d504aabcbff63cf7228479a540f7fb187cf4383e8fa
5
5
  SHA512:
6
- metadata.gz: 14d60ae3e9876edbbcac836010f6dbfd1655c3be4798119f79ac064cb70cfef71a612694d7b31ae6475c31f9813ca9d7775fb1ab3b3153707643bd61190e057d
7
- data.tar.gz: 4e69c991fd6db0d47136d6a7e489fd516e1aa9c62b1422ccf87ed35164e7f6641a60fd64392281f5c99b84c4b9caef8be78bbd73faa922b604d27c227ec7080f
6
+ metadata.gz: 036a6a9d2e713632f5f8ca68b997017cf728dbf7f0dfa46709762b185ee32d576526bcad7ebbb453a0a8feb9e809c95dd5e86bf20d91d35293b2009fd972f0b3
7
+ data.tar.gz: 876823d94cae4f3fbbcc4a8e5c178a35e0d9c90b8ea5f0d29b8e9ec737097d9764608f3dbfea13f7d8ae8aa252c07f33fba46e53638cc249b1f20c86e0c99cc6
@@ -1,89 +1,88 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
- GOVUK.Modules = GOVUK.Modules || {}
6
-
7
- GOVUK.Modules.ExplicitCrossDomainLinks = function () {
8
- this.start = function ($module) {
9
- this.element = $module[0]
10
- this.attribute = 'href'
11
- this.attributeValue = this.element.getAttribute(this.attribute)
12
- this.eventType = 'click'
13
- if (!this.attributeValue) {
14
- this.attribute = 'action'
15
- this.attributeValue = this.element.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.element.addEventListener(this.eventType, this.handleEvent)
23
- }
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
+ }
24
8
 
25
- this.handleEvent = function (e) {
26
- // prevent default: we want the link href and/or form action to be decorated before we navigate away
27
- e.preventDefault()
28
- var cookieBannerEngaged = GOVUK.cookie('cookies_preferences_set')
29
- var cookieConsent = GOVUK.getConsentCookie()
30
-
31
- if (cookieBannerEngaged !== 'true') {
32
- // If not engaged, append only ?cookie_consent=not-engaged
33
- this.decorate(this.element, 'cookie_consent=not-engaged', this.attribute)
34
- } else if (cookieConsent && cookieConsent.usage === true) {
35
- this.handleCookiesAccepted()
36
- } else {
37
- this.decorate(this.element, 'cookie_consent=reject', this.attribute)
38
- }
39
-
40
- // remove the event listener to avoid an infinite loop
41
- this.element.removeEventListener(this.eventType, this.handleEvent)
42
-
43
- // if the element is a form, submit it. If it is a link, click it
44
- if (this.eventType === 'submit') {
45
- this.element.submit()
46
- } else {
47
- this.element.click()
48
- }
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'
49
17
  }
50
18
 
51
- this.handleCookiesAccepted = function () {
52
- // If the cookie banner was engaged and usage cookie accepted, append ?_ga=clientid if available and cookie_consent=accept
53
- var element = this.element
54
- var attribute = this.attribute
55
- this.decorate(element, 'cookie_consent=accept', attribute)
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
+ }
56
24
 
57
- if (!global.ga) {
58
- return
59
- }
25
+ ExplicitCrossDomainLinks.prototype.decorate = function (element, param, attribute) {
26
+ var attributeValue = element.getAttribute(attribute)
60
27
 
61
- global.ga(function () {
62
- var trackers = global.ga.getAll()
28
+ if (!attributeValue) { return }
63
29
 
64
- if (!trackers.length) { return }
30
+ if (attributeValue.indexOf('?') !== -1) {
31
+ attributeValue += '&' + param
32
+ } else {
33
+ attributeValue += '?' + param
34
+ }
65
35
 
66
- var linker = new global.gaplugins.Linker(trackers[0])
67
- var attrValue = element.getAttribute(attribute)
36
+ element.setAttribute(attribute, attributeValue)
37
+ }
68
38
 
69
- element.setAttribute(attribute, linker.decorate(attrValue))
70
- })
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)
71
52
  }
72
53
 
73
- this.decorate = function (element, param, attribute) {
74
- var attributeValue = element.getAttribute(attribute)
54
+ // remove the event listener to avoid an infinite loop
55
+ this.$module.removeEventListener(this.eventType, this.handleEvent)
75
56
 
76
- if (!attributeValue) { return }
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
+ }
77
64
 
78
- if (attributeValue.indexOf('?') !== -1) {
79
- attributeValue += '&' + param
80
- } else {
81
- attributeValue += '?' + param
82
- }
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)
83
70
 
84
- element.setAttribute(attribute, attributeValue)
71
+ if (!window.ga) {
72
+ return
85
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
+ })
86
85
  }
87
86
 
88
- global.GOVUK = GOVUK
89
- })(window)
87
+ Modules.ExplicitCrossDomainLinks = ExplicitCrossDomainLinks
88
+ })(window.GOVUK.Modules)
@@ -13,6 +13,10 @@
13
13
  return document.querySelectorAll('[data-track-count="accordionSection"]').length
14
14
  case isDocumentCollectionPage():
15
15
  return document.querySelectorAll('.document-collection .group-title').length
16
+ case isNewBrowsePageLevelTwo():
17
+ // if there are no accordion sections on the browse level 2 page
18
+ // then it is a default page with one or two lists
19
+ return document.querySelectorAll('[data-track-count="accordionSection"]').length || document.querySelectorAll('main .govuk-list').length
16
20
  case isNewBrowsePage():
17
21
  return document.querySelectorAll('[data-track-count="cardList"]').length
18
22
  case isMainstreamBrowsePage():
@@ -46,6 +50,8 @@
46
50
  return document.querySelectorAll('a[data-track-category="navAccordionLinkClicked"]').length
47
51
  case isDocumentCollectionPage():
48
52
  return document.querySelectorAll('.document-collection .group-document-list li a').length
53
+ case isNewBrowsePageLevelTwo():
54
+ return document.querySelectorAll('[data-track-count="contentLink"]').length
49
55
  case isNewBrowsePage():
50
56
  return document.querySelectorAll('[data-track-count="cardLink"]').length
51
57
  case isMainstreamBrowsePage():
@@ -71,7 +77,6 @@
71
77
  var metaApplicationSelector = 'meta[name="govuk:rendering-application"]'
72
78
  var metaFormatSelector = 'meta[name="govuk:format"]'
73
79
  var metaNavigationTypeSelector = 'meta[name="govuk:navigation-page-type"]'
74
- var metaSectionSelector = 'meta[name="govuk:section"]'
75
80
 
76
81
  function getMetaAttribute (selector) {
77
82
  var element = document.querySelector(selector)
@@ -98,9 +103,15 @@
98
103
  getMetaAttribute(metaNavigationTypeSelector) === 'leaf'
99
104
  }
100
105
 
106
+ function isNewBrowsePageLevelTwo () {
107
+ return getMetaAttribute(metaApplicationSelector) === 'collections' &&
108
+ getMetaAttribute(metaNavigationTypeSelector) === 'browse level 2'
109
+ }
110
+
101
111
  function isNewBrowsePage () {
102
112
  return getMetaAttribute(metaApplicationSelector) === 'collections' &&
103
- getMetaAttribute(metaSectionSelector) === 'new_browse_page' &&
113
+ (getMetaAttribute(metaNavigationTypeSelector) === 'browse level 0' ||
114
+ getMetaAttribute(metaNavigationTypeSelector) === 'browse level 1') &&
104
115
  getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
105
116
  }
106
117
 
@@ -0,0 +1,49 @@
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
+
4
+ (function (Modules) {
5
+ 'use strict'
6
+
7
+ function GtmClickTracking (module) {
8
+ this.module = module
9
+ this.trackingTrigger = 'data-gtm-event-name' // elements with this attribute get tracked
10
+ }
11
+
12
+ GtmClickTracking.prototype.init = function () {
13
+ var trackClicksOn = [this.module]
14
+ if (!this.module.getAttribute(this.trackingTrigger)) {
15
+ trackClicksOn = this.module.querySelectorAll('[' + this.trackingTrigger + ']')
16
+ }
17
+
18
+ for (var i = 0; i < trackClicksOn.length; i++) {
19
+ trackClicksOn[i].addEventListener('click', this.trackClick.bind(this))
20
+ }
21
+ }
22
+
23
+ GtmClickTracking.prototype.trackClick = function (event) {
24
+ if (window.dataLayer) {
25
+ var target = event.currentTarget
26
+ var data = {
27
+ event: 'analytics',
28
+ event_name: target.getAttribute('data-gtm-event-name'),
29
+ // get entire URL apart from domain
30
+ link_url: window.location.href.substring(window.location.origin.length),
31
+ ui: JSON.parse(target.getAttribute('data-gtm-attributes'))
32
+ }
33
+ var ariaExpanded = this.checkExpandedState(target)
34
+ if (ariaExpanded) {
35
+ data.ui.state = ariaExpanded === 'false' ? 'opened' : 'closed'
36
+ }
37
+ window.dataLayer.push(data)
38
+ }
39
+ }
40
+
41
+ GtmClickTracking.prototype.checkExpandedState = function (clicked) {
42
+ var expanded = clicked.querySelector('[aria-expanded]')
43
+ if (expanded) {
44
+ return expanded.getAttribute('aria-expanded')
45
+ }
46
+ }
47
+
48
+ Modules.GtmClickTracking = GtmClickTracking
49
+ })(window.GOVUK.Modules)
@@ -0,0 +1 @@
1
+ //= require ./analytics-ga4/gtm-click-tracking
@@ -131,7 +131,6 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
131
131
 
132
132
  if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
133
133
  window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
134
- console.log('pageElementInteraction', action, options)
135
134
  }
136
135
  }
137
136
 
@@ -35,7 +35,6 @@
35
35
  for (var j = 0, k = moduleNames.length; j < k; j++) {
36
36
  var moduleName = camelCaseAndCapitalise(moduleNames[j])
37
37
  var started = element.getAttribute('data-' + moduleNames[j] + '-module-started')
38
-
39
38
  if (typeof GOVUK.Modules[moduleName] === 'function' && !started) {
40
39
  // Vanilla JavaScript GOV.UK Modules and GOV.UK Frontend Modules
41
40
  if (GOVUK.Modules[moduleName].prototype.init) {
@@ -157,3 +157,40 @@ if (
157
157
  LongTaskObserver.observe({ type: ["longtask"] });
158
158
  } catch (e) {}
159
159
  }
160
+
161
+ // As per RFC 147[1], this adds in monitoring of the type of HTTP protocol that
162
+ // is used when a browser loads a page.
163
+ //
164
+ // The User Timing API (aka window.performance) is used to record the data - to
165
+ // avoid the use of this from breaking the JavaScript for the small number of
166
+ // browsers that don't support it, it's been wrapped in a try/catch block plus a
167
+ // couple of checks to prevent "is not defined" errors.
168
+ //
169
+ // Because the `nextHopProtocol` isn't immediately available - it seems to need
170
+ // a request to be made before it's populated - we need to wait for the
171
+ // `DOMContentReady` event before we can see what the HTTP version is.
172
+ //
173
+ // [1]: https://github.com/alphagov/govuk-rfcs/pull/148
174
+
175
+ var measureHTTPProtocol = function () {
176
+ var getEntriesByType = performance.getEntriesByType('navigation')
177
+
178
+ if (getEntriesByType.length > 0) {
179
+ var httpProtocol = JSON.parse(JSON.stringify(performance.getEntriesByType('navigation')[0].nextHopProtocol))
180
+ LUX.addData("http-protocol", httpProtocol)
181
+ }
182
+ }
183
+
184
+ try {
185
+ if (typeof performance !== 'undefined' && typeof performance.getEntriesByType !== 'undefined') {
186
+ if (document.readyState === 'complete') {
187
+ measureHTTPProtocol()
188
+ } else {
189
+ window.addEventListener('load', function() {
190
+ measureHTTPProtocol()
191
+ })
192
+ }
193
+ }
194
+ } catch (e) {
195
+ console.error('Error in LUX reporting the HTTP protocol (' + window.location + '):', e)
196
+ }