govuk_publishing_components 35.1.1 → 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: da29b78f56ceabe774802deed6b8570f0459ba1414b60d0a46b1c891facb5b25
4
- data.tar.gz: 2b431b2babeb7dc74281f27b13f23525b658d8cace7727ed08658945d0669763
3
+ metadata.gz: 972ee046b894a4166b8098b0fd68443fe83c9dd3ca990dc53df66943719bc3f8
4
+ data.tar.gz: fe06a9efe47489b88fe35088fe043cbf404683516ba709d9ec8192412749e2e6
5
5
  SHA512:
6
- metadata.gz: 74a753d9e83276ae6c71bf0ce682a8cfd269195adda6ca9d04188d729f19da63103de4a31285902a5195b87762921a905adb91acf5674a19e1b0e90a9b3c5f6d
7
- data.tar.gz: 17a2048555b604f03a55ab8756c9a33a8b1324b8c2db8944868264d06526e1e01fd2ced69b3fb06746be8252e32aaeb0d7b2a28ae005b0ccd082986f5b408d4a
6
+ metadata.gz: 788a0616987260f023d3c4b982e9ae7ca1150bdf996ed6001c7d999eb22116725b4a5ebaef2069ab23882fb4d1acbdb7c47d7f0686c1ef4bd171773de27da178
7
+ data.tar.gz: ee4d860cc7fcaa7e7f374edd761d4f513455b319efea4b1e115667ae8cef89c0fef815c46c00b9b0330eb511ce6d5822dea79877174dddc3e1c67cb9feac3182
@@ -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')