govuk_publishing_components 30.6.1 → 30.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06ca4d601d0b03adb4b547798eaffae4455c9fa854e97172bce34fe6164cbd2f
4
- data.tar.gz: 7cb234f6d40408729f077a5c5faacf7d878300fca110d5d56847e7efeee78dcc
3
+ metadata.gz: 932b483ebc824de1a71b97e465fe66919e6adc1d95e95948e0fefa71cc094fe4
4
+ data.tar.gz: 22584814d289f173d79f6ea9f9bf9e2d7368daa59b681772cb6a45ebaf381a24
5
5
  SHA512:
6
- metadata.gz: bf986be244673e1346c95d129993a51beea17104ff5e2deba9e454f3eb4299d2c4961651e8a5fe1fde162bf95348024d72cc58465f81fb8bda7466cd2d3ea42c
7
- data.tar.gz: 6c1b7d356bf4cf208ca53379b26c07e1b815f0324a5a5ad16be3762c0388c497a7a4b5737df73e0b4bb9775979a81ab255a8b2b8a1da978b1c7b5a4b39cef610
6
+ metadata.gz: 21a4d08ff321e2ef0e112e44a98ff1cd7da84991a5b650fc0e881355baee7162da644c2cc2b96e774951b5d64482ee293861b28cb1ebc7bdd0ee39ecdef1a30c
7
+ data.tar.gz: b2b47fe59365c766b0511d609830aa082a1892f0ce939e7ddc6fc8da659ba2edd338ed363e5d802322e866cde20ca49c4ee06f9a847cfe44a42c6f31d9b7bb7e
@@ -0,0 +1,141 @@
1
+ // = require govuk/vendor/polyfills/Element/prototype/closest.js
2
+ ;(function (global) {
3
+ 'use strict'
4
+
5
+ var GOVUK = global.GOVUK || {}
6
+ GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
7
+
8
+ GOVUK.analyticsGA4.Ga4EnhancedEcommerceTracker = {
9
+ PIIRemover: new GOVUK.analyticsGA4.PIIRemover(),
10
+ DEFAULT_LIST_TITLE: 'Site search results',
11
+
12
+ init: function (isNewPageLoad) {
13
+ if (window.dataLayer) {
14
+ this.searchResultsBlocks = document.querySelectorAll('[data-ga4-ecommerce]')
15
+ this.isNewPageLoad = isNewPageLoad
16
+
17
+ if (!this.searchResultsBlocks.length === 0) {
18
+ return
19
+ }
20
+
21
+ /* If the results are updated by JS, the URL of the page will change and this needs to be visible to PA's,
22
+ hence the pageView object push to the dataLayer. We do not need to send a pageView object on page load as
23
+ this is handled elsewhere. */
24
+ if (!this.isNewPageLoad) {
25
+ var pageViewTracker = window.GOVUK.analyticsGA4.analyticsModules.PageViewTracker
26
+
27
+ if (pageViewTracker) {
28
+ pageViewTracker.init()
29
+ }
30
+ }
31
+
32
+ for (var i = 0; i < this.searchResultsBlocks.length; i++) {
33
+ this.trackSearchResults(this.searchResultsBlocks[i])
34
+
35
+ if (this.isNewPageLoad) {
36
+ this.searchResultsBlocks[i].addEventListener('click', this.handleClick.bind(this))
37
+ }
38
+ }
39
+ }
40
+ },
41
+
42
+ trackSearchResults: function (searchResultsBlock) {
43
+ var schema = this.populateEcommerceSchema(searchResultsBlock, false, null)
44
+
45
+ this.clearPreviousEcommerceObject()
46
+ window.dataLayer.push(schema)
47
+ },
48
+
49
+ handleClick: function (event) {
50
+ var searchResultsBlock = event.target.closest('[data-ga4-ecommerce]')
51
+ var isSearchResult = event.target.getAttribute('data-ecommerce-path')
52
+
53
+ if (isSearchResult) {
54
+ var searchResult = event.target
55
+ var schema = this.populateEcommerceSchema(searchResultsBlock, true, searchResult)
56
+
57
+ this.clearPreviousEcommerceObject()
58
+ window.dataLayer.push(schema)
59
+ }
60
+ },
61
+
62
+ populateEcommerceSchema: function (searchResultsBlock, searchResultClicked, searchResult) {
63
+ // Limiting to 100 characters to avoid noise from extra long search queries and to stop the size of the payload going over 8k limit.
64
+ var searchQuery = this.PIIRemover.stripPII(searchResultsBlock.getAttribute('data-search-query')).substring(0, 100).toLowerCase()
65
+ var variant = searchResultsBlock.getAttribute('data-ecommerce-variant') || undefined
66
+ var ecommerceRows = searchResultsBlock.querySelectorAll('[data-ecommerce-row]')
67
+ var listTitle = searchResultsBlock.getAttribute('data-list-title') || this.DEFAULT_LIST_TITLE
68
+ var startPosition = parseInt(searchResultsBlock.getAttribute('data-ecommerce-start-index'), 10)
69
+
70
+ var ecommerceObject = {
71
+ event: 'search_results',
72
+ search_results: {
73
+ event_name: searchResultClicked && searchResult ? 'select_item' : 'view_item_list',
74
+ term: searchQuery,
75
+ sort: variant,
76
+ results: this.getResultsCount(searchResultsBlock),
77
+ ecommerce: {
78
+ items: []
79
+ }
80
+ }
81
+ }
82
+
83
+ // Populate items array
84
+ if (searchResultClicked && searchResult) {
85
+ ecommerceObject.search_results.ecommerce.items.push({
86
+ item_id: searchResult.getAttribute('data-ecommerce-path'),
87
+ item_name: searchResult.textContent,
88
+ item_list_name: listTitle,
89
+ index: this.getIndex(searchResult, startPosition)
90
+ })
91
+
92
+ ecommerceObject.event_data = {
93
+ external: GOVUK.analyticsGA4.analyticsModules.Ga4LinkTracker.isExternalLink(searchResult.getAttribute('data-ecommerce-path')) ? 'true' : 'false'
94
+ }
95
+ } else {
96
+ for (var i = 0; i < ecommerceRows.length; i++) {
97
+ var ecommerceRow = ecommerceRows[i]
98
+ var path = ecommerceRow.getAttribute('data-ecommerce-path')
99
+
100
+ /* If the element does not have a data-ecommerce-index attribute, we set one so that we can use it later when setting the index property
101
+ on the ecommerce object. This for loop will always run on page load and so data-ecommerce-index will be available when we use it in the
102
+ initial if block above that checks if a search result has been clicked. */
103
+ if (!ecommerceRow.getAttribute('data-ecommerce-index')) {
104
+ ecommerceRow.setAttribute('data-ecommerce-index', i + 1)
105
+ }
106
+
107
+ ecommerceObject.search_results.ecommerce.items.push({
108
+ item_id: path,
109
+ item_list_name: listTitle,
110
+ index: this.getIndex(ecommerceRow, startPosition)
111
+ })
112
+ }
113
+ }
114
+
115
+ return ecommerceObject
116
+ },
117
+
118
+ getIndex: function (element, startPosition) {
119
+ return parseInt(element.getAttribute('data-ecommerce-index')) + startPosition - 1
120
+ },
121
+
122
+ clearPreviousEcommerceObject: function () {
123
+ window.dataLayer.push({ search_results: { ecommerce: null } })
124
+ },
125
+
126
+ getResultsCount: function (searchResultsBlock) {
127
+ // This returns a string e.g. '12,345 results'. Therefore to extract the number, we need to remove the comma and split the string at the space
128
+ var resultsCount = searchResultsBlock.querySelector('#js-result-count')
129
+
130
+ if (!resultsCount) {
131
+ return null
132
+ }
133
+
134
+ resultsCount = resultsCount.textContent.replace(',', '')
135
+ resultsCount = resultsCount.split(' ')[0]
136
+ return parseInt(resultsCount)
137
+ }
138
+ }
139
+
140
+ global.GOVUK = GOVUK
141
+ })(window)
@@ -7,7 +7,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
7
7
 
8
8
  var PageViewTracker = {
9
9
  PIIRemover: new window.GOVUK.analyticsGA4.PIIRemover(), // imported in analytics-ga4.js
10
- nullValue: null,
10
+ nullValue: undefined,
11
11
 
12
12
  init: function () {
13
13
  if (window.dataLayer) {
@@ -102,7 +102,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
102
102
  // return only the date from given timestamps of the form
103
103
  // 2022-03-28T19:11:00.000+00:00
104
104
  stripTimeFrom: function (value) {
105
- if (value !== null) {
105
+ if (value !== undefined) {
106
106
  return value.split('T')[0]
107
107
  } else {
108
108
  return this.nullValue
@@ -4,24 +4,24 @@
4
4
  var GOVUK = global.GOVUK || {}
5
5
 
6
6
  var Schemas = function () {
7
- this.null = null
7
+ this.undefined = undefined
8
8
  }
9
9
 
10
10
  Schemas.prototype.eventSchema = function () {
11
11
  return {
12
- event: this.null,
12
+ event: this.undefined,
13
13
 
14
14
  event_data: {
15
- event_name: this.null,
16
- type: this.null,
17
- url: this.null,
18
- text: this.null,
19
- index: this.null,
20
- index_total: this.null,
21
- section: this.null,
22
- action: this.null,
23
- external: this.null,
24
- link_method: this.null
15
+ event_name: this.undefined,
16
+ type: this.undefined,
17
+ url: this.undefined,
18
+ text: this.undefined,
19
+ index: this.undefined,
20
+ index_total: this.undefined,
21
+ section: this.undefined,
22
+ action: this.undefined,
23
+ external: this.undefined,
24
+ link_method: this.undefined
25
25
  }
26
26
  }
27
27
  }
@@ -5,4 +5,5 @@
5
5
  //= require ./analytics-ga4/ga4-page-views
6
6
  //= require ./analytics-ga4/ga4-link-tracker
7
7
  //= require ./analytics-ga4/ga4-event-tracker
8
+ //= require ./analytics-ga4/ga4-enhanced-ecommerce-tracker
8
9
  //= require ./analytics-ga4/init-ga4
@@ -8,7 +8,7 @@
8
8
  path_without_pii = utf_encode(request.fullpath.gsub(email_regex, '[email]'))
9
9
  %>
10
10
 
11
- <div class="gem-c-feedback govuk-!-display-none-print" data-module="feedback">
11
+ <div class="gem-c-feedback govuk-!-display-none-print" data-module="feedback ga4-event-tracker">
12
12
  <%= render "govuk_publishing_components/components/feedback/yes_no_banner" %>
13
13
  <%= render "govuk_publishing_components/components/feedback/problem_form", url_without_pii: url_without_pii %>
14
14
  <%= render "govuk_publishing_components/components/feedback/survey_signup_form", path_without_pii: path_without_pii %>
@@ -20,12 +20,12 @@
20
20
  <% end %>
21
21
  </li>
22
22
  <li class="gem-c-feedback__option-list-item">
23
- <button class="govuk-button gem-c-feedback__prompt-link js-page-is-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffYesClick">
23
+ <button class="govuk-button gem-c-feedback__prompt-link js-page-is-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffYesClick" data-ga4='{"event_name":"form_submit","type":"feedback","text":"Yes", "section": "Is this page useful?"}'>
24
24
  <%= t("components.feedback.yes") %> <span class="govuk-visually-hidden"><%= t("components.feedback.is_useful") %></span>
25
25
  </button>
26
26
  </li>
27
27
  <li class="gem-c-feedback__option-list-item">
28
- <button class="govuk-button gem-c-feedback__prompt-link js-toggle-form js-page-is-not-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffNoClick" aria-controls="page-is-not-useful" aria-expanded="false">
28
+ <button class="govuk-button gem-c-feedback__prompt-link js-toggle-form js-page-is-not-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffNoClick" aria-controls="page-is-not-useful" aria-expanded="false" data-ga4='{"event_name":"form_submit","type":"feedback","text":"No", "section": "Is this page useful?"}'>
29
29
  <%= t("components.feedback.no") %> <span class="govuk-visually-hidden"><%= t("components.feedback.is_not_useful") %></span>
30
30
  </button>
31
31
  </li>
@@ -232,12 +232,12 @@ en:
232
232
  navigation_search_heading: Search and popular pages
233
233
  navigation_search_subheading: Search
234
234
  popular_links:
235
- - label: 'Her Majesty Queen Elizabeth II'
236
- href: '/government/topical-events/her-majesty-queen-elizabeth-ii'
237
235
  - label: 'Check benefits and financial support you can get'
238
236
  href: '/check-benefits-financial-support'
239
237
  - label: 'Limits on energy prices: Energy Price Guarantee'
240
238
  href: '/government/publications/energy-bills-support/energy-bills-support-factsheet-8-september-2022'
239
+ - label: 'Find a job'
240
+ href: '/find-a-job'
241
241
  - label: 'Coronavirus (COVID-19)'
242
242
  href: '/coronavirus'
243
243
  - label: 'Universal Credit account: sign in'
@@ -295,11 +295,11 @@ en:
295
295
  title: Invasion of Ukraine
296
296
  links:
297
297
  - label: "UK visa support for Ukrainian nationals"
298
- href: "https://www.gov.uk/guidance/support-for-family-members-of-british-nationals-in-ukraine-and-ukrainian-nationals-in-ukraine-and-the-uk"
298
+ href: "https://www.gov.uk/guidance/support-for-family-members-of-british-nationals-in-ukraine-and-ukrainian-nationals-in-ukraine-and-the-uk"
299
299
  - label: "Move to the UK if you're coming from Ukraine"
300
300
  href: "https://www.gov.uk/guidance/move-to-the-uk-if-youre-from-ukraine"
301
301
  - label: "Homes for Ukraine: record your interest"
302
- href: "https://www.gov.uk/register-interest-homes-ukraine"
302
+ href: "https://www.gov.uk/register-interest-homes-ukraine"
303
303
  - label: "Find out about the UK’s response"
304
304
  href: "https://ukstandswithukraine.campaign.gov.uk/"
305
305
  world_locations: World locations
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "30.6.1".freeze
2
+ VERSION = "30.7.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: 30.6.1
4
+ version: 30.7.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: 2022-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -437,6 +437,7 @@ files:
437
437
  - app/assets/javascripts/govuk_publishing_components/all_components.js
438
438
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
439
439
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js.erb
440
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-enhanced-ecommerce-tracker.js
440
441
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
441
442
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js
442
443
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js