govuk_publishing_components 35.1.0 → 35.2.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: fd345b52485fb5fefdb529d929af976ca97fe31f8c9d73d5d8aa42868dbc55b0
4
- data.tar.gz: 3a41640de2f4784004f724604bdc7dc1a9a9202f963e1304c2c4ae4d2db2dfa9
3
+ metadata.gz: 972ee046b894a4166b8098b0fd68443fe83c9dd3ca990dc53df66943719bc3f8
4
+ data.tar.gz: fe06a9efe47489b88fe35088fe043cbf404683516ba709d9ec8192412749e2e6
5
5
  SHA512:
6
- metadata.gz: 0cfddee718886b034fcef934d97479726c0cf74257c268a8671f8ce2d88de9715416021dff81cc948d0791b70a115ba9545e6bde329ccf0fccaac1530687c915
7
- data.tar.gz: 561a511659dd0a07ca6d6b8432bdddff207770cc6a782d54ddd769dfbfd17c30583b9e2585688ad1decb645bd4390ae17d61e5e52b97fc33859ef801e9c73c4d
6
+ metadata.gz: 788a0616987260f023d3c4b982e9ae7ca1150bdf996ed6001c7d999eb22116725b4a5ebaef2069ab23882fb4d1acbdb7c47d7f0686c1ef4bd171773de27da178
7
+ data.tar.gz: ee4d860cc7fcaa7e7f374edd761d4f513455b319efea4b1e115667ae8cef89c0fef815c46c00b9b0330eb511ce6d5822dea79877174dddc3e1c67cb9feac3182
@@ -17,8 +17,6 @@
17
17
  // if there are no accordion sections on the browse level 2 page
18
18
  // then it is a default page with one or two lists
19
19
  return document.querySelectorAll('[data-track-count="accordionSection"]').length || document.querySelectorAll('main .govuk-list').length
20
- case isCostOfLivingHub():
21
- return document.querySelectorAll('[data-track-count="accordionSection"]').length
22
20
  case isNewBrowsePage():
23
21
  return document.querySelectorAll('[data-track-count="cardList"]').length
24
22
  case isMainstreamBrowsePage():
@@ -53,7 +51,6 @@
53
51
  case isDocumentCollectionPage():
54
52
  return document.querySelectorAll('.document-collection .group-document-list li a').length
55
53
  case isNewBrowsePageLevelTwo():
56
- case isCostOfLivingHub():
57
54
  return document.querySelectorAll('[data-track-count="contentLink"]').length
58
55
  case isNewBrowsePage():
59
56
  return document.querySelectorAll('[data-track-count="cardLink"]').length
@@ -111,11 +108,6 @@
111
108
  getMetaAttribute(metaNavigationTypeSelector) === 'browse level 2'
112
109
  }
113
110
 
114
- function isCostOfLivingHub () {
115
- return getMetaAttribute(metaApplicationSelector) === 'collections' &&
116
- getMetaAttribute(metaNavigationTypeSelector) === 'cost of living hub'
117
- }
118
-
119
111
  function isNewBrowsePage () {
120
112
  return getMetaAttribute(metaApplicationSelector) === 'collections' &&
121
113
  (getMetaAttribute(metaNavigationTypeSelector) === 'browse level 0' ||
@@ -230,13 +230,18 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
230
230
  // Only index links that are not search results
231
231
  if (!link.getAttribute('data-ga4-ecommerce-path')) {
232
232
  totalLinks++
233
- link.setAttribute('data-ga4-index', totalLinks)
233
+ link.setAttribute('data-ga4-index', '{"index_link": "' + totalLinks + '"}')
234
234
  }
235
235
  }
236
236
 
237
- var ga4LinkData = JSON.parse(module.getAttribute('data-ga4-link'))
238
- ga4LinkData.index_total = totalLinks
239
- module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
237
+ try {
238
+ var ga4LinkData = JSON.parse(module.getAttribute('data-ga4-link'))
239
+ ga4LinkData.index_total = totalLinks
240
+ module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
241
+ } catch (e) {
242
+ // if there's a problem with the config, don't start the tracker
243
+ console.error('Unable to JSON.parse or JSON.stringify index: ' + e.message, window.location)
244
+ }
240
245
  },
241
246
 
242
247
  // index is given as a string of the form 1.2.3 or 1.2
@@ -87,8 +87,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
87
87
  data.link_path_parts = window.GOVUK.analyticsGa4.core.trackFunctions.populateLinkPathParts(data.url)
88
88
  data.method = window.GOVUK.analyticsGa4.core.trackFunctions.getClickType(event)
89
89
  data.external = window.GOVUK.analyticsGa4.core.trackFunctions.isExternalLink(data.url) ? 'true' : 'false'
90
- data.index = event.target.getAttribute('data-ga4-index') ? parseInt(event.target.getAttribute('data-ga4-index')) : data.index || undefined
91
- data.index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(data.index)
90
+ data.index = this.setIndex(data.index, event.target)
92
91
 
93
92
  if (data.type === 'smart answer' && data.action === 'change response') {
94
93
  data.section = PIIRemover.stripPIIWithOverride(data.section, true, true)
@@ -108,5 +107,22 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
108
107
  }
109
108
  }
110
109
 
110
+ Ga4LinkTracker.prototype.setIndex = function (indexData, target) {
111
+ var index
112
+
113
+ if (target.getAttribute('data-ga4-index')) {
114
+ try {
115
+ index = JSON.parse(target.getAttribute('data-ga4-index'))
116
+ } catch (e) {
117
+ console.error('Unable to parse index as JSON: ' + e.message, window.location)
118
+ return
119
+ }
120
+ } else {
121
+ index = indexData || undefined
122
+ }
123
+
124
+ return window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(index)
125
+ }
126
+
111
127
  Modules.Ga4LinkTracker = Ga4LinkTracker
112
128
  })(window.GOVUK.Modules)
@@ -196,8 +196,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
196
196
  event_name: 'select_content',
197
197
  type: 'step by step',
198
198
  text: titleText.trim(),
199
- index: i + 1,
200
- index_total: this.$module.totalSteps
199
+ index: {
200
+ index_section: i + 1,
201
+ index_section_count: this.$module.totalSteps
202
+ },
203
+ index_total: thisel.querySelectorAll('a').length
201
204
  }
202
205
 
203
206
  var button = thisel.querySelector('.js-step-title-button')