govuk_publishing_components 37.4.0 → 37.5.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: 81dc4d3b658e38f0d167a46180539b5f0f1178f33635d9d9472f3884d8d33355
4
- data.tar.gz: 597a4200b06d9c332799947eda6edd505efc78b86e4c892d93ca0a86842fea05
3
+ metadata.gz: 9ae79b74c7f168d201da93dd67100925c6e89c34ea187b924fd9a4b93abc6b28
4
+ data.tar.gz: a0386e47e87e26590be08d1671be29add20066d965d1998b370ab26dd21d629e
5
5
  SHA512:
6
- metadata.gz: 8705485b6efeafbf3ff6803e9199268281c11ba853fbfb5fa3819a13500f41aa3848aeea462ed221dc1df59c3c1657a15a03c01b04d13431c6debd773fc3d2d9
7
- data.tar.gz: e5486f71d07feba017108aaf9da158a00f9b5f3110f8f7c123fbcf17bd3d7c48ba70e8eb5e675bdb830d34acd77bfc287cb0c4a9517d63a2621e16f430012f2a
6
+ metadata.gz: fb9f0fe2fce0cfbce193404c2e0f8a1e7842fdb4d011e96c698c00a999c59d71518b94463ce1ae8369fbc60e72ba0f53d5c590cb947aba2d8d4eb8052d36752b
7
+ data.tar.gz: a3cd14147b0f1d842f8d8688f6d3dfdc0adbea71588406b3b80b0b97240452fcdf3a9c5a3c366bd59836d6cef5811d8af1410ed6d8cfbe592ad442315d13df81
@@ -32,7 +32,8 @@
32
32
  var remainingUtValues = utValues.slice(config.maxBeaconUTEntries);
33
33
  // Trim UT entries until they fit within the maximum URL length, ensuring at least one UT entry
34
34
  // is included.
35
- while ((url + "&UT=" + beaconUtValues.join(",")).length > config.maxBeaconUrlLength && beaconUtValues.length > 1) {
35
+ while ((url + "&UT=" + beaconUtValues.join(",")).length > config.maxBeaconUrlLength &&
36
+ beaconUtValues.length > 1) {
36
37
  remainingUtValues.unshift(beaconUtValues.pop());
37
38
  }
38
39
  return [beaconUtValues, remainingUtValues];
@@ -546,10 +547,10 @@
546
547
  // -------------------------------------------------------------------------
547
548
  /// End
548
549
  // -------------------------------------------------------------------------
549
- var SCRIPT_VERSION = "312";
550
+ var SCRIPT_VERSION = "313";
550
551
  var logger = new Logger();
551
552
  var globalConfig = fromObject(LUX);
552
- logger.logEvent(LogEvent.EvaluationStart, [SCRIPT_VERSION]);
553
+ logger.logEvent(LogEvent.EvaluationStart, [SCRIPT_VERSION, globalConfig]);
553
554
  // Variable aliases that allow the minifier to reduce file size.
554
555
  var document = window.document;
555
556
  var addEventListener = window.addEventListener;
@@ -650,7 +651,7 @@
650
651
  var gSessionTimeout = 30 * 60; // number of seconds after which we consider a session to have "timed out" (used for calculating bouncerate)
651
652
  var gSyncId = createSyncId(); // if we send multiple beacons, use this to sync them (eg, LUX & IX) (also called "luxid")
652
653
  var gUid = refreshUniqueId(gSyncId); // cookie for this session ("Unique ID")
653
- var gCustomerDataTimeout; // setTimeout timer for sending a Customer Data beacon after onload
654
+ var gCustomDataTimeout; // setTimeout timer for sending a Custom data beacon after onload
654
655
  var gMaxMeasureTimeout; // setTimeout timer for sending the beacon after a maximum measurement time
655
656
  var pageRestoreTime; // ms since navigationStart representing when the page was restored from the bfcache
656
657
  /**
@@ -1186,16 +1187,16 @@
1186
1187
  }
1187
1188
  if (gbLuxSent) {
1188
1189
  // This is special: We want to allow customers to call LUX.addData()
1189
- // _after_ window.onload. So we have to send a Customer Data beacon that
1190
- // includes the new customer data.
1190
+ // _after_ window.onload. So we have to send a Custom data beacon that
1191
+ // includes the new custom data.
1191
1192
  // Do setTimeout so that if there are multiple back-to-back addData calls
1192
1193
  // we get them all in one beacon.
1193
- if (gCustomerDataTimeout) {
1194
+ if (gCustomDataTimeout) {
1194
1195
  // Cancel the timer for any previous beacons so that if they have not
1195
1196
  // yet been sent we can combine all the data in a new beacon.
1196
- clearTimeout(gCustomerDataTimeout);
1197
+ clearTimeout(gCustomDataTimeout);
1197
1198
  }
1198
- gCustomerDataTimeout = setTimeout(_sendCustomerData, 100);
1199
+ gCustomDataTimeout = setTimeout(_sendCustomData, 100);
1199
1200
  }
1200
1201
  }
1201
1202
  // _sample()
@@ -1211,7 +1212,8 @@
1211
1212
  * Re-initialize lux.js to start a new "page". This is typically called within a SPA at the
1212
1213
  * beginning of a page transition, but is also called internally when the BF cache is restored.
1213
1214
  */
1214
- function _init(startTime) {
1215
+ function _init(startTime, clearFlags) {
1216
+ if (clearFlags === void 0) { clearFlags = true; }
1215
1217
  // Some customers (incorrectly) call LUX.init on the very first page load of a SPA. This would
1216
1218
  // cause some first-page-only data (like paint metrics) to be lost. To prevent this, we silently
1217
1219
  // bail from this function when we detect an unnecessary LUX.init call.
@@ -1245,8 +1247,10 @@
1245
1247
  nErrors = 0;
1246
1248
  gFirstInputDelay = undefined;
1247
1249
  // Clear flags then set the flag that init was called (ie, this is a SPA).
1248
- gFlags = 0;
1249
- gFlags = addFlag(gFlags, Flags.InitCalled);
1250
+ if (clearFlags) {
1251
+ gFlags = 0;
1252
+ gFlags = addFlag(gFlags, Flags.InitCalled);
1253
+ }
1250
1254
  // Reset the maximum measure timeout
1251
1255
  createMaxMeasureTimeout();
1252
1256
  }
@@ -1653,9 +1657,9 @@
1653
1657
  if (gFlags) {
1654
1658
  queryParams.push("fl=" + gFlags);
1655
1659
  }
1656
- var customerData = valuesToString(customData);
1657
- if (customerData) {
1658
- queryParams.push("CD=" + customerData);
1660
+ var customDataValues = valuesToString(customData);
1661
+ if (customDataValues) {
1662
+ queryParams.push("CD=" + customDataValues);
1659
1663
  clearUpdateCustomData();
1660
1664
  }
1661
1665
  return globalConfig.beaconUrl + "?" + queryParams.join("&");
@@ -1720,7 +1724,7 @@
1720
1724
  LUX.addData(conversion, BOOLEAN_TRUE);
1721
1725
  });
1722
1726
  }
1723
- // We want ALL beacons to have ALL the data used for query filters (geo, pagelabel, browser, & customerdata).
1727
+ // We want ALL beacons to have ALL the data used for query filters (geo, pagelabel, browser, & custom data).
1724
1728
  // So we create a base URL that has all the necessary information:
1725
1729
  var baseUrl = _getBeaconUrl(getAllCustomData());
1726
1730
  var is = inlineTagSize("script");
@@ -1819,9 +1823,9 @@
1819
1823
  gbIxSent = 1;
1820
1824
  }
1821
1825
  }
1822
- // Beacon back customer data that is recorded _after_ the main beacon was sent
1823
- // (i.e., customer data after window.onload).
1824
- function _sendCustomerData() {
1826
+ // Beacon back custom data that is recorded _after_ the main beacon was sent
1827
+ // (i.e., custom data after window.onload).
1828
+ function _sendCustomData() {
1825
1829
  var customerid = getCustomerId();
1826
1830
  if (!customerid ||
1827
1831
  !gSyncId ||
@@ -1830,8 +1834,8 @@
1830
1834
  ) {
1831
1835
  return;
1832
1836
  }
1833
- var sCustomerData = valuesToString(getUpdatedCustomData());
1834
- if (sCustomerData) {
1837
+ var customDataValues = valuesToString(getUpdatedCustomData());
1838
+ if (customDataValues) {
1835
1839
  var beaconUrl = _getBeaconUrl(getUpdatedCustomData());
1836
1840
  logger.logEvent(LogEvent.CustomDataBeaconSent, [beaconUrl]);
1837
1841
  _sendBeacon(beaconUrl);
@@ -2122,7 +2126,7 @@
2122
2126
  if (gbLuxSent) {
2123
2127
  // If the beacon was already sent for this page, we start a new page view and mark the
2124
2128
  // load time as the time it took to restore the page.
2125
- _init(pageRestoreTime);
2129
+ _init(pageRestoreTime, false);
2126
2130
  _markLoadTime();
2127
2131
  }
2128
2132
  // Flag the current page as a bfcache restore
@@ -92,11 +92,6 @@
92
92
  }
93
93
  }
94
94
 
95
- .gem-c-document-list__multi-list {
96
- width: 100%;
97
- margin-right: 25px;
98
- }
99
-
100
95
  .gem-c-document-list__item--highlight {
101
96
  border: 1px solid govuk-colour("mid-grey", $legacy: "grey-2");
102
97
  padding: govuk-spacing(6);
@@ -11,20 +11,29 @@
11
11
  classes << "gem-c-document-list--no-top-border-first-child" if local_assigns[:remove_top_border_from_first_child]
12
12
  classes << shared_helper.get_margin_bottom
13
13
 
14
- within_multitype_list ||= false
15
- within_multitype_list_class = " gem-c-document-list__multi-list" if within_multitype_list
16
14
  title_with_context_class = " gem-c-document-list__item-title--context"
17
15
 
18
16
  brand ||= false
19
17
  brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)
18
+
19
+ disable_ga4 ||= false
20
+ unless disable_ga4
21
+ ga4_extra_data ||= {}
22
+ ga4_ul_attributes = {
23
+ module: "ga4-link-tracker",
24
+ ga4_track_links_only: "",
25
+ ga4_link: {
26
+ "event_name": "navigation",
27
+ "type": "document list",
28
+ }.merge(ga4_extra_data)
29
+ }
30
+ end
20
31
  %>
21
32
  <% if items.any? %>
22
- <% unless within_multitype_list %>
23
- <ul class="<%= classes.join(" ") %>">
24
- <% end %>
33
+ <%= tag.ul(class: classes.join(" "), data: ga4_ul_attributes) do %>
25
34
  <% items.each do |item| %>
26
35
  <% highlight_class = " gem-c-document-list__item--highlight" if item[:highlight] %>
27
- <li class="gem-c-document-list__item<%= within_multitype_list_class %> <%= brand_helper.brand_class %> <%= highlight_class %>">
36
+ <li class="gem-c-document-list__item <%= brand_helper.brand_class %> <%= highlight_class %>">
28
37
  <% if item[:highlight] && item[:highlight_text] %>
29
38
  <p class='gem-c-document-list__highlight-text'><%= item[:highlight_text] %></p>
30
39
  <% end %>
@@ -127,7 +136,5 @@
127
136
  <% end %>
128
137
  </li>
129
138
  <% end %>
130
- <% unless within_multitype_list %>
131
- </ul>
132
139
  <% end %>
133
140
  <% end %>
@@ -31,7 +31,6 @@
31
31
  event_name: "navigation",
32
32
  type: "content history",
33
33
  section: "Top",
34
- action: "opened"
35
34
  }.to_json unless disable_ga4
36
35
  %>
37
36
  <%= content_tag :div, class: classes, data: { module: "gem-toggle metadata" } do %>
@@ -25,9 +25,28 @@
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
+
30
+ if description_govspeak
31
+ govspeak_data_attributes = {
32
+ 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
+ }
46
+ end
28
47
  %>
29
48
  <% if title || description_present %>
30
- <%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region" do %>
49
+ <%= tag.section class: css_classes, aria: aria_attributes, lang: lang, role: "region", data: section_data_attributes do %>
31
50
  <%= tag.div class: "govuk-notification-banner__header" do %>
32
51
  <%= tag.h2 banner_title, class: "govuk-notification-banner__title", id: banner_title_id %>
33
52
  <% end if show_banner_title %>
@@ -37,8 +56,9 @@
37
56
  <%= tag.p description_text, class: "gem-c-notice__description" if description_text %>
38
57
 
39
58
  <%= description if description %>
40
-
41
- <%= render 'govuk_publishing_components/components/govspeak', content: description_govspeak if description_govspeak %>
59
+ <% if govspeak_data_attributes %>
60
+ <%= render 'govuk_publishing_components/components/govspeak', govspeak_data_attributes %>
61
+ <% end %>
42
62
  <% end %>
43
63
  <% end %>
44
64
  <% end %>
@@ -5,7 +5,7 @@
5
5
  title ||= false
6
6
  track_as_sharing ||= false
7
7
  track_as_follow ||= false
8
- ga4_data ||= {}
8
+ ga4_extra_data ||= {}
9
9
  stacked ||= false
10
10
  columns ||= false
11
11
 
@@ -58,7 +58,7 @@
58
58
  'index_link': index + 1,
59
59
  'index_total': links.length,
60
60
  'text': link[:icon],
61
- }.merge(ga4_data)
61
+ }.merge(ga4_extra_data)
62
62
  end
63
63
  if track_as_follow
64
64
  ga4_link_data = {
@@ -66,7 +66,7 @@
66
66
  'type': 'follow us',
67
67
  'index_link': index + 1,
68
68
  'index_total': links.length,
69
- }.merge(ga4_data)
69
+ }.merge(ga4_extra_data)
70
70
  end
71
71
  %>
72
72
  <%
@@ -73,7 +73,7 @@ examples:
73
73
  public_updated_at: 2016-09-05 16:48:27
74
74
  document_type: 'Statutory guidance'
75
75
  with_data_attributes_on_links:
76
- description: Note that the component does not include built in tracking. If this is required consider using the [track click script](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics/track-click.md).
76
+ description: Note that the component does not include built in Universal Analytics tracking. If this is required consider using the [track click script](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics/track-click.md).
77
77
  data:
78
78
  items:
79
79
  - link:
@@ -356,3 +356,26 @@ examples:
356
356
  path: 'https://www.actionfraud.police.uk/contact-us'
357
357
  rel: 'external'
358
358
  description: "Contact Action Fraud to report fraud and cyber crime, or to tell them you've been the victim of a scam."
359
+ with_extra_ga4_data:
360
+ description: |
361
+ Allows you to add extra GA4 link tracker attributes, or overwrite the existing ones on the links. See the
362
+ [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
363
+ data:
364
+ ga4_extra_data:
365
+ hello: 'world'
366
+ items:
367
+ - link:
368
+ text: 'Test link'
369
+ path: 'https://www.gov.uk'
370
+ description: "GOV.UK link"
371
+ without_ga4_tracking:
372
+ description: |
373
+ Disables GA4 tracking. Tracking is enabled by default. See the
374
+ [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
375
+ data:
376
+ disable_ga4: true
377
+ items:
378
+ - link:
379
+ text: 'Test link'
380
+ path: 'https://www.gov.uk'
381
+ description: "GOV.UK link"
@@ -65,3 +65,13 @@ 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
+
@@ -111,10 +111,10 @@ examples:
111
111
  Where the component is used to allow users to share content on social media, tracking can be added that uses [Social Interactions](https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions) in UA.
112
112
  If this option is not included, it is assumed the component is simply linking to social media pages and the extra options are omitted from the tracking call in UA.
113
113
  In GA4, when this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer.
114
- Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_data object.
114
+ Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
115
115
  data:
116
116
  track_as_sharing: true
117
- ga4_data: {
117
+ ga4_extra_data: {
118
118
  optional_extra_values: "go here"
119
119
  }
120
120
  links: [
@@ -133,10 +133,10 @@ examples:
133
133
  description: |
134
134
  Where the component is used to allow users to follow us on social media, tracking can be added.
135
135
  When this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer.
136
- Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_data object.
136
+ Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
137
137
  data:
138
138
  track_as_follow: true
139
- ga4_data: {
139
+ ga4_extra_data: {
140
140
  optional_extra_values: "go here"
141
141
  }
142
142
  links: [
@@ -45,7 +45,7 @@ module GovukPublishingComponents
45
45
  step_by_step: false,
46
46
  breadcrumbs: navigation.taxon_breadcrumbs,
47
47
  }
48
- elsif navigation.content_tagged_to_mainstream_browse_pages?
48
+ elsif navigation.content_parent_is_mainstream_browse?
49
49
  {
50
50
  step_by_step: false,
51
51
  breadcrumbs: navigation.breadcrumbs,
@@ -68,6 +68,10 @@ module GovukPublishingComponents
68
68
  content_item.dig("links", "mainstream_browse_pages").present?
69
69
  end
70
70
 
71
+ def content_parent_is_mainstream_browse?
72
+ content_item.dig("links", "parent").present? && content_item.dig("links", "parent", 0, "document_type") == "mainstream_browse_page"
73
+ end
74
+
71
75
  def content_has_curated_related_items?
72
76
  content_item.dig("links", "ordered_related_items").present? && content_item.dig("links", "parent").present?
73
77
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.4.0".freeze
2
+ VERSION = "37.5.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: 37.4.0
4
+ version: 37.5.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-02-19 00:00:00.000000000 Z
11
+ date: 2024-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config