govuk_publishing_components 37.8.1 → 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: 5689381c1b91fcd27eda4f683bd3787378cd1e1c13747ac62934454a46217317
4
- data.tar.gz: abbe0c8a389cfa3b9b6081ceeb0852399a980406d4dc3a19d2ab983a1c16cfd4
3
+ metadata.gz: c5dd2b5e600cf344b23c52992b273a3af2ea102506584e06dfb001aa810e0491
4
+ data.tar.gz: 459ba0f50e42851c6ea04b0490aba7714cb221fb6b97e735cb48f4548f1e8237
5
5
  SHA512:
6
- metadata.gz: ae4406bbc724801473b8bdceda5e009cc12042766a3960f70b0bceeb3369488c3e027e9379d1a6508787de3a75d23789987b4b4eb475823858e92aa45cf545b0
7
- data.tar.gz: 07c97f13633569bf66540ee250f06ebf0fa32fbaa7e6cf904f2e78e521eece57fe2aa3763e5adf0f8fd3e41bf4cdb7113ed90364e0d426561a8d50491fc8ebcd
6
+ metadata.gz: 0dd79b5496db1fe55d085e18476983bcaf5abefa630e44544acfe795f40c68c3529556a8dcb02d8f0b25695bb4c0db223fb0e0038cfc6cdc1389db5fe48c86a2
7
+ data.tar.gz: e54878f904583f718889acc341ea00f8a7281f82783bb8141e358c29068c63c67f3c96dbd04820c5d09562cfe2aa31cb6b3008f3897ef7e113cefd792675ae62
@@ -0,0 +1,61 @@
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
+
4
+ (function (Modules) {
5
+ 'use strict'
6
+
7
+ function Ga4FocusLossTracker (module) {
8
+ this.module = module
9
+ this.trackingTrigger = 'data-ga4-focus-loss' // elements with this attribute get tracked
10
+ }
11
+
12
+ Ga4FocusLossTracker.prototype.init = function () {
13
+ var consentCookie = window.GOVUK.getConsentCookie()
14
+
15
+ if (consentCookie && consentCookie.usage) {
16
+ this.startModule()
17
+ } else {
18
+ this.start = this.startModule.bind(this)
19
+ window.addEventListener('cookie-consent', this.start)
20
+ }
21
+ }
22
+
23
+ // triggered by cookie-consent event, which happens when users consent to cookies
24
+ Ga4FocusLossTracker.prototype.startModule = function () {
25
+ if (window.dataLayer) {
26
+ window.removeEventListener('cookie-consent', this.start)
27
+ this.module.addEventListener('blur', this.trackFocusLoss.bind(this))
28
+ this.module.piiRemover = new window.GOVUK.analyticsGa4.PIIRemover()
29
+ }
30
+ }
31
+
32
+ Ga4FocusLossTracker.prototype.trackFocusLoss = function (event) {
33
+ var data = event.target.getAttribute(this.trackingTrigger)
34
+ if (!data) {
35
+ return
36
+ }
37
+
38
+ try {
39
+ data = JSON.parse(data)
40
+ } catch (e) {
41
+ // if there's a problem with the config, don't start the tracker
42
+ console.warn('GA4 configuration error: ' + e.message, window.location)
43
+ return
44
+ }
45
+
46
+ var tagName = event.target.tagName
47
+ var inputType = event.target.getAttribute('type')
48
+
49
+ if (data.text) {
50
+ data.text = this.module.piiRemover.stripPIIWithOverride(data.text, true, true)
51
+ } else {
52
+ if (tagName === 'INPUT' && (inputType === 'search' || inputType === 'text')) {
53
+ data.text = window.GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(this.module.value)
54
+ }
55
+ }
56
+
57
+ window.GOVUK.analyticsGa4.core.applySchemaAndSendData(data, 'event_data')
58
+ }
59
+
60
+ Modules.Ga4FocusLossTracker = Ga4FocusLossTracker
61
+ })(window.GOVUK.Modules)
@@ -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
 
@@ -14,4 +14,5 @@
14
14
  //= require ./analytics-ga4/ga4-smart-answer-results-tracker
15
15
  //= require ./analytics-ga4/ga4-scroll-tracker
16
16
  //= require ./analytics-ga4/ga4-video-tracker
17
+ //= require ./analytics-ga4/ga4-focus-loss-tracker
17
18
  //= require ./analytics-ga4/init-ga4
@@ -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 %>">
@@ -50,7 +50,7 @@
50
50
  <svg version="1.1" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="0" height="0" class="gem-c-option-select__icon gem-c-option-select__icon--down" aria-hidden="true" focusable="false"><path d="m225.84 414.16l256 256c16.683 16.683 43.691 16.683 60.331 0l256-256c16.683-16.683 16.683-43.691 0-60.331s-43.691-16.683-60.331 0l-225.84 225.84-225.84-225.84c-16.683-16.683-43.691-16.683-60.331 0s-16.683 43.691 0 60.331z"/></svg>
51
51
  </h3>
52
52
 
53
- <%= content_tag(:div, role: "group", aria: { labelledby: title_id }, class: options_container_classes, id: options_container_id, tabindex: "-1") do %>
53
+ <%= content_tag(:div, class: options_container_classes, id: options_container_id, tabindex: "-1") do %>
54
54
  <div class="gem-c-option-select__container-inner js-auto-height-inner">
55
55
  <% if show_filter %>
56
56
  <span id="<%= checkboxes_count_id %>"
@@ -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.8.1".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.8.1
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-15 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
@@ -456,6 +456,7 @@ files:
456
456
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
457
457
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js
458
458
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
459
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-focus-loss-tracker.js
459
460
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-form-tracker.js
460
461
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js
461
462
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js