govuk_publishing_components 29.7.0 → 29.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +72 -73
- data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +13 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-click-tracking.js +49 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -0
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +0 -1
- data/app/assets/javascripts/govuk_publishing_components/modules.js +0 -1
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-measurer.js +37 -0
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +166 -142
- data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +11 -4
- data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +20 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +3 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +8 -2
- data/app/controllers/govuk_publishing_components/audit_controller.rb +3 -2
- data/app/controllers/govuk_publishing_components/component_guide_controller.rb +0 -9
- data/app/models/govuk_publishing_components/audit_comparer.rb +92 -34
- data/app/views/govuk_publishing_components/audit/_applications.html.erb +20 -9
- data/app/views/govuk_publishing_components/component_guide/index.html.erb +3 -21
- data/app/views/govuk_publishing_components/component_guide/show.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_cards.html.erb +13 -11
- data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +20 -2
- data/app/views/govuk_publishing_components/components/_summary_list.html.erb +4 -5
- data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +18 -19
- data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/document_list.yml +4 -4
- data/app/views/govuk_publishing_components/components/docs/heading.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/image_card.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +4 -4
- data/app/views/govuk_publishing_components/components/docs/metadata.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/share_links.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +1 -2
- data/config/locales/ar.yml +1 -2
- data/config/locales/az.yml +1 -2
- data/config/locales/be.yml +1 -2
- data/config/locales/bg.yml +1 -2
- data/config/locales/bn.yml +1 -2
- data/config/locales/cs.yml +1 -2
- data/config/locales/cy.yml +1 -2
- data/config/locales/da.yml +1 -2
- data/config/locales/de.yml +1 -2
- data/config/locales/dr.yml +1 -2
- data/config/locales/el.yml +1 -2
- data/config/locales/en.yml +9 -2
- data/config/locales/es-419.yml +1 -2
- data/config/locales/es.yml +1 -2
- data/config/locales/et.yml +1 -2
- data/config/locales/fa.yml +1 -2
- data/config/locales/fi.yml +1 -2
- data/config/locales/fr.yml +1 -2
- data/config/locales/gd.yml +1 -2
- data/config/locales/gu.yml +1 -2
- data/config/locales/he.yml +1 -2
- data/config/locales/hi.yml +1 -2
- data/config/locales/hr.yml +1 -2
- data/config/locales/hu.yml +1 -2
- data/config/locales/hy.yml +1 -2
- data/config/locales/id.yml +1 -2
- data/config/locales/is.yml +1 -2
- data/config/locales/it.yml +1 -2
- data/config/locales/ja.yml +1 -2
- data/config/locales/ka.yml +1 -2
- data/config/locales/kk.yml +1 -2
- data/config/locales/ko.yml +1 -2
- data/config/locales/lt.yml +1 -2
- data/config/locales/lv.yml +1 -2
- data/config/locales/ms.yml +1 -2
- data/config/locales/mt.yml +1 -2
- data/config/locales/nl.yml +1 -2
- data/config/locales/no.yml +1 -2
- data/config/locales/pa-pk.yml +1 -2
- data/config/locales/pa.yml +1 -2
- data/config/locales/pl.yml +1 -2
- data/config/locales/ps.yml +1 -2
- data/config/locales/pt.yml +1 -2
- data/config/locales/ro.yml +1 -2
- data/config/locales/ru.yml +1 -2
- data/config/locales/si.yml +1 -2
- data/config/locales/sk.yml +1 -2
- data/config/locales/sl.yml +1 -2
- data/config/locales/so.yml +1 -2
- data/config/locales/sq.yml +1 -2
- data/config/locales/sr.yml +1 -2
- data/config/locales/sv.yml +1 -2
- data/config/locales/sw.yml +1 -2
- data/config/locales/ta.yml +1 -2
- data/config/locales/th.yml +1 -2
- data/config/locales/tk.yml +1 -2
- data/config/locales/tr.yml +1 -2
- data/config/locales/uk.yml +1 -2
- data/config/locales/ur.yml +1 -2
- data/config/locales/uz.yml +1 -2
- data/config/locales/vi.yml +1 -2
- data/config/locales/zh-hk.yml +1 -2
- data/config/locales/zh-tw.yml +1 -2
- data/config/locales/zh.yml +1 -2
- data/lib/generators/govuk_publishing_components/templates/_component.html.erb +1 -1
- data/lib/govuk_publishing_components/app_helpers/brand_helper.rb +1 -1
- data/lib/govuk_publishing_components/presenters/attachment_helper.rb +1 -3
- data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +35 -16
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/govuk-frontend/govuk/all.js +120 -49
- data/node_modules/govuk-frontend/govuk/components/back-link/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +0 -2
- data/node_modules/govuk-frontend/govuk/components/breadcrumbs/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/button/_index.scss +6 -16
- data/node_modules/govuk-frontend/govuk/components/button/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +120 -49
- data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +33 -17
- data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +1 -4
- data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +3 -2
- data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +22 -10
- data/node_modules/govuk-frontend/govuk/components/checkboxes/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +23 -23
- data/node_modules/govuk-frontend/govuk/components/date-input/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/details/macro-options.json +4 -4
- data/node_modules/govuk-frontend/govuk/components/error-message/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/error-summary/macro-options.json +3 -3
- data/node_modules/govuk-frontend/govuk/components/fieldset/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +12 -22
- data/node_modules/govuk-frontend/govuk/components/header/_index.scss +13 -3
- data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/hint/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/input/_index.scss +4 -13
- data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +5 -5
- data/node_modules/govuk-frontend/govuk/components/inset-text/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/label/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/panel/_index.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/panel/macro-options.json +4 -4
- data/node_modules/govuk-frontend/govuk/components/phase-banner/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +5 -4
- data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +17 -12
- data/node_modules/govuk-frontend/govuk/components/radios/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +1 -3
- data/node_modules/govuk-frontend/govuk/components/skip-link/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/summary-list/macro-options.json +5 -5
- data/node_modules/govuk-frontend/govuk/components/table/macro-options.json +4 -4
- data/node_modules/govuk-frontend/govuk/components/tabs/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/tag/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/warning-text/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +3 -3
- data/node_modules/govuk-frontend/govuk/helpers/_links.scss +7 -5
- data/node_modules/govuk-frontend/govuk/helpers/_media-queries.scss +2 -2
- data/node_modules/govuk-frontend/govuk/helpers/_shape-arrow.scss +1 -1
- data/node_modules/govuk-frontend/govuk/helpers/_spacing.scss +3 -3
- data/node_modules/govuk-frontend/govuk/helpers/_typography.scss +2 -2
- data/node_modules/govuk-frontend/govuk/objects/_button-group.scss +10 -26
- data/node_modules/govuk-frontend/govuk/objects/_template.scss +1 -1
- data/node_modules/govuk-frontend/govuk/objects/_width-container.scss +0 -4
- data/node_modules/govuk-frontend/govuk/tools/_exports.scss +1 -1
- data/node_modules/govuk-frontend/govuk/tools/_font-url.scss +1 -1
- data/node_modules/govuk-frontend/govuk/tools/_image-url.scss +1 -1
- data/node_modules/govuk-frontend/govuk/tools/_px-to-em.scss +2 -2
- data/node_modules/govuk-frontend/govuk/tools/_px-to-rem.scss +1 -1
- data/node_modules/govuk-frontend/govuk-esm/all.mjs +88 -0
- data/node_modules/govuk-frontend/govuk-esm/common.mjs +28 -0
- data/node_modules/govuk-frontend/govuk-esm/components/accordion/accordion.mjs +374 -0
- data/node_modules/govuk-frontend/govuk-esm/components/button/button.mjs +64 -0
- data/node_modules/govuk-frontend/govuk-esm/components/character-count/character-count.mjs +251 -0
- data/node_modules/govuk-frontend/govuk-esm/components/checkboxes/checkboxes.mjs +164 -0
- data/node_modules/govuk-frontend/govuk-esm/components/details/details.mjs +147 -0
- data/node_modules/govuk-frontend/govuk-esm/components/error-summary/error-summary.mjs +168 -0
- data/node_modules/govuk-frontend/govuk-esm/components/header/header.mjs +52 -0
- data/node_modules/govuk-frontend/govuk-esm/components/notification-banner/notification-banner.mjs +55 -0
- data/node_modules/govuk-frontend/govuk-esm/components/radios/radios.mjs +122 -0
- data/node_modules/govuk-frontend/govuk-esm/components/skip-link/skip-link.mjs +94 -0
- data/node_modules/govuk-frontend/govuk-esm/components/tabs/tabs.mjs +282 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/DOMTokenList.js +264 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Document.js +26 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/classList.js +93 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/closest.js +24 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/matches.js +23 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/nextElementSibling.js +22 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/previousElementSibling.js +22 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element.js +114 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Event.js +252 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Function/prototype/bind.js +159 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Object/defineProperty.js +86 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Window.js +20 -0
- data/node_modules/govuk-frontend/package.json +8 -1
- metadata +30 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c90f6280f1c3ce88606be0f030883575971e8fd8447cac1b353b2e1163221b63
|
|
4
|
+
data.tar.gz: 79e9a7c4d8f262fd3dd65d504aabcbff63cf7228479a540f7fb187cf4383e8fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 036a6a9d2e713632f5f8ca68b997017cf728dbf7f0dfa46709762b185ee32d576526bcad7ebbb453a0a8feb9e809c95dd5e86bf20d91d35293b2009fd972f0b3
|
|
7
|
+
data.tar.gz: 876823d94cae4f3fbbcc4a8e5c178a35e0d9c90b8ea5f0d29b8e9ec737097d9764608f3dbfea13f7d8ae8aa252c07f33fba46e53638cc249b1f20c86e0c99cc6
|
data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js
CHANGED
|
@@ -1,89 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
25
|
+
ExplicitCrossDomainLinks.prototype.decorate = function (element, param, attribute) {
|
|
26
|
+
var attributeValue = element.getAttribute(attribute)
|
|
60
27
|
|
|
61
|
-
|
|
62
|
-
var trackers = global.ga.getAll()
|
|
28
|
+
if (!attributeValue) { return }
|
|
63
29
|
|
|
64
|
-
|
|
30
|
+
if (attributeValue.indexOf('?') !== -1) {
|
|
31
|
+
attributeValue += '&' + param
|
|
32
|
+
} else {
|
|
33
|
+
attributeValue += '?' + param
|
|
34
|
+
}
|
|
65
35
|
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
element.setAttribute(attribute, attributeValue)
|
|
37
|
+
}
|
|
68
38
|
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
54
|
+
// remove the event listener to avoid an infinite loop
|
|
55
|
+
this.$module.removeEventListener(this.eventType, this.handleEvent)
|
|
75
56
|
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
+
}
|