govuk_publishing_components 37.9.0 → 37.9.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: 620e260c7be413ed137d8e74b40dc48c19319aec32a0a7d19cc595ac63f88ace
4
- data.tar.gz: aa8cc4913d9db8852e43c7eb3e47f43716b749c640ba31b4004ad60f78c88ea2
3
+ metadata.gz: c5dd2b5e600cf344b23c52992b273a3af2ea102506584e06dfb001aa810e0491
4
+ data.tar.gz: 459ba0f50e42851c6ea04b0490aba7714cb221fb6b97e735cb48f4548f1e8237
5
5
  SHA512:
6
- metadata.gz: de3cdf70234ce290d51b5132f6cde36fc6c43f5c2281fc5f094a468ee5b496bbc49325e4633ff01836bcafa4c6e4ac30af496e40034c50dd2e6da27b847ed2f1
7
- data.tar.gz: 56b4d106d440fbc30dd4ad64108cc9f3dbdba4c65a23a37df3147e80e8703ccc3e91349cfe65d7ee484068abe0ee07366ea8a1abc742798f19c68d5877c02513
6
+ metadata.gz: 0dd79b5496db1fe55d085e18476983bcaf5abefa630e44544acfe795f40c68c3529556a8dcb02d8f0b25695bb4c0db223fb0e0038cfc6cdc1389db5fe48c86a2
7
+ data.tar.gz: e54878f904583f718889acc341ea00f8a7281f82783bb8141e358c29068c63c67f3c96dbd04820c5d09562cfe2aa31cb6b3008f3897ef7e113cefd792675ae62
@@ -72,7 +72,22 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
72
72
  if (!href) {
73
73
  return
74
74
  }
75
+
75
76
  var data = {}
77
+ var extraAttributes = element.getAttribute('data-ga4-attributes')
78
+ if (extraAttributes) {
79
+ try {
80
+ extraAttributes = JSON.parse(extraAttributes)
81
+ // make sure the data object remains an object - JSON.parse can return a string
82
+ for (var attrname in extraAttributes) {
83
+ data[attrname] = extraAttributes[attrname]
84
+ }
85
+ } catch (e) {
86
+ // fall back to the empty data object if something goes wrong
87
+ console.error('GA4 configuration error: ' + e.message, window.location)
88
+ }
89
+ }
90
+
76
91
  var mailToLink = false
77
92
  if (window.GOVUK.analyticsGa4.core.trackFunctions.isMailToLink(href)) {
78
93
  data.event_name = 'navigation'
@@ -85,7 +100,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
85
100
  data.external = window.GOVUK.analyticsGa4.core.trackFunctions.isExternalLink(href) ? 'true' : 'false'
86
101
  } else if (window.GOVUK.analyticsGa4.core.trackFunctions.isExternalLink(href)) {
87
102
  data.event_name = 'navigation'
88
- data.type = 'generic link'
103
+ data.type = data.type || 'generic link'
89
104
  data.external = 'true'
90
105
  }
91
106
 
@@ -1,5 +1,6 @@
1
1
  <%
2
2
  add_gem_component_stylesheet("button")
3
+ disable_ga4 ||= false
3
4
 
4
5
  # button_helper.css_classes generates "gem-c-button"
5
6
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
@@ -5,11 +5,13 @@
5
5
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
6
6
  items ||= []
7
7
 
8
- classes = %w[gem-c-document-list]
9
- classes << "gem-c-document-list--no-underline" if local_assigns[:remove_underline]
10
- classes << "gem-c-document-list--no-top-border" if local_assigns[:remove_top_border]
11
- classes << "gem-c-document-list--no-top-border-first-child" if local_assigns[:remove_top_border_from_first_child]
12
- classes << shared_helper.get_margin_bottom
8
+ component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
9
+ component_helper.add_class("gem-c-document-list")
10
+ component_helper.add_class("gem-c-document-list--no-underline") if local_assigns[:remove_underline]
11
+ component_helper.add_class("gem-c-document-list--no-top-border") if local_assigns[:remove_top_border]
12
+ component_helper.add_class("gem-c-document-list--no-top-border-first-child") if local_assigns[:remove_top_border_from_first_child]
13
+ component_helper.add_class(shared_helper.get_margin_bottom)
14
+
13
15
 
14
16
  title_with_context_class = " gem-c-document-list__item-title--context"
15
17
 
@@ -19,18 +21,18 @@
19
21
  disable_ga4 ||= false
20
22
  unless disable_ga4
21
23
  ga4_extra_data ||= {}
22
- ga4_ul_attributes = {
24
+ component_helper.add_data_attribute({
23
25
  module: "ga4-link-tracker",
24
26
  ga4_track_links_only: "",
25
27
  ga4_link: {
26
28
  "event_name": "navigation",
27
29
  "type": "document list",
28
30
  }.merge(ga4_extra_data)
29
- }
31
+ })
30
32
  end
31
33
  %>
32
34
  <% if items.any? %>
33
- <%= tag.ul(class: classes.join(" "), data: ga4_ul_attributes) do %>
35
+ <%= tag.ul(**component_helper.all_attributes) do %>
34
36
  <% items.each do |item| %>
35
37
  <% highlight_class = " gem-c-document-list__item--highlight" if item[:highlight] %>
36
38
  <li class="gem-c-document-list__item <%= brand_helper.brand_class %> <%= highlight_class %>">
@@ -44,6 +44,14 @@ examples:
44
44
  href: '#'
45
45
  start: true
46
46
  rel: external
47
+ start_now_button_without_ga4_attributes:
48
+ description: By default the start now button version of this component includes a `data-ga4-attributes` attribute that is used by the specialist (external) link tracker to uniquely identify start now buttons. This attribute can be removed using the `disable_ga4` option.
49
+ data:
50
+ text: Start now
51
+ disable_ga4: true
52
+ href: '#'
53
+ start: true
54
+ rel: external
47
55
  secondary_button:
48
56
  data:
49
57
  text: Secondary button
@@ -15,6 +15,7 @@ accessibility_criteria: |
15
15
  * inform the user how many items are in the list
16
16
  shared_accessibility_criteria:
17
17
  - link
18
+ uses_component_wrapper_helper: true
18
19
  examples:
19
20
  default:
20
21
  data:
@@ -28,6 +28,7 @@ module GovukPublishingComponents
28
28
  :aria_describedby
29
29
 
30
30
  def initialize(local_assigns)
31
+ @disable_ga4 = local_assigns[:disable_ga4]
31
32
  @href = local_assigns[:href]
32
33
  @text = local_assigns[:text]
33
34
  @title = local_assigns[:title]
@@ -45,6 +46,7 @@ module GovukPublishingComponents
45
46
  @target = local_assigns[:target]
46
47
  @type = local_assigns[:type]
47
48
  @start = local_assigns[:start]
49
+ @data_attributes[:ga4_attributes] = ga4_attribute if start
48
50
  @secondary = local_assigns[:secondary]
49
51
  @secondary_quiet = local_assigns[:secondary_quiet]
50
52
  @secondary_solid = local_assigns[:secondary_solid]
@@ -129,6 +131,10 @@ module GovukPublishingComponents
129
131
 
130
132
  [*0..9].include?(margin) ? "govuk-!-margin-bottom-#{margin}" : legacy_class
131
133
  end
134
+
135
+ def ga4_attribute
136
+ { type: "start button" }.to_json unless @disable_ga4
137
+ end
132
138
  end
133
139
  end
134
140
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.9.0".freeze
2
+ VERSION = "37.9.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: 37.9.0
4
+ version: 37.9.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: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config