govuk_publishing_components 34.9.0 → 34.10.0

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: b6da9ed1af8922136300b056ca61432de28330b478e25e23334917d0fdec9041
4
- data.tar.gz: 2efcf7e5c91aaca82158059670b6b5ea7d4f52cb998b49a23e13deb32276958e
3
+ metadata.gz: '02198ba8894765b065f3835bbc229f0a5ebe82da8d81b7eae0cd2926874c629d'
4
+ data.tar.gz: c74c4a44f50497650fe6f13acead0ecf07ae005c2c4b83327135e68c556d4445
5
5
  SHA512:
6
- metadata.gz: c5b8de64f9ba866ce83e1ef48be8d42f3f57b74891f446cba362c83e1a4be599d67039fc9f4cd9ee2e3b77345a4fb2955310a2aefb45b9bfcdf59e69bc06fdd3
7
- data.tar.gz: 75251f6417ec2c5e3e542eab3f2a914b93c9a5153f6b3be40848640d1e4944d2186e169a26198760cac76f482667e1d73e743105504c465b31974c583b4a0f3f
6
+ metadata.gz: 7d710c78158dc0f1b6a194e133fc1e8fa10b6611d38025261cef1f4d1076be4c4e5e516d2ef008a3d619ee672c0af3870468481a7960585d9ce37340aaf41c83
7
+ data.tar.gz: dc8fb3e2b90175173e7d39a0bcd8da797c8b0713676b1184cdb56b46146ff9ef55e5a3707e843dcc65b52ebf60efb04af331386c4b4a2e7bb41c0b65a7e7c390
data/README.md CHANGED
@@ -39,6 +39,7 @@ yarn run jasmine:ci
39
39
 
40
40
  - [Install and use this gem](docs/install-and-use.md)
41
41
  - [Use a component in your application](docs/use-components.md)
42
+ - [Test a branch of the gem](docs/test-a-branch-of-the-gem.md)
42
43
 
43
44
  ### Managing the gem
44
45
 
@@ -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
@@ -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>
@@ -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
@@ -58,7 +58,7 @@ examples:
58
58
  subscribe: 'Subscribe to this page of things'
59
59
  unsubscribe: 'Unsubscribe to this page of things'
60
60
  with_skip_account:
61
- description: If the skip_account flag is present, the button action will be set to the non GOV.UK account signup endpoint of /email-signup.
61
+ description: If the skip_account flag is present, the button action will be set to the non GOV.UK One Login signup endpoint of /email-signup.
62
62
  data:
63
63
  base_path: '/current-page-path'
64
64
  js_enhancement: true
@@ -153,9 +153,9 @@ en:
153
153
  navigation:
154
154
  menu_bar:
155
155
  account:
156
- link_text: Your account
156
+ link_text: Your GOV.UK One Login
157
157
  manage:
158
- link_text: Manage your account
158
+ link_text: Settings
159
159
  layout_header:
160
160
  hide_button: Hide search
161
161
  menu: Menu
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "34.9.0".freeze
2
+ VERSION = "34.10.0".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.0
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-08 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