govuk_publishing_components 34.9.1 → 34.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f8b043d1285aa3d0477957b2472686e584b62fc8dc89f0e74dde18c989f3c4a
4
- data.tar.gz: 4bf6daf82bb9958e9d042b75f03d424be2f985ec02ffc3b18aef68f3b8a3b47c
3
+ metadata.gz: 135e634f4b00ec7ed1030e313d6ee52f1202a0a6a2c83be7722d1a20dac4463b
4
+ data.tar.gz: a41d77bfdef86a922c417c9d53e0c98b8d9f87bf942e38c477518b5ac6fffc28
5
5
  SHA512:
6
- metadata.gz: 61de44ede7ebe2d0f79c642648edf6ec9e7894c05d5e36a0d8f4dbf15f82dc66d43c0320819459d4034a8c9dc8b42b6ae2c69f2946b200160cf6eebc7a6c3aae
7
- data.tar.gz: 16ef6c35ed6ef86b4ad420baaa2ecac77b513065d68a7c9b7380d910d1318a5e4ee1ac314fa7d69e0474333761f3e615bad1ff817e84dbf132c6b74042f6d7bd
6
+ metadata.gz: cf937ba2e03913a679decc84d49dbef881ee1647af4235311c39a2bcfbabdbc838c10f10f5ca2ad67fa42832bb9c0c91c614797c13faa6fd0fb109d83df40f90
7
+ data.tar.gz: 3f8857da3f7227d59d765e0fdb92fea13d4abc0978af9ed07b005c2877e20be68d41f40b1450688adaa4b3f781e5d6b2303feb97928776f2644daed474735e33
@@ -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 link path split every 100 characters, or undefined.
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 = path.match(/.{1,100}/g)
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)[0]
192
- return domain
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.getMetaContent('taxon-slugs'),
35
- taxonomy_all_ids: this.getMetaContent('taxon-ids'),
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) {
@@ -8,4 +8,5 @@
8
8
  //= require ./analytics-ga4/ga4-event-tracker
9
9
  //= require ./analytics-ga4/ga4-ecommerce-tracker
10
10
  //= require ./analytics-ga4/ga4-form-tracker
11
+ //= require ./analytics-ga4/ga4-auto-tracker
11
12
  //= require ./analytics-ga4/init-ga4
@@ -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>
@@ -1,14 +1,23 @@
1
- <% shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns) %>
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").each do |link| %>
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 and Step by Step navigation components accept this option.
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 and Step by Step navigation components accept this option.
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: "Learn to drive a car: step by step"
136
- base_path: "/micropigs-vs-micropugs"
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: 'Stay in the UK after it leaves the EU (''settled status''): step by step'
144
+ title: 'What to do when someone dies: step by step'
140
145
  steps:
141
- - title: Check you're allowed to drive
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: Check what age you can drive
148
- href: "/vehicles-can-drive"
150
+ - text: Register the death
151
+ href: "/after-a-death"
149
152
  optional: false
150
- - title: Testing the and
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: The Highway Code
162
- href: "/guidance/the-highway-code"
157
+ - text: Arrange the funeral
158
+ href: "/after-a-death/arrange-the-funeral"
163
159
  optional: false
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "34.9.1".freeze
2
+ VERSION = "34.10.1".freeze
3
3
  end
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.9.1
4
+ version: 34.10.1
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-09 00:00:00.000000000 Z
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