govuk_publishing_components 36.0.2 → 36.0.3

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: 9964e934f4ce2788b32ae7209b5838a04a44cadbb302c4cf45bd723fd6e9cf38
4
- data.tar.gz: 9aa95ca3c117ebef6c201f29990e1b12961b53c435c7904936c44e7b22b53cd7
3
+ metadata.gz: fca7a5f4a2f77be1b86157531a3f2884b70ebde62cea12c194bad2b29886d121
4
+ data.tar.gz: 9e59cd6485f898e8f86f1b2f21022bca130c5d471d2a87afd498be029811a265
5
5
  SHA512:
6
- metadata.gz: 1094205965013e02ab4655bd58fa2e6ac6cfad898ba94275ab93fc3bec5c738fff2fe575e34ac2429e66c912fc54c25afdcf3f878d6090e20ce180bc805e4aa5
7
- data.tar.gz: 52f249d3d4edbf8f16d696154c5faf1e751ea386eae9ede15bde6ad248bd705eda6c91b98dfaf4f221c03908b5dd57e9b8ce84eba0c9e85d2078aee907dfe9a8
6
+ metadata.gz: 00cb71df653b04a54fd700ab26efedde9852421def70e5e4c5e40b8ac3b90828e926aa9311dd526a0c2f2e417ed6dff0d70cd6197beaad702ffd311ac2e05a31
7
+ data.tar.gz: e34e2387ad6ef7903892a12090be73aa46c1307749fde8b38338afb7bcda5cd0f987eb675737012dc6f72b715643f14a16d2795a3593ea8671d04a81761eb8a3
@@ -275,6 +275,19 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
275
275
  return url
276
276
  }
277
277
  return this.getPathname() + url
278
+ },
279
+
280
+ standardiseSearchTerm: function (searchTerm) {
281
+ if (!searchTerm) {
282
+ return undefined // Prevents conversion of undefined to a string by this function.
283
+ }
284
+
285
+ var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
286
+ searchTerm = searchTerm.replace(/\++|(%2B)+/gm, ' ') // Turn + characters or unicode + characters (%2B) into a space.
287
+ searchTerm = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(searchTerm)
288
+ searchTerm = PIIRemover.stripPIIWithOverride(searchTerm, true, true)
289
+ searchTerm = searchTerm.toLowerCase()
290
+ return searchTerm
278
291
  }
279
292
  },
280
293
 
@@ -313,12 +326,11 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
313
326
  var isSearchResult = element.getAttribute('data-ga4-search-query')
314
327
 
315
328
  var ecommerceSchema = new window.GOVUK.analyticsGa4.Schemas().ecommerceSchema()
316
- var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
317
329
  var DEFAULT_LIST_TITLE = 'Smart answer results'
318
330
 
319
331
  if (isSearchResult) {
320
332
  // Limiting to 100 characters to avoid noise from extra long search queries and to stop the size of the payload going over 8k limit.
321
- var searchQuery = PIIRemover.stripPII(element.getAttribute('data-ga4-search-query')).substring(0, 100).toLowerCase()
333
+ var searchQuery = window.GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(element.getAttribute('data-ga4-search-query')).substring(0, 100)
322
334
  var variant = element.getAttribute('data-ga4-ecommerce-variant')
323
335
  DEFAULT_LIST_TITLE = 'Site search results'
324
336
  }
@@ -47,8 +47,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
47
47
  data.text = data.text || this.combineGivenAnswers(formData) || this.useFallbackValue
48
48
 
49
49
  if (data.action === 'search' && data.text) {
50
- data.text = data.text.toLowerCase()
51
- data.text = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(data.text)
50
+ data.text = window.GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(data.text)
52
51
  }
53
52
  window.GOVUK.analyticsGa4.core.applySchemaAndSendData(data, 'event_data')
54
53
  }
@@ -85,7 +85,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
85
85
  if (!data.text && (element.querySelector('img') || element.querySelector('svg') || element.tagName === 'IMG' || element.closest('svg'))) {
86
86
  data.text = 'image'
87
87
  }
88
- var url = data.url || this.findLink(event.target).getAttribute('href')
88
+ try {
89
+ var url = data.url || this.findLink(event.target).getAttribute('href')
90
+ } catch (e) {
91
+ // no href found, so abort
92
+ return
93
+ }
94
+
89
95
  data.url = trackFunctions.removeCrossDomainParams(url)
90
96
  data.url = trackFunctions.applyRedactionIfRequired(this.PIIRemover, element, data.url)
91
97
  data.url = trackFunctions.appendPathToAnchorLinks(data.url)
@@ -86,9 +86,8 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
86
86
  }
87
87
 
88
88
  searchTerm = searchTerm[0].replace('keywords=', '')
89
- searchTerm = searchTerm.replace(/\++/g, ' ')
90
- searchTerm = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(searchTerm)
91
- searchTerm = this.PIIRemover.stripPIIWithOverride(searchTerm, true, true)
89
+ searchTerm = window.GOVUK.analyticsGa4.core.trackFunctions.standardiseSearchTerm(searchTerm)
90
+
92
91
  return searchTerm
93
92
  },
94
93
 
@@ -116,7 +116,7 @@
116
116
  // https://github.com/alphagov/govuk_publishing_components/pull/908#discussion_r302913995
117
117
  var videoTitle = options.title
118
118
  event.target.getIframe().title = videoTitle + ' (video)'
119
- if (window.GOVUK.analyticsGa4.analyticsModules.VideoTracker) {
119
+ if (window.GOVUK.analyticsGa4.analyticsModules && window.GOVUK.analyticsGa4.analyticsModules.VideoTracker) {
120
120
  window.GOVUK.analyticsGa4.analyticsModules.VideoTracker.configureVideo(event)
121
121
  }
122
122
  },
@@ -105,6 +105,7 @@ module GovukPublishingComponents
105
105
  { content_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation", name: "MS PowerPoint Presentation" }.freeze, # pptx
106
106
  { content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", name: "MS Excel Spreadsheet", spreadsheet: true }.freeze, # xlsx
107
107
  { content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", name: "MS Word Document", document: true }.freeze, # docx
108
+ { content_type: "application/zip", abbr: "ZIP", name: "Zip archive" }.freeze,
108
109
  { content_type: "application/xml", abbr: "XML", name: "XML Document" }.freeze,
109
110
  { content_type: "image/gif", abbr: "GIF", name: "Graphics Interchange Format" }.freeze,
110
111
  { content_type: "image/jpeg", name: "JPEG" }.freeze,
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "36.0.2".freeze
2
+ VERSION = "36.0.3".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: 36.0.2
4
+ version: 36.0.3
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-12-04 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config