govuk_publishing_components 30.7.3 → 31.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{ga4-core.js.erb → ga4-core.js} +12 -21
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{ga4-enhanced-ecommerce-tracker.js → ga4-ecommerce-tracker.js} +5 -5
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +2 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +5 -5
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +5 -5
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js +2 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +5 -5
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js +2 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -1
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +5 -5
- data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -1
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ce979400ac37e8bffd5eb9c1d751bde2eee271c3330ed8188ab34cbb3c5bbb0
|
4
|
+
data.tar.gz: 77cf3bfa31ee119a705406a6d55a18463b532154033f367409f20161b23ea62a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27c7baa3ca76b555d6ea9c861e4b3b9d9e72ef3e78492291ed51dc0046bee589f6665866e2a9a7cd69fb7f9c16f220a7b0b1836e3d3c4aaa27818e8f1e7e33e0
|
7
|
+
data.tar.gz: 3b2e79bfe6a49a7b7caf0166a0db70536837903b69aa818a4933d04d9c29b741ca622a732010c04bffce7c41702f4829bff61b9e045276937e12b53aa9ca14d2
|
@@ -1,39 +1,31 @@
|
|
1
|
-
// note that because this file is .js.erb it is not linted
|
2
|
-
// temporarily rename to .js to check with the linter
|
3
1
|
window.GOVUK = window.GOVUK || {}
|
4
|
-
window.GOVUK.
|
2
|
+
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
5
3
|
|
6
4
|
(function (analytics) {
|
7
5
|
'use strict'
|
8
6
|
|
9
7
|
var core = {
|
10
8
|
load: function () {
|
11
|
-
var firstScript
|
12
|
-
var newScript
|
9
|
+
var firstScript = document.getElementsByTagName('script')[0]
|
10
|
+
var newScript = document.createElement('script')
|
11
|
+
newScript.async = true
|
13
12
|
|
14
|
-
if (window.GOVUK.
|
13
|
+
if (window.GOVUK.analyticsGa4.vars.gtag_id) {
|
15
14
|
// initialise gtag
|
16
15
|
window.dataLayer = window.dataLayer || []
|
17
16
|
var gtag = function () { window.dataLayer.push(arguments) }
|
18
17
|
gtag('js', new Date())
|
19
|
-
gtag('config', window.GOVUK.
|
18
|
+
gtag('config', window.GOVUK.analyticsGa4.vars.gtag_id)
|
20
19
|
|
21
|
-
|
22
|
-
newScript = document.createElement('script')
|
23
|
-
|
24
|
-
newScript.async = true
|
25
|
-
newScript.src = '//www.googletagmanager.com/gtag/js?id=' + window.GOVUK.analyticsGA4.vars.gtag_id
|
20
|
+
newScript.src = '//www.googletagmanager.com/gtag/js?id=' + window.GOVUK.analyticsGa4.vars.gtag_id
|
26
21
|
firstScript.parentNode.insertBefore(newScript, firstScript)
|
27
22
|
} else {
|
28
23
|
// initialise GTM
|
29
24
|
window.dataLayer = window.dataLayer || []
|
30
25
|
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' })
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
var auth = window.GOVUK.analyticsGA4.vars.auth || ''
|
36
|
-
var preview = window.GOVUK.analyticsGA4.vars.preview || ''
|
27
|
+
var auth = window.GOVUK.analyticsGa4.vars.auth || ''
|
28
|
+
var preview = window.GOVUK.analyticsGa4.vars.preview || ''
|
37
29
|
if (auth) {
|
38
30
|
auth = '>m_auth=' + auth
|
39
31
|
}
|
@@ -41,8 +33,7 @@ window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {};
|
|
41
33
|
preview = '>m_preview=' + preview + '>m_cookies_win=x'
|
42
34
|
}
|
43
35
|
|
44
|
-
|
45
|
-
this.googleSrc = 'https://www.googletagmanager.com/gtm.js?id=' + window.GOVUK.analyticsGA4.vars.id + auth + preview
|
36
|
+
this.googleSrc = 'https://www.googletagmanager.com/gtm.js?id=' + window.GOVUK.analyticsGa4.vars.id + auth + preview
|
46
37
|
newScript.src = this.googleSrc
|
47
38
|
firstScript.parentNode.insertBefore(newScript, firstScript)
|
48
39
|
window.dataLayer.push({ 'gtm.blocklist': ['customPixels', 'customScripts', 'html', 'nonGoogleScripts'] })
|
@@ -55,9 +46,9 @@ window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {};
|
|
55
46
|
},
|
56
47
|
|
57
48
|
getGemVersion: function () {
|
58
|
-
return
|
49
|
+
return window.GOVUK.analyticsGa4.vars.gem_version || 'not found'
|
59
50
|
}
|
60
51
|
}
|
61
52
|
|
62
53
|
analytics.core = core
|
63
|
-
})(window.GOVUK.
|
54
|
+
})(window.GOVUK.analyticsGa4)
|
@@ -3,10 +3,10 @@
|
|
3
3
|
'use strict'
|
4
4
|
|
5
5
|
var GOVUK = global.GOVUK || {}
|
6
|
-
GOVUK.
|
6
|
+
GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
|
7
7
|
|
8
|
-
GOVUK.
|
9
|
-
PIIRemover: new GOVUK.
|
8
|
+
GOVUK.analyticsGa4.Ga4EcommerceTracker = {
|
9
|
+
PIIRemover: new GOVUK.analyticsGa4.PIIRemover(),
|
10
10
|
DEFAULT_LIST_TITLE: 'Site search results',
|
11
11
|
|
12
12
|
init: function (isNewPageLoad) {
|
@@ -22,7 +22,7 @@
|
|
22
22
|
hence the pageView object push to the dataLayer. We do not need to send a pageView object on page load as
|
23
23
|
this is handled elsewhere. */
|
24
24
|
if (!this.isNewPageLoad) {
|
25
|
-
var pageViewTracker = window.GOVUK.
|
25
|
+
var pageViewTracker = window.GOVUK.analyticsGa4.analyticsModules.PageViewTracker
|
26
26
|
|
27
27
|
if (pageViewTracker) {
|
28
28
|
pageViewTracker.init()
|
@@ -90,7 +90,7 @@
|
|
90
90
|
})
|
91
91
|
|
92
92
|
ecommerceObject.event_data = {
|
93
|
-
external: GOVUK.
|
93
|
+
external: GOVUK.analyticsGa4.analyticsModules.Ga4LinkTracker.isExternalLink(searchResult.getAttribute('data-ecommerce-path')) ? 'true' : 'false'
|
94
94
|
}
|
95
95
|
} else {
|
96
96
|
for (var i = 0; i < ecommerceRows.length; i++) {
|
@@ -31,7 +31,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
31
31
|
Ga4EventTracker.prototype.trackClick = function (event) {
|
32
32
|
var target = this.findTrackingAttributes(event.target)
|
33
33
|
if (target) {
|
34
|
-
var schema = new window.GOVUK.
|
34
|
+
var schema = new window.GOVUK.analyticsGa4.Schemas().eventSchema()
|
35
35
|
|
36
36
|
try {
|
37
37
|
var data = target.getAttribute(this.trackingTrigger)
|
@@ -84,7 +84,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
84
84
|
}
|
85
85
|
}
|
86
86
|
|
87
|
-
window.GOVUK.
|
87
|
+
window.GOVUK.analyticsGa4.core.sendData(schema)
|
88
88
|
}
|
89
89
|
}
|
90
90
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// = require govuk/vendor/polyfills/Element/prototype/closest.js
|
2
2
|
window.GOVUK = window.GOVUK || {}
|
3
|
-
window.GOVUK.
|
4
|
-
window.GOVUK.
|
3
|
+
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
|
4
|
+
window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
|
5
5
|
|
6
6
|
(function (analyticsModules) {
|
7
7
|
'use strict'
|
@@ -97,7 +97,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
|
|
97
97
|
}
|
98
98
|
|
99
99
|
if (Object.keys(clickData).length > 0) {
|
100
|
-
var schema = new window.GOVUK.
|
100
|
+
var schema = new window.GOVUK.analyticsGa4.Schemas().eventSchema()
|
101
101
|
schema.event = 'event_data'
|
102
102
|
|
103
103
|
// get attributes from the clickData object to send to GA
|
@@ -108,7 +108,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
|
|
108
108
|
}
|
109
109
|
}
|
110
110
|
|
111
|
-
window.GOVUK.
|
111
|
+
window.GOVUK.analyticsGa4.core.sendData(schema)
|
112
112
|
}
|
113
113
|
},
|
114
114
|
|
@@ -251,4 +251,4 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
|
|
251
251
|
}
|
252
252
|
|
253
253
|
analyticsModules.Ga4LinkTracker = Ga4LinkTracker
|
254
|
-
})(window.GOVUK.
|
254
|
+
})(window.GOVUK.analyticsGa4.analyticsModules)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
window.GOVUK = window.GOVUK || {}
|
2
|
-
window.GOVUK.
|
3
|
-
window.GOVUK.
|
2
|
+
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
|
3
|
+
window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
|
4
4
|
|
5
5
|
(function (analyticsModules) {
|
6
6
|
'use strict'
|
7
7
|
|
8
8
|
var PageViewTracker = {
|
9
|
-
PIIRemover: new window.GOVUK.
|
9
|
+
PIIRemover: new window.GOVUK.analyticsGa4.PIIRemover(), // imported in analytics-ga4.js
|
10
10
|
nullValue: undefined,
|
11
11
|
|
12
12
|
init: function () {
|
@@ -45,7 +45,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
|
|
45
45
|
world_locations: this.getMetaContent('analytics:world-locations')
|
46
46
|
}
|
47
47
|
}
|
48
|
-
window.GOVUK.
|
48
|
+
window.GOVUK.analyticsGa4.core.sendData(data)
|
49
49
|
}
|
50
50
|
},
|
51
51
|
|
@@ -111,4 +111,4 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
|
|
111
111
|
}
|
112
112
|
|
113
113
|
analyticsModules.PageViewTracker = PageViewTracker
|
114
|
-
})(window.GOVUK.
|
114
|
+
})(window.GOVUK.analyticsGa4.analyticsModules)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
window.GOVUK = window.GOVUK || {}
|
2
|
-
window.GOVUK.
|
2
|
+
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
|
3
3
|
|
4
4
|
var initFunction = function () {
|
5
5
|
// to be added: digital identity consent mechanism
|
@@ -7,9 +7,9 @@ var initFunction = function () {
|
|
7
7
|
var consentCookie = window.GOVUK.getConsentCookie()
|
8
8
|
|
9
9
|
if (consentCookie && consentCookie.usage) {
|
10
|
-
window.GOVUK.
|
10
|
+
window.GOVUK.analyticsGa4.core.load()
|
11
11
|
|
12
|
-
var analyticsModules = window.GOVUK.
|
12
|
+
var analyticsModules = window.GOVUK.analyticsGa4.analyticsModules
|
13
13
|
for (var property in analyticsModules) {
|
14
14
|
var module = analyticsModules[property]
|
15
15
|
if (typeof module.init === 'function') {
|
@@ -18,8 +18,8 @@ var initFunction = function () {
|
|
18
18
|
}
|
19
19
|
// to be added: cross domain tracking code
|
20
20
|
} else {
|
21
|
-
window.addEventListener('cookie-consent', window.GOVUK.
|
21
|
+
window.addEventListener('cookie-consent', window.GOVUK.analyticsGa4.init)
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
-
window.GOVUK.
|
25
|
+
window.GOVUK.analyticsGa4.init = initFunction
|
@@ -128,8 +128,8 @@
|
|
128
128
|
return string
|
129
129
|
}
|
130
130
|
|
131
|
-
GOVUK.
|
132
|
-
GOVUK.
|
131
|
+
GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
|
132
|
+
GOVUK.analyticsGa4.PIIRemover = PIIRemover
|
133
133
|
|
134
134
|
global.GOVUK = GOVUK
|
135
135
|
})(window)
|
@@ -5,5 +5,5 @@
|
|
5
5
|
//= require ./analytics-ga4/ga4-page-views
|
6
6
|
//= require ./analytics-ga4/ga4-link-tracker
|
7
7
|
//= require ./analytics-ga4/ga4-event-tracker
|
8
|
-
//= require ./analytics-ga4/ga4-
|
8
|
+
//= require ./analytics-ga4/ga4-ecommerce-tracker
|
9
9
|
//= require ./analytics-ga4/init-ga4
|
@@ -59,11 +59,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
|
|
59
59
|
|
60
60
|
// Navigate to and open accordions with anchored content on page load if a hash is present
|
61
61
|
GemAccordion.prototype.openByAnchorOnLoad = function () {
|
62
|
+
if (!window.location.hash) return
|
62
63
|
var splitHash = window.location.hash.split('#')[1]
|
63
|
-
|
64
|
-
if (window.location.hash && document.getElementById(splitHash)) {
|
65
|
-
this.openForAnchor(splitHash)
|
66
|
-
}
|
64
|
+
this.openForAnchor(splitHash)
|
67
65
|
}
|
68
66
|
|
69
67
|
// Add event listeners for links to open accordion sections when navigated to using said anchor links on the page
|
@@ -80,7 +78,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
|
|
80
78
|
|
81
79
|
// Find the parent accordion section for the given id and open it
|
82
80
|
GemAccordion.prototype.openForAnchor = function (hash) {
|
83
|
-
|
81
|
+
hash = hash.replace(':', '\\:')
|
82
|
+
var target = this.$module.querySelector('#' + hash)
|
83
|
+
if (!target) return
|
84
84
|
var $section = this.getContainingSection(target)
|
85
85
|
var $header = $section.querySelector(this.sectionHeader)
|
86
86
|
var $expanded = this.getContainingSection($section)
|
@@ -187,7 +187,7 @@ examples:
|
|
187
187
|
|
188
188
|
The `data_attributes` option applies attributes to the outermost element in the accordion. Each item can also have a `data_attributes` hash, which are placed on the `button` that triggers the opening and closing - useful for differentiating between each section of the accordion.
|
189
189
|
|
190
|
-
Data attributes can be added to the 'Show/hide all' link using the `data_attributes_show_all` option, primarily where custom tracking is required. These attributes are read from the accordion markup and then added to the link by JavaScript (which is how the link is created). More details on how this can be used with the GA4 event tracking can be found in the 'Advanced' section of the [event tracking documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-
|
190
|
+
Data attributes can be added to the 'Show/hide all' link using the `data_attributes_show_all` option, primarily where custom tracking is required. These attributes are read from the accordion markup and then added to the link by JavaScript (which is how the link is created). More details on how this can be used with the GA4 event tracking can be found in the 'Advanced' section of the [event tracking documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-event-tracker.md).
|
191
191
|
|
192
192
|
If `track_options` within `data_attributes_show_all` is set, then it is possible to pass a custom dimension when 'Show/Hide all' is clicked.
|
193
193
|
data:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 31.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_app_config
|
@@ -436,8 +436,8 @@ files:
|
|
436
436
|
- app/assets/javascripts/component_guide/vendor/matches-polyfill.min.js
|
437
437
|
- app/assets/javascripts/govuk_publishing_components/all_components.js
|
438
438
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
|
439
|
-
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
|
440
|
-
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-
|
439
|
+
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
|
440
|
+
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js
|
441
441
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
|
442
442
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js
|
443
443
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js
|