govuk_publishing_components 37.9.0 → 37.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +2 -1
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +16 -1
  4. data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +3 -3
  5. data/app/views/govuk_publishing_components/components/_button.html.erb +1 -0
  6. data/app/views/govuk_publishing_components/components/_document_list.html.erb +10 -8
  7. data/app/views/govuk_publishing_components/components/_govspeak.html.erb +0 -11
  8. data/app/views/govuk_publishing_components/components/_notice.html.erb +1 -14
  9. data/app/views/govuk_publishing_components/components/_warning_text.html.erb +1 -10
  10. data/app/views/govuk_publishing_components/components/docs/button.yml +8 -0
  11. data/app/views/govuk_publishing_components/components/docs/document_list.yml +1 -0
  12. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +0 -9
  13. data/app/views/govuk_publishing_components/components/docs/notice.yml +0 -10
  14. data/app/views/govuk_publishing_components/components/docs/warning_text.yml +0 -7
  15. data/lib/govuk_publishing_components/presenters/breadcrumb_selector.rb +0 -5
  16. data/lib/govuk_publishing_components/presenters/button_helper.rb +6 -0
  17. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +0 -8
  18. data/lib/govuk_publishing_components/version.rb +1 -1
  19. data/lib/govuk_publishing_components.rb +0 -1
  20. metadata +3 -4
  21. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 620e260c7be413ed137d8e74b40dc48c19319aec32a0a7d19cc595ac63f88ace
4
- data.tar.gz: aa8cc4913d9db8852e43c7eb3e47f43716b749c640ba31b4004ad60f78c88ea2
3
+ metadata.gz: 88e7235efad66b3b4e58b76104ee17ffd0df45709e3a0ead2d21b3349af45514
4
+ data.tar.gz: 70a11adff6bea43df88c5b10bf9d0ab0934510d8a57ec7f621c50e0006e689a6
5
5
  SHA512:
6
- metadata.gz: de3cdf70234ce290d51b5132f6cde36fc6c43f5c2281fc5f094a468ee5b496bbc49325e4633ff01836bcafa4c6e4ac30af496e40034c50dd2e6da27b847ed2f1
7
- data.tar.gz: 56b4d106d440fbc30dd4ad64108cc9f3dbdba4c65a23a37df3147e80e8703ccc3e91349cfe65d7ee484068abe0ee07366ea8a1abc742798f19c68d5877c02513
6
+ metadata.gz: 750feab9da7c02d5fd72d55e9b40a027d02000656a987316974a282dc4357832a3600670826b9a80dac4c64a087f18acc97eacab3573879e3ba46148f5b5bf08
7
+ data.tar.gz: db8c5538ef83cb50bcf37e11e6e5693a8995da9a2deda172dfc9591eb10a1d77c5ed54b65ecf62fab5d4233146a201556f1eb9280a37a9be693e30a94ca44297
@@ -62,7 +62,8 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
62
62
  intervention: this.getBannerPresence('[data-ga4-intervention-banner]'),
63
63
  query_string: this.getQueryString(),
64
64
  search_term: this.getSearchTerm(),
65
- spelling_suggestion: this.getMetaContent('spelling-suggestion')
65
+ spelling_suggestion: this.getMetaContent('spelling-suggestion'),
66
+ discovery_engine_attribution_token: this.getMetaContent('discovery-engine-attribution-token')
66
67
  }
67
68
  }
68
69
  window.GOVUK.analyticsGa4.core.sendData(data)
@@ -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
 
@@ -134,8 +134,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
134
134
  var $navMenuLinks = this.$navMenu.querySelectorAll('li a')
135
135
  var $firstNavLink = $navMenuLinks[0]
136
136
  var $lastNavLink = $navMenuLinks[$navMenuLinks.length - 1]
137
- var $searchMenuLinks = this.$searchMenu.querySelectorAll('li a')
138
- var $lastSearchLink = $searchMenuLinks[$searchMenuLinks.length - 1]
137
+ var $searchMenuTabbable = this.$searchMenu.querySelectorAll('li a, input, button')
138
+ var $lastSearchMenuTabbable = $searchMenuTabbable[$searchMenuTabbable.length - 1]
139
139
 
140
140
  if (event.keyCode === KEY_TAB) {
141
141
  if (!this.$navMenu.hasAttribute('hidden')) {
@@ -169,7 +169,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
169
169
  break
170
170
  }
171
171
  } else if (!this.$searchMenu.hasAttribute('hidden')) {
172
- if (document.activeElement === $lastSearchLink) {
172
+ if (document.activeElement === $lastSearchMenuTabbable) {
173
173
  if (!event.shiftKey) {
174
174
  hide(this.$searchToggle, this.$searchMenu)
175
175
  }
@@ -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 %>">
@@ -10,20 +10,9 @@
10
10
  classes << "disable-youtube" if disable_youtube_expansions
11
11
  classes << "gem-c-govspeak--inverse" if inverse
12
12
 
13
- disable_ga4 ||= false
14
-
15
13
  data_modules = "govspeak"
16
- data_modules << " ga4-link-tracker" unless disable_ga4
17
14
  data_attributes = { module: data_modules }
18
15
 
19
- unless disable_ga4
20
- data_attributes.merge!({
21
- ga4_track_links_only: "",
22
- ga4_limit_to_element_class: "call-to-action, info-notice, help-notice, advisory",
23
- ga4_link: { "event_name": "navigation", "type": "callout" }.to_json,
24
- })
25
- end
26
-
27
16
  %>
28
17
 
29
18
  <%= tag.div(class: "gem-c-govspeak govuk-govspeak " + classes.join(" "), data: data_attributes) do %>
@@ -25,28 +25,15 @@
25
25
  aria_attributes[:labelledby] = banner_title_id if show_banner_title
26
26
 
27
27
  description_present = description.present? || description_text.present? || description_govspeak.present?
28
- disable_ga4 ||= false
29
28
 
30
29
  if description_govspeak
31
30
  govspeak_data_attributes = {
32
31
  content: description_govspeak,
33
- disable_ga4: true # Keep the govspeak component GA4 tracking disabled, otherwise tracking will be duplicated when tracking is enabled on this component.
34
- }
35
- end
36
-
37
- unless disable_ga4
38
- section_data_attributes = {
39
- module: "ga4-link-tracker",
40
- ga4_track_links_only: "",
41
- ga4_link: {
42
- event_name: "navigation",
43
- type: "callout"
44
- }.to_json
45
32
  }
46
33
  end
47
34
  %>
48
35
  <% if title || description_present %>
49
- <%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region", data: section_data_attributes do %>
36
+ <%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region" do %>
50
37
  <%= tag.div class: "govuk-notification-banner__header" do %>
51
38
  <%= tag.h2 banner_title, class: "govuk-notification-banner__title", id: banner_title_id %>
52
39
  <% end if show_banner_title %>
@@ -14,18 +14,9 @@
14
14
  text_classes << "gem-c-warning-text__text--no-indent" if text_icon.empty?
15
15
  text_classes << "gem-c-warning-text__text--large" if large_font
16
16
  text_classes << "gem-c-warning-text__text--highlight" if highlight_text
17
-
18
- disable_ga4 ||= false
19
-
20
- ga4_data_attributes = {
21
- "module": "ga4-link-tracker",
22
- "ga4-track-links-only": "",
23
- "ga4-link": { "event_name": "navigation", "type": "callout" }.to_json
24
- } unless disable_ga4
25
-
26
17
  %>
27
18
 
28
- <%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text", data: ga4_data_attributes do %>
19
+ <%= tag.div id: id, class: "gem-c-warning-text govuk-warning-text" do %>
29
20
  <% unless text_icon.empty? %>
30
21
  <%= tag.span text_icon, class: "govuk-warning-text__icon", "aria-hidden": "true" %>
31
22
  <% end %>
@@ -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:
@@ -914,12 +914,3 @@ examples:
914
914
  <p>Deforested area. Credit: Blue Ventures-Garth Cripps</p>
915
915
  </figcaption>
916
916
  </figure>
917
- without_ga4_tracking:
918
- description: |
919
- Disables GA4 tracking on the component. Tracking is enabled by default. This adds a data module and data-attributes with JSON data. See the [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
920
- data:
921
- block: |
922
- <p>
923
- <a href='https://www.gov.uk'>Hello World</a>
924
- </p>
925
- disable_ga4: true
@@ -65,13 +65,3 @@ examples:
65
65
  description_govspeak: <p>This document is no longer current. We published a new version on 30 September 2015.</p>
66
66
  show_banner_title: true
67
67
  banner_title: "Information"
68
- with_ga4_tracking_disabled:
69
- description: |
70
- Disables GA4 tracking on the component. Tracking on the component is enabled by default. Tracking on the nested govspeak component is always disabled to prevent duplication. When tracking is enabled on this component, a data module and data attributes are added to the parent element. See the [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
71
- data:
72
- disable_ga4: true
73
- title: 'This publication was withdrawn on 30 September 2015'
74
- description_govspeak: <p>This document is no longer current. We published a new version on 30 September 2015.</p>
75
- show_banner_title: true
76
- banner_title: "Information"
77
-
@@ -33,10 +33,3 @@ examples:
33
33
  data:
34
34
  text: "This is a heading 3"
35
35
  heading_level: 3
36
- without_ga4_tracking:
37
- description: |
38
- Disables GA4 tracking on warning text links. Tracking is enabled by default, which adds a data module and data attributes to the component. See the [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
39
- data:
40
- disable_ga4: true
41
- text: "This is a heading 3"
42
- heading_level: 3
@@ -55,11 +55,6 @@ module GovukPublishingComponents
55
55
  step_by_step: false,
56
56
  breadcrumbs: navigation.breadcrumbs,
57
57
  }
58
- elsif navigation.content_has_a_topic?
59
- {
60
- step_by_step: false,
61
- breadcrumbs: navigation.topic_breadcrumbs,
62
- }
63
58
  elsif navigation.use_taxon_breadcrumbs?
64
59
  {
65
60
  step_by_step: false,
@@ -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
@@ -33,10 +33,6 @@ module GovukPublishingComponents
33
33
  @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.call(content_item)
34
34
  end
35
35
 
36
- def topic_breadcrumbs
37
- @topic_breadcrumbs ||= ContentBreadcrumbsBasedOnTopic.call(content_item)
38
- end
39
-
40
36
  def breadcrumbs
41
37
  breadcrumbs_based_on_ancestors
42
38
  end
@@ -88,10 +84,6 @@ module GovukPublishingComponents
88
84
  content_item["document_type"] == "html_publication"
89
85
  end
90
86
 
91
- def content_has_a_topic?
92
- content_item.dig("links", "topics").present?
93
- end
94
-
95
87
  def content_tagged_to_current_step_by_step?
96
88
  # TODO: remove indirection here
97
89
  step_nav_helper.show_header?
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.9.0".freeze
2
+ VERSION = "37.10.0".freeze
3
3
  end
@@ -24,7 +24,6 @@ require "govuk_publishing_components/presenters/page_with_step_by_step_navigatio
24
24
  require "govuk_publishing_components/presenters/public_layout_helper"
25
25
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors"
26
26
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
27
- require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic"
28
27
  require "govuk_publishing_components/presenters/checkboxes_helper"
29
28
  require "govuk_publishing_components/presenters/select_helper"
30
29
  require "govuk_publishing_components/presenters/meta_tags"
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.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: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -957,7 +957,6 @@ files:
957
957
  - lib/govuk_publishing_components/presenters/component_wrapper_helper.rb
958
958
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors.rb
959
959
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
960
- - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
961
960
  - lib/govuk_publishing_components/presenters/content_item.rb
962
961
  - lib/govuk_publishing_components/presenters/contents_list_helper.rb
963
962
  - lib/govuk_publishing_components/presenters/contextual_navigation.rb
@@ -1640,7 +1639,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1640
1639
  - !ruby/object:Gem::Version
1641
1640
  version: '0'
1642
1641
  requirements: []
1643
- rubygems_version: 3.5.6
1642
+ rubygems_version: 3.5.7
1644
1643
  signing_key:
1645
1644
  specification_version: 4
1646
1645
  summary: A gem to document components in GOV.UK frontend applications
@@ -1,38 +0,0 @@
1
- module GovukPublishingComponents
2
- module Presenters
3
- class ContentBreadcrumbsBasedOnTopic
4
- def self.call(content_item)
5
- new(content_item).breadcrumbs
6
- end
7
-
8
- attr_reader :content_item
9
-
10
- def initialize(content_item)
11
- @content_item = content_item
12
- end
13
-
14
- def breadcrumbs
15
- breadcrumbs = [{ title: "Home", url: "/" }]
16
- return breadcrumbs unless topics.present?
17
-
18
- breadcrumbs << topic_breadcrumb
19
- breadcrumbs
20
- end
21
-
22
- def topic_breadcrumb
23
- {
24
- title: first_topic["title"],
25
- url: first_topic["base_path"],
26
- }
27
- end
28
-
29
- def first_topic
30
- topics.first
31
- end
32
-
33
- def topics
34
- @topics ||= content_item.dig("links", "topics")
35
- end
36
- end
37
- end
38
- end