govuk_publishing_components 34.13.0 → 34.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21e3ffb5b58dc3b31d794d2582929eac560f6dbf9509bf79164e90718483ef18
4
- data.tar.gz: 7c003248697419a6c54c6fdeba073fbce724390f266a54ba7e2a3149447f75d2
3
+ metadata.gz: c4137db9fa2f61ba41157832c2d8a959756eb36e11837e4d58654b264d68a3f0
4
+ data.tar.gz: a3eb50516bf440839af9b74e1fc5ab44e9fc21ee0afb7910cdb742d10a6d3182
5
5
  SHA512:
6
- metadata.gz: 90c9c967e09f36e6c9c8fefed7db444427ff14568e800a6b9255dfb69eab7c6e81f78e6eb939958075645822f9d9ca93875c91a1f83b38be61e4951522a584f0
7
- data.tar.gz: 5163288eb0c08e404376545724810b3854a5f745f6e4ad0fd1fe23a3ef82fa152ac14b1c2971df6b6f8e04563b0ddac4018ec218f5e6dabe85879481cbd39f28
6
+ metadata.gz: 3e780d3b9f9f2e72c471767c7be3bb611bae0eb7f2b211e19ae85b6fdae4338ae20d346c53b72c6d1b1d0e3d06447084eb389aeb64960df48b68d60bdaa4ed7e
7
+ data.tar.gz: 7cfd8703805c415ffad093fd18dc104d6d41c7e51305673c178b90778eb52bf3037b52ea2550cdb42c0ba4291d6e53c95c577800f2b8fe398ee503c1a3910b76
@@ -28,13 +28,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
28
28
  if (window.dataLayer) {
29
29
  try {
30
30
  var data = this.module.getAttribute(this.trackingTrigger)
31
- data = JSON.parse(data)
31
+ data = JSON.parse(data) || {}
32
32
  } catch (e) {
33
33
  // if there's a problem with the config, don't start the tracker
34
34
  console.error('GA4 configuration error: ' + e.message, window.location)
35
35
  return
36
36
  }
37
37
 
38
+ if (data.index) {
39
+ data.index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(data.index)
40
+ }
38
41
  var schemas = new window.GOVUK.analyticsGa4.Schemas()
39
42
  var schema = schemas.mergeProperties(data, 'event_data')
40
43
 
@@ -237,6 +237,37 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
237
237
  var ga4LinkData = JSON.parse(module.getAttribute('data-ga4-link'))
238
238
  ga4LinkData.index_total = totalLinks
239
239
  module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
240
+ },
241
+
242
+ // index is given as a string of the form 1.2.3 or 1.2
243
+ // split this into named sub-parameters
244
+ createIndexObject: function (index) {
245
+ if (typeof index === 'undefined') {
246
+ return undefined
247
+ }
248
+ if (typeof index === 'object') {
249
+ return index
250
+ }
251
+
252
+ index = index.toString().split('.')
253
+ // this will soon include 'index_section_count'
254
+ // number of sections overall in the thing being tracked (but not yet in use)
255
+ switch (index.length) {
256
+ case 1:
257
+ return {
258
+ index_section: parseInt(index[0])
259
+ }
260
+ case 2:
261
+ return {
262
+ index_section: parseInt(index[0]),
263
+ index_link: parseInt(index[1])
264
+ }
265
+ case 3:
266
+ return {
267
+ index_section: parseInt(index[1]),
268
+ index_link: parseInt(index[2])
269
+ }
270
+ }
240
271
  }
241
272
  },
242
273
 
@@ -42,6 +42,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
42
42
 
43
43
  var text = data.text || event.target.textContent
44
44
  data.text = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(text)
45
+ data.index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(data.index)
45
46
 
46
47
  var schemas = new window.GOVUK.analyticsGa4.Schemas()
47
48
  var schema = schemas.mergeProperties(data, 'event_data')
@@ -87,6 +87,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
87
87
  data.method = window.GOVUK.analyticsGa4.core.trackFunctions.getClickType(event)
88
88
  data.external = window.GOVUK.analyticsGa4.core.trackFunctions.isExternalLink(data.url) ? 'true' : 'false'
89
89
  data.index = event.target.getAttribute('data-ga4-index') ? parseInt(event.target.getAttribute('data-ga4-index')) : data.index || undefined
90
+ data.index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(data.index)
90
91
 
91
92
  var schemas = new window.GOVUK.analyticsGa4.Schemas()
92
93
  var schema = schemas.mergeProperties(data, 'event_data')
@@ -1,7 +1,10 @@
1
- <% prioritise_taxon_breadcrumbs ||= false %>
2
- <% breadcrumb_selector = GovukPublishingComponents::Presenters::BreadcrumbSelector.new(content_item, request, prioritise_taxon_breadcrumbs) %>
3
- <% inverse ||= false %>
4
- <% collapse_on_mobile ||= true unless local_assigns[:collapse_on_mobile].eql?(false) %>
1
+ <%
2
+ ga4_tracking ||= false
3
+ prioritise_taxon_breadcrumbs ||= false
4
+ breadcrumb_selector = GovukPublishingComponents::Presenters::BreadcrumbSelector.new(content_item, request, prioritise_taxon_breadcrumbs, ga4_tracking)
5
+ inverse ||= false
6
+ collapse_on_mobile ||= true unless local_assigns[:collapse_on_mobile].eql?(false)
7
+ %>
5
8
 
6
9
  <div class="gem-c-contextual-breadcrumbs">
7
10
  <% if breadcrumb_selector.step_by_step %>
@@ -10,7 +10,7 @@
10
10
  <div class="gem-c-contextual-sidebar">
11
11
  <% if navigation.content_tagged_to_a_reasonable_number_of_step_by_steps? %>
12
12
  <%# Rendering step by step related items because there are a few but not too many of them %>
13
- <%= render 'govuk_publishing_components/components/step_by_step_nav_related', links: navigation.step_nav_helper.related_links %>
13
+ <%= render 'govuk_publishing_components/components/step_by_step_nav_related', links: navigation.step_nav_helper.related_links, ga4_tracking: ga4_tracking %>
14
14
  <% end %>
15
15
 
16
16
  <% if navigation.content_tagged_to_current_step_by_step? %>
@@ -26,7 +26,8 @@
26
26
  <%= render 'govuk_publishing_components/components/step_by_step_nav_related', {
27
27
  pretitle: t("components.contextual_sidebar.pretitle"),
28
28
  links: navigation.step_nav_helper.also_part_of_step_nav,
29
- always_display_as_list: true
29
+ always_display_as_list: true,
30
+ ga4_tracking: ga4_tracking
30
31
  } %>
31
32
  <% end %>
32
33
 
@@ -3,12 +3,17 @@
3
3
 
4
4
  title ||= false
5
5
  path ||= false
6
+ ga4_tracking ||= false
6
7
  breadcrumbs = [
7
8
  { title: "Home", url: "/" },
8
9
  { title: title, url: path }
9
10
  ]
10
11
  breadcrumb_presenter = GovukPublishingComponents::Presenters::Breadcrumbs.new(breadcrumbs)
11
12
 
13
+ data = {}
14
+ data[:module] = "gem-track-click"
15
+ data[:module] << " ga4-link-tracker" if ga4_tracking
16
+
12
17
  tracking_id ||= false
13
18
  tracking_category ||= "stepNavHeaderClicked"
14
19
  tracking_action ||= "top"
@@ -30,7 +35,7 @@
30
35
  <%= raw JSON.pretty_generate(breadcrumb_presenter.structured_data) %>
31
36
  </script>
32
37
 
33
- <%= tag.div class: classes, data: { module: "gem-track-click" } do %>
38
+ <%= tag.div(class: classes, data: data) do %>
34
39
  <strong class="gem-c-step-nav-header__part-of">Part of</strong>
35
40
  <% if path %>
36
41
  <a href="<%= path %>"
@@ -38,6 +43,9 @@
38
43
  data-track-category="<%= tracking_category %>"
39
44
  data-track-action="<%= tracking_action %>"
40
45
  data-track-label="<%= tracking_label %>"
46
+ <% if ga4_tracking %>
47
+ data-ga4-link='{"event_name":"navigation", "type":"super breadcrumb", "index":{"index_link": "1"}, "index_total":"1"}'
48
+ <% end %>
41
49
  <% if tracking_dimension_enabled %>
42
50
  data-track-dimension="<%= tracking_dimension %>"
43
51
  data-track-dimension-index="<%= tracking_dimension_index %>"
@@ -1,14 +1,17 @@
1
1
  <%
2
2
  add_gem_component_stylesheet("step-by-step-nav-related")
3
-
3
+ ga4_tracking ||= false
4
4
  links ||= []
5
5
  pretitle ||= t("components.step_by_step_nav_related.part_of")
6
6
  always_display_as_list ||= false
7
+ classes = %w(gem-c-step-nav-related)
8
+ classes << "gem-c-step-nav-related--singular" if links.length == 1
9
+ data = {}
10
+ data[:module] = "gem-track-click"
11
+ data[:module] << " ga4-link-tracker" if ga4_tracking
7
12
  %>
8
13
  <% if links.any? %>
9
- <div
10
- class="gem-c-step-nav-related <%= "gem-c-step-nav-related--singular" if links.length == 1 %>"
11
- data-module="gem-track-click">
14
+ <%= tag.div(class: classes, data: data) do %>
12
15
  <h2 class="gem-c-step-nav-related__heading">
13
16
  <span class="gem-c-step-nav-related__pretitle"><%= pretitle %></span>
14
17
  <% if links.length == 1 && !always_display_as_list %>
@@ -19,14 +22,18 @@
19
22
  data-track-label="<%= links[0][:href] %>"
20
23
  data-track-dimension="<%= links[0][:text] %>"
21
24
  data-track-dimension-index="29"
22
- data-track-options='{"dimension96" : "<%= links[0][:tracking_id] %>" }'>
25
+ data-track-options='{"dimension96" : "<%= links[0][:tracking_id] %>" }'
26
+ <% if ga4_tracking %>
27
+ data-ga4-link='{"event_name":"navigation", "type":"related content", "index":{"index_link": "1"}, "index_total":"1"}'
28
+ <% end %>
29
+ >
23
30
  <%= links[0][:text] %>
24
31
  </a>
25
32
  </h2>
26
33
  <% else %>
27
34
  </h2>
28
35
  <ul class="gem-c-step-nav-related__links">
29
- <% links.each do |link| %>
36
+ <% links.each_with_index do |link, index| %>
30
37
  <li class="gem-c-step-nav-related__link-item">
31
38
  <a href="<%= link[:href] %>"
32
39
  class="govuk-link"
@@ -35,12 +42,16 @@
35
42
  data-track-label="<%= link[:href] %>"
36
43
  data-track-dimension="<%= link[:text] %>"
37
44
  data-track-dimension-index="29"
38
- data-track-options='{"dimension96" : "<%= link[:tracking_id] %>" }'>
45
+ data-track-options='{"dimension96" : "<%= link[:tracking_id] %>" }'
46
+ <% if ga4_tracking %>
47
+ data-ga4-link='{"event_name":"navigation", "type":"related content", "index":{"index_link": "<%= index + 1 %>"}, "index_total": "<%= links.length %>"}'
48
+ <% end %>
49
+ >
39
50
  <%= link[:text] %>
40
51
  </a>
41
52
  </li>
42
53
  <% end %>
43
54
  </ul>
44
55
  <% end %>
45
- </div>
46
- <% end %>
56
+ <% end %>
57
+ <% end %>
@@ -32,3 +32,16 @@ examples:
32
32
  inverse: true
33
33
  context:
34
34
  dark_background: true
35
+ with_ga4_tracking:
36
+ description: |
37
+ Adds GA4 tracking to the step by step nav header component when it is rendered as a breadcrumb. See the
38
+ [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
39
+ Note: tracking on regular breadcrumbs is enabled by default and does not require activating.
40
+ data:
41
+ ga4_tracking: true
42
+ content_item:
43
+ title: "A content item"
44
+ links:
45
+ part_of_step_navs:
46
+ - title: "Learn to drive a car: step by step"
47
+ base_path: "/micropigs-vs-micropugs"
@@ -157,3 +157,14 @@ examples:
157
157
  - text: Arrange the funeral
158
158
  href: "/after-a-death/arrange-the-funeral"
159
159
  optional: false
160
+ with_ga4_tracking_on_part_of_step_by_step_heading(s):
161
+ description: Adds Google Analytics 4 tracking to the "Part of" step by step heading(s) in the sidebar. Currently only the Related Navigation component, Step by Step navigation component and Ukraine CTA accept this option.
162
+ data:
163
+ ga4_tracking: true
164
+ content_item:
165
+ links:
166
+ part_of_step_navs:
167
+ - title: "Choosing a micropig or micropug: step by step"
168
+ base_path: "/micropigs-vs-micropugs"
169
+ - title: "Walk your micropig: step by step"
170
+ base_path: "/porgs-step-by-step"
@@ -51,3 +51,9 @@ examples:
51
51
  tracking_action: "customTrackingAction"
52
52
  tracking_label: "customTrackingLabel"
53
53
  tracking_dimension_enabled: false
54
+ with_ga4_tracking:
55
+ description: The ga4_tracking boolean allows you to add Google Analytics 4 (GA4) tracking to your component. Setting this to true will add the `ga4-link-tracker` module to your component. The JavaScript will then add a `data-ga4-link` attribute which contains a JSON object with data relevant to our tracking. See the [ga4-link-tracker docs](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
56
+ data:
57
+ ga4_tracking: true
58
+ title: 'Learn to drive a motorbike: step by step'
59
+ path: /learn-to-drive-a-motorbike
@@ -76,3 +76,13 @@ examples:
76
76
  text: 'Learn to drive a motorbike: step by step'
77
77
  }
78
78
  ]
79
+ with_ga4_tracking:
80
+ description: The ga4_tracking boolean allows you to add Google Analytics 4 (GA4) tracking to your component. Setting this to true will add the `ga4-link-tracker` module to your component. The JavaScript will then add a `data-ga4-link` attribute which contains a JSON object with data relevant to our tracking. See the [ga4-link-tracker docs](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
81
+ data:
82
+ ga4_tracking: true
83
+ links: [
84
+ {
85
+ href: '#',
86
+ text: 'With ga4 tracking'
87
+ }
88
+ ]
@@ -3,10 +3,11 @@ module GovukPublishingComponents
3
3
  class BreadcrumbSelector
4
4
  attr_reader :content_item, :request, :prioritise_taxon_breadcrumbs
5
5
 
6
- def initialize(content_item, request, prioritise_taxon_breadcrumbs)
6
+ def initialize(content_item, request, prioritise_taxon_breadcrumbs, ga4_tracking)
7
7
  @content_item = content_item
8
8
  @request = request
9
9
  @prioritise_taxon_breadcrumbs = prioritise_taxon_breadcrumbs
10
+ @ga4_tracking = ga4_tracking
10
11
  end
11
12
 
12
13
  def breadcrumbs
@@ -37,7 +38,7 @@ module GovukPublishingComponents
37
38
  elsif navigation.content_tagged_to_current_step_by_step?
38
39
  {
39
40
  step_by_step: true,
40
- breadcrumbs: navigation.step_nav_helper.header,
41
+ breadcrumbs: navigation.step_nav_helper.header(@ga4_tracking),
41
42
  }
42
43
  elsif navigation.content_is_tagged_to_a_live_taxon? && prioritise_taxon_breadcrumbs
43
44
  {
@@ -61,7 +61,9 @@ module GovukPublishingComponents
61
61
  ga4_link: {
62
62
  event_name: "navigation",
63
63
  type: "breadcrumbs",
64
- index: index.to_s,
64
+ index: {
65
+ index_link: index.to_s,
66
+ },
65
67
  index_total: breadcrumbs_length.to_s,
66
68
  },
67
69
  }
@@ -82,12 +82,13 @@ module GovukPublishingComponents
82
82
  end
83
83
  end
84
84
 
85
- def header
85
+ def header(ga4_tracking)
86
86
  if show_header?
87
87
  {
88
88
  title: current_step_nav.title,
89
89
  path: current_step_nav.base_path,
90
90
  tracking_id: current_step_nav.content_id,
91
+ ga4_tracking: ga4_tracking,
91
92
  }
92
93
  else
93
94
  {}
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "34.13.0".freeze
2
+ VERSION = "34.14.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.13.0
4
+ version: 34.14.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-28 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config