govuk_publishing_components 36.0.1 → 36.0.3

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: d41ddf9d28242ee496fbf50b88e10bbf1785c27ed809bb8ee40a9cb099092068
4
- data.tar.gz: 72d8c532895124b04ffedc228c0baffaa180828f1765d75a7cc792b4969f6ceb
3
+ metadata.gz: fca7a5f4a2f77be1b86157531a3f2884b70ebde62cea12c194bad2b29886d121
4
+ data.tar.gz: 9e59cd6485f898e8f86f1b2f21022bca130c5d471d2a87afd498be029811a265
5
5
  SHA512:
6
- metadata.gz: ddd6e3b7b2dcb71844e37cb5065aea4c331c0a4e0bbf7daa38e52a9b4161bde2edea212ac24553e74df5d5b599346a8f4e72b853a1a3eb99413fec316519497b
7
- data.tar.gz: bd76e4fbb84e10bd6d20b55bd46e499431d52b9dd794b1b152065f63798d922587b9ef22d8fca9a9b3fe6d5e77d5387ddfbd52e0dcde86b7a1bfe5948ecfcd84
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,
@@ -92,13 +92,12 @@ module GovukPublishingComponents
92
92
  def add_ga4_political_tags(meta_tags)
93
93
  government = content_item.dig(:links, :government, 0)
94
94
 
95
- # political: true/false is in a different place to current: true/false, which is why we have 'details' and 'government[:details]'
95
+ # political: true/false is in a different place to current: true/false, which is why we have 'details' and 'government.dig(:details)'
96
96
  if government && details[:political]
97
- meta_tags["govuk:ga4-political-status"] = government[:details][:current] ? "political" : "historic"
98
-
99
- government_title = government[:title]
100
- if government_title && !government[:details][:current]
101
- meta_tags["govuk:ga4-publishing-government"] = government_title
97
+ current_government = government.dig(:details, :current)
98
+ unless current_government
99
+ meta_tags["govuk:ga4-political-status"] = "historic"
100
+ meta_tags["govuk:ga4-publishing-government"] = government[:title] if government[:title]
102
101
  end
103
102
  end
104
103
 
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "36.0.1".freeze
2
+ VERSION = "36.0.3".freeze
3
3
  end
@@ -54,12 +54,12 @@ Demo: http://sortablejs.github.io/Sortable/
54
54
 
55
55
  Install with NPM:
56
56
  ```bash
57
- $ npm install sortablejs --save
57
+ npm install sortablejs --save
58
58
  ```
59
59
 
60
60
  Install with Bower:
61
61
  ```bash
62
- $ bower install --save sortablejs
62
+ bower install --save sortablejs
63
63
  ```
64
64
 
65
65
  Import into your project: