govuk_publishing_components 34.9.1 → 34.10.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-auto-tracker.js +46 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +10 -4
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +9 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss +9 -0
- data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +16 -6
- data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +16 -20
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '02198ba8894765b065f3835bbc229f0a5ebe82da8d81b7eae0cd2926874c629d'
|
4
|
+
data.tar.gz: c74c4a44f50497650fe6f13acead0ecf07ae005c2c4b83327135e68c556d4445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d710c78158dc0f1b6a194e133fc1e8fa10b6611d38025261cef1f4d1076be4c4e5e516d2ef008a3d619ee672c0af3870468481a7960585d9ce37340aaf41c83
|
7
|
+
data.tar.gz: dc8fb3e2b90175173e7d39a0bcd8da797c8b0713676b1184cdb56b46146ff9ef55e5a3707e843dcc65b52ebf60efb04af331386c4b4a2e7bb41c0b65a7e7c390
|
@@ -0,0 +1,46 @@
|
|
1
|
+
window.GOVUK = window.GOVUK || {}
|
2
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
+
|
4
|
+
(function (Modules) {
|
5
|
+
'use strict'
|
6
|
+
|
7
|
+
function Ga4AutoTracker (module) {
|
8
|
+
this.module = module
|
9
|
+
this.trackingTrigger = 'data-ga4-auto'
|
10
|
+
}
|
11
|
+
|
12
|
+
Ga4AutoTracker.prototype.init = function () {
|
13
|
+
var consentCookie = window.GOVUK.getConsentCookie()
|
14
|
+
|
15
|
+
if (consentCookie && consentCookie.settings) {
|
16
|
+
this.startModule()
|
17
|
+
} else {
|
18
|
+
this.startModule = this.startModule.bind(this)
|
19
|
+
window.addEventListener('cookie-consent', this.startModule)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
Ga4AutoTracker.prototype.startModule = function () {
|
24
|
+
this.sendEvent()
|
25
|
+
}
|
26
|
+
|
27
|
+
Ga4AutoTracker.prototype.sendEvent = function () {
|
28
|
+
if (window.dataLayer) {
|
29
|
+
try {
|
30
|
+
var data = this.module.getAttribute(this.trackingTrigger)
|
31
|
+
data = JSON.parse(data)
|
32
|
+
} catch (e) {
|
33
|
+
// if there's a problem with the config, don't start the tracker
|
34
|
+
console.error('GA4 configuration error: ' + e.message, window.location)
|
35
|
+
return
|
36
|
+
}
|
37
|
+
|
38
|
+
var schemas = new window.GOVUK.analyticsGa4.Schemas()
|
39
|
+
var schema = schemas.mergeProperties(data, 'event_data')
|
40
|
+
|
41
|
+
window.GOVUK.analyticsGa4.core.sendData(schema)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
Modules.Ga4AutoTracker = Ga4AutoTracker
|
46
|
+
})(window.GOVUK.Modules)
|
@@ -63,13 +63,17 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
|
63
63
|
return
|
64
64
|
}
|
65
65
|
|
66
|
+
return this.splitStringIntoParts(path)
|
67
|
+
},
|
68
|
+
|
69
|
+
splitStringIntoParts: function (string) {
|
66
70
|
/*
|
67
71
|
This will create an object with 5 keys that are indexes ("1", "2", etc.)
|
68
|
-
The values will be each part of the
|
72
|
+
The values will be each part of the string split every 100 characters, or undefined.
|
69
73
|
For example: {"1": "/hello/world/etc...", "2": "/more/path/text...", "3": undefined, "4": undefined, "5": undefined}
|
70
74
|
Undefined values are needed to override the persistent object in GTM so that any values from old pushes are overwritten.
|
71
75
|
*/
|
72
|
-
var parts =
|
76
|
+
var parts = string.match(/.{1,100}/g)
|
73
77
|
var obj = {}
|
74
78
|
for (var i = 0; i < 5; i++) {
|
75
79
|
obj[(i + 1).toString()] = parts[i]
|
@@ -188,8 +192,10 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
|
188
192
|
} else {
|
189
193
|
// This regex matches a protocol and domain name at the start of a string such as https://www.gov.uk, http://gov.uk, //gov.uk
|
190
194
|
var domainRegex = /^(http:||https:)?(\/\/)([^\/]*)/ // eslint-disable-line no-useless-escape
|
191
|
-
var domain = domainRegex.exec(href)
|
192
|
-
|
195
|
+
var domain = domainRegex.exec(href)
|
196
|
+
if (domain) {
|
197
|
+
return domain[0]
|
198
|
+
}
|
193
199
|
}
|
194
200
|
},
|
195
201
|
|
@@ -31,8 +31,8 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
|
|
31
31
|
taxonomy_level1: this.getMetaContent('themes'),
|
32
32
|
taxonomy_main: this.getMetaContent('taxon-slug'),
|
33
33
|
taxonomy_main_id: this.getMetaContent('taxon-id'),
|
34
|
-
taxonomy_all: this.
|
35
|
-
taxonomy_all_ids: this.
|
34
|
+
taxonomy_all: this.splitLongMetaContent('taxon-slugs'),
|
35
|
+
taxonomy_all_ids: this.splitLongMetaContent('taxon-ids'),
|
36
36
|
|
37
37
|
language: this.getLanguage(),
|
38
38
|
history: this.getHistory(),
|
@@ -106,6 +106,13 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
|
|
106
106
|
return (withdrawn === 'withdrawn') ? 'true' : 'false'
|
107
107
|
},
|
108
108
|
|
109
|
+
splitLongMetaContent: function (metatag) {
|
110
|
+
var tag = this.getMetaContent(metatag)
|
111
|
+
if (tag) {
|
112
|
+
return window.GOVUK.analyticsGa4.core.trackFunctions.splitStringIntoParts(tag)
|
113
|
+
}
|
114
|
+
},
|
115
|
+
|
109
116
|
// return only the date from given timestamps of the form
|
110
117
|
// 2022-03-28T19:11:00.000+00:00
|
111
118
|
stripTimeFrom: function (value) {
|
@@ -17,3 +17,12 @@ $gem-quiet-button-colour: govuk-colour("dark-grey", $legacy: "grey-1");
|
|
17
17
|
$gem-quiet-button-hover-colour: darken($gem-quiet-button-colour, 5%);
|
18
18
|
|
19
19
|
$gem-hover-dark-background: #dddcdb;
|
20
|
+
|
21
|
+
$govuk-colours-organisations: map-merge(
|
22
|
+
$govuk-colours-organisations,
|
23
|
+
(
|
24
|
+
"department-for-energy-security-and-net-zero": (
|
25
|
+
colour: #0da04a
|
26
|
+
)
|
27
|
+
)
|
28
|
+
);
|
@@ -29,6 +29,6 @@
|
|
29
29
|
<% end %>
|
30
30
|
|
31
31
|
<% if navigation.show_ukraine_cta? %>
|
32
|
-
<%= render 'govuk_publishing_components/components/contextual_sidebar/ukraine_cta', content_item: content_item %>
|
32
|
+
<%= render 'govuk_publishing_components/components/contextual_sidebar/ukraine_cta', content_item: content_item, ga4_tracking: ga4_tracking %>
|
33
33
|
<% end %>
|
34
34
|
</div>
|
data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
-
<%
|
2
|
-
|
1
|
+
<%
|
2
|
+
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
|
3
3
|
title = t("components.related_navigation.ukraine.title")
|
4
4
|
lang = shared_helper.t_locale("components.related_navigation.ukraine.title")
|
5
|
+
data_module = "gem-track-click"
|
6
|
+
data_module << " ga4-link-tracker" if ga4_tracking
|
5
7
|
%>
|
6
|
-
|
7
|
-
<%= tag.div class: "gem-c-contextual-sidebar__cta gem-c-contextual-sidebar__cta--ukraine", data: { module: "gem-track-click" } do %>
|
8
|
+
<%= tag.div class: "gem-c-contextual-sidebar__cta gem-c-contextual-sidebar__cta--ukraine", data: { module: data_module } do %>
|
8
9
|
<%= tag.h2 title, class: "gem-c-contextual-sidebar__heading govuk-heading-s" %>
|
9
10
|
<%= tag.ul class: "gem-c-contextual-sidebar__list" do %>
|
10
|
-
<% t("components.related_navigation.ukraine.links").
|
11
|
+
<% t("components.related_navigation.ukraine.links").each_with_index do |link, index| %>
|
11
12
|
<%= tag.li class: "gem-c-contextual-sidebar__text govuk-body" do %>
|
13
|
+
<%
|
14
|
+
ga4_attributes = {
|
15
|
+
event_name: "navigation",
|
16
|
+
type: "related content",
|
17
|
+
index: "1.#{index + 1}",
|
18
|
+
section: title,
|
19
|
+
} if ga4_tracking
|
20
|
+
%>
|
12
21
|
<%= link_to link[:label],
|
13
22
|
link[:href],
|
14
23
|
class: "govuk-link",
|
@@ -18,9 +27,10 @@
|
|
18
27
|
"track-label": link[:href],
|
19
28
|
"track-dimension": link[:label],
|
20
29
|
"track-dimension-index": "29",
|
30
|
+
ga4_link: ga4_attributes,
|
21
31
|
},
|
22
32
|
lang: lang %>
|
23
33
|
<% end %>
|
24
34
|
<% end %>
|
25
|
-
<% end %>
|
35
|
+
<% end %>
|
26
36
|
<% end %>
|
@@ -104,7 +104,7 @@ examples:
|
|
104
104
|
base_path: "/government/topical-events/russian-invasion-of-ukraine-uk-government-response"
|
105
105
|
locale: "en"
|
106
106
|
with_ga4_tracking_on_related_navigation:
|
107
|
-
description: Adds Google Analytics 4 tracking to components within the sidebar. Currently only the Related Navigation
|
107
|
+
description: Adds Google Analytics 4 tracking to components within the sidebar. Currently only the Related Navigation component, Step by Step navigation component and Ukraine CTA accept this option.
|
108
108
|
data:
|
109
109
|
ga4_tracking: true
|
110
110
|
content_item:
|
@@ -124,40 +124,36 @@ examples:
|
|
124
124
|
- title: The future of jobs and skills
|
125
125
|
base_path: /government/collections/the-future-of-jobs-and-skills
|
126
126
|
document_type: document_collection
|
127
|
+
topical_events:
|
128
|
+
- content_id: "bfa79635-ffda-4b5d-8266-a9cd3a03649c"
|
129
|
+
title: "Russian invasion of Ukraine: UK government response"
|
130
|
+
base_path: "/government/topical-events/russian-invasion-of-ukraine-uk-government-response"
|
131
|
+
locale: "en"
|
127
132
|
with_ga4_tracking_on_step_by_step:
|
128
|
-
description: Adds Google Analytics 4 tracking to components within the sidebar. Currently only the Related Navigation
|
133
|
+
description: Adds Google Analytics 4 tracking to components within the sidebar. Currently only the Related Navigation component, Step by Step navigation component and Ukraine CTA accept this option.
|
129
134
|
data:
|
130
135
|
ga4_tracking: true
|
131
136
|
content_item:
|
132
137
|
title: "A content item"
|
133
138
|
links:
|
134
139
|
part_of_step_navs:
|
135
|
-
- title: "
|
136
|
-
base_path: "/
|
140
|
+
- title: "What to do when someone dies: step by step"
|
141
|
+
base_path: "/when-someone-dies"
|
137
142
|
details:
|
138
143
|
step_by_step_nav:
|
139
|
-
title: '
|
144
|
+
title: 'What to do when someone dies: step by step'
|
140
145
|
steps:
|
141
|
-
- title:
|
146
|
+
- title: Register the death
|
142
147
|
contents:
|
143
|
-
- type: paragraph
|
144
|
-
text: Most people can start learning to drive when they’re 17.
|
145
148
|
- type: list
|
146
149
|
contents:
|
147
|
-
- text:
|
148
|
-
href: "/
|
150
|
+
- text: Register the death
|
151
|
+
href: "/after-a-death"
|
149
152
|
optional: false
|
150
|
-
- title:
|
151
|
-
logic: and
|
153
|
+
- title: Arrange the funeral
|
152
154
|
contents:
|
153
|
-
- type: paragraph
|
154
|
-
text: hello hello what's UP
|
155
|
-
- title: Driving lessons and practice
|
156
|
-
contents:
|
157
|
-
- type: paragraph
|
158
|
-
text: You need a provisional driving licence to take lessons or practice.
|
159
155
|
- type: list
|
160
156
|
contents:
|
161
|
-
- text:
|
162
|
-
href: "/
|
157
|
+
- text: Arrange the funeral
|
158
|
+
href: "/after-a-death/arrange-the-funeral"
|
163
159
|
optional: false
|
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: 34.
|
4
|
+
version: 34.10.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: 2023-02-
|
11
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_app_config
|
@@ -439,6 +439,7 @@ files:
|
|
439
439
|
- app/assets/javascripts/component_guide/vendor/matches-polyfill.min.js
|
440
440
|
- app/assets/javascripts/govuk_publishing_components/all_components.js
|
441
441
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
|
442
|
+
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js
|
442
443
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
|
443
444
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js
|
444
445
|
- app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
|