govuk_publishing_components 35.13.2 → 35.14.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: d89a426d686fe0891582f8851ff7b27c57a457b838dccd81aa07a4868a9a9975
4
- data.tar.gz: b267048c6e6bd91689fcedbad4e16835de62ff50aee68e94684ec4533ad7c5ab
3
+ metadata.gz: cbe4c3f60d3220a9d2b715392ba0bdd2f6bce4f92153fff876e8a0b608361161
4
+ data.tar.gz: 94bd59d7a23b8e3cec4882814d7fb0140f81f0bd53bc23f0e475700ba8c489f8
5
5
  SHA512:
6
- metadata.gz: 9dcd81b321da508d0475825320afa9674bfbac1bf1ef73f5ce32ccd66d0f5225e08b569a9819ca34672c13e919e154e02570b51109613e53d9bc79945a0f3482
7
- data.tar.gz: 24bf0744fc140a4644c5b12d0de816869298a1927a25e3b1e126d0644b4bae78cd6ae5409d194e48465429e049517440321d39b12edd1ee783e717f54446659f
6
+ metadata.gz: 47f46ab14ccabebf2a3a3c0da9bc03f9b8207d1e54b6a0c4eb8830eb87b5ce200dd606fd2de50c3804d61f222518c560b046ff77b0de87e635a84a653d77d758
7
+ data.tar.gz: c51c0a0407bfa84b24ba4d5dfb281f9c31657f1b18e5afe687198c401dbb0f05dc795d7c27ecdf9fbbfe8413cc82a18f28016d77f3d4248351780e0731a61e55
@@ -169,10 +169,10 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
169
169
  removeCrossDomainParams: function (href) {
170
170
  if (href.indexOf('_ga') !== -1 || href.indexOf('_gl') !== -1) {
171
171
  // _ga & _gl are values needed for cross domain tracking, but we don't want them included in our click tracking.
172
- href = href.replaceAll(/_g[al]=([^&]*)/g, '')
172
+ href = href.replace(/_g[al]=([^&]*)/g, '')
173
173
 
174
174
  // The following code cleans up inconsistencies such as gov.uk/&&, gov.uk/?&hello=world, gov.uk/?, and gov.uk/&.
175
- href = href.replaceAll(/(&&)+/g, '&')
175
+ href = href.replace(/(&&)+/g, '&')
176
176
  href = href.replace('?&', '?')
177
177
  if (this.stringEndsWith(href, '?') || this.stringEndsWith(href, '&')) {
178
178
  href = href.substring(0, href.length - 1)
@@ -53,7 +53,9 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
53
53
  /* The existence of a referrer parameter indicates that the page has been dynamically updated via an AJAX request
54
54
  and therefore we can use it to set the dynamic property appropriately. This value is used by PA's to differentiate
55
55
  between fresh page loads and dynamic page updates. */
56
- dynamic: referrer ? 'true' : 'false'
56
+ dynamic: referrer ? 'true' : 'false',
57
+ emergency_banner: document.querySelector('[data-ga4-emergency-banner]') ? 'true' : undefined,
58
+ phase_banner: this.getElementAttribute('data-ga4-phase-banner') || undefined
57
59
  }
58
60
  }
59
61
  window.GOVUK.analyticsGa4.core.sendData(data)
@@ -91,6 +93,13 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
91
93
  }
92
94
  },
93
95
 
96
+ getElementAttribute: function (attributeName) {
97
+ var el = document.querySelector('[' + attributeName + ']')
98
+ if (el) {
99
+ return el.getAttribute(attributeName)
100
+ }
101
+ },
102
+
94
103
  getLanguage: function () {
95
104
  var content = document.getElementById('content')
96
105
  if (content) {
@@ -11,6 +11,7 @@
11
11
 
12
12
  container_class_names = %w[gem-c-attachment govuk-!-display-none-print]
13
13
  container_class_names << shared_helper.get_margin_bottom if local_assigns.key?(:margin_bottom)
14
+ ga4_link = { 'event_name': 'navigation', 'type': 'attachment' }
14
15
 
15
16
  case attachment.type
16
17
  when "file"
@@ -38,6 +39,9 @@
38
39
  class: "gem-c-attachment__attribute",
39
40
  )
40
41
  end
42
+
43
+ ga4_link[:event_name] = 'file_download'
44
+
41
45
  when "html"
42
46
  attributes << tag.span(
43
47
  "HTML",
@@ -51,7 +55,7 @@
51
55
  end
52
56
 
53
57
  %>
54
- <%= tag.section class: class_names(container_class_names), data: { module: "ga4-link-tracker", ga4_track_links_only: "", ga4_link: { 'event_name': 'navigation', 'type': 'attachment' } } do %>
58
+ <%= tag.section class: class_names(container_class_names), data: { module: "ga4-link-tracker", ga4_track_links_only: "", ga4_link: ga4_link } do %>
55
59
  <%= tag.div class: "gem-c-attachment__thumbnail" do %>
56
60
  <%= link_to attachment.url,
57
61
  class: "govuk-link",
@@ -7,6 +7,7 @@
7
7
  link_text ||= "More information"
8
8
  campaign_class ||= nil
9
9
  homepage ||= false
10
+ ga4_tracking ||= false
10
11
 
11
12
  emergency_banner_helper = GovukPublishingComponents::Presenters::EmergencyBannerHelper.new()
12
13
 
@@ -28,9 +29,25 @@
28
29
  description_classes = %w[gem-c-emergency-banner__description]
29
30
  description_classes << "gem-c-emergency-banner__description--homepage" if homepage
30
31
 
32
+
33
+ data_attributes = {
34
+ "nosnippet": true,
35
+ }
36
+
37
+ if ga4_tracking
38
+ data_attributes[:ga4_emergency_banner] = ""
39
+ data_attributes[:module] = "ga4-link-tracker"
40
+ data_attributes[:ga4_track_links_only] = ""
41
+ data_attributes[:ga4_set_indexes] = ""
42
+ data_attributes[:ga4_link] = {
43
+ event_name: "navigation",
44
+ type: "emergency banner",
45
+ section: heading,
46
+ }.to_json
47
+ end
31
48
  %>
32
49
 
33
- <%= content_tag('section', class: banner_classes, "aria-labelledby": "emergency-banner-heading", "data-nosnippet": true ) do %>
50
+ <%= content_tag('section', class: banner_classes, "aria-labelledby": "emergency-banner-heading", data: data_attributes) do %>
34
51
  <div class="govuk-width-container">
35
52
  <div class="govuk-grid-row">
36
53
  <div class="govuk-grid-column-two-thirds">
@@ -5,6 +5,7 @@ app_name ||= nil
5
5
  phase ||= nil
6
6
  message ||= nil
7
7
  inverse ||= false
8
+ ga4_tracking ||= false
8
9
 
9
10
  unless message.present?
10
11
  if phase == "beta"
@@ -16,9 +17,24 @@ end
16
17
 
17
18
  container_css_classes = %w(gem-c-phase-banner govuk-phase-banner)
18
19
  container_css_classes << "gem-c-phase-banner--inverse" if inverse
20
+
21
+ data_attributes = {}
22
+
23
+ if ga4_tracking
24
+ data_attributes[:ga4_phase_banner] = phase
25
+ data_attributes[:module] = "ga4-link-tracker"
26
+ data_attributes[:ga4_track_links_only] = ""
27
+ data_attributes[:ga4_set_indexes] = ""
28
+ data_attributes[:ga4_link] = {
29
+ event_name: "navigation",
30
+ type: "phase banner",
31
+ section: Nokogiri::HTML(message).text,
32
+ }.to_json
33
+ end
34
+
19
35
  %>
20
36
 
21
- <%= tag.div class: container_css_classes do %>
37
+ <%= tag.div class: container_css_classes, data: data_attributes do %>
22
38
  <%= tag.p class: "govuk-phase-banner__content" do %>
23
39
  <%= tag.strong app_name, class: "govuk-phase-banner__content__app-name" if app_name %>
24
40
  <%= tag.strong phase, class: "govuk-tag govuk-phase-banner__content__tag" if phase %>
@@ -45,3 +45,13 @@ examples:
45
45
  short_description: "1491 to 1547"
46
46
  link: "https://www.gov.uk/"
47
47
  homepage: true
48
+ with_ga4_tracking:
49
+ description: |
50
+ Enables GA4 tracking on the banner. This includes link tracking on the component itself, and allows pageviews to record the presence of the banner on page load.
51
+ data:
52
+ campaign_class: "notable-death"
53
+ heading: "His Royal Highness Henry VIII"
54
+ short_description: "1491 to 1547"
55
+ link: "https://www.gov.uk/"
56
+ homepage: true
57
+ ga4_tracking: true
@@ -32,3 +32,11 @@ examples:
32
32
  app_name: Skittles Maker
33
33
  phase: beta
34
34
  inverse: true
35
+ with_ga4_tracking:
36
+ description: |
37
+ Enables GA4 tracking on the banner. This includes link tracking on the component itself, and allows pageviews to record the presence of the banner on page load.
38
+ data:
39
+ app_name: Skittles Maker
40
+ phase: beta
41
+ inverse: true
42
+ ga4_tracking: true
@@ -6,7 +6,7 @@
6
6
  <% else %>
7
7
  <%= render "govuk_publishing_components/components/layout_header", {
8
8
  environment: GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment,
9
- product_name: GovukPublishingComponents::Config.component_guide_title,
9
+ product_name: "#{GovukPublishingComponents::Config.component_guide_title} #{GovukPublishingComponents::VERSION}",
10
10
  href: component_guide_path
11
11
  } %>
12
12
  <div class="govuk-width-container app-width-container--wide">
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "35.13.2".freeze
2
+ VERSION = "35.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: 35.13.2
4
+ version: 35.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-08-15 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config