govuk_publishing_components 35.1.1 → 35.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/component_guide/application.js +1 -0
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +34 -4
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +20 -2
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +5 -0
  6. data/app/assets/javascripts/govuk_publishing_components/components/intervention.js +69 -0
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +5 -2
  8. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +1 -0
  9. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +430 -313
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +2 -3
  11. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +1 -1
  12. data/app/models/govuk_publishing_components/audit_applications.rb +5 -1
  13. data/app/models/govuk_publishing_components/audit_comparer.rb +4 -4
  14. data/app/views/govuk_publishing_components/audit/_applications.html.erb +22 -4
  15. data/app/views/govuk_publishing_components/components/_accordion.html.erb +25 -1
  16. data/app/views/govuk_publishing_components/components/_intervention.html.erb +15 -7
  17. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +19 -5
  18. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +23 -3
  19. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +24 -4
  20. data/app/views/govuk_publishing_components/components/docs/intervention.yml +11 -6
  21. data/lib/govuk_publishing_components/presenters/component_wrapper_helper.rb +35 -12
  22. data/lib/govuk_publishing_components/presenters/intervention_helper.rb +16 -5
  23. data/lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb +0 -16
  24. data/lib/govuk_publishing_components/version.rb +1 -1
  25. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da29b78f56ceabe774802deed6b8570f0459ba1414b60d0a46b1c891facb5b25
4
- data.tar.gz: 2b431b2babeb7dc74281f27b13f23525b658d8cace7727ed08658945d0669763
3
+ metadata.gz: 0f87c9fa99d845d53392c5a02a8c4330f7a9557b94290a55cc18b5f169862215
4
+ data.tar.gz: ee6d97596ccbc7cfc9704f95dd3b1940e6b60254fc3fe7f6c51d5d6c16d1ead4
5
5
  SHA512:
6
- metadata.gz: 74a753d9e83276ae6c71bf0ce682a8cfd269195adda6ca9d04188d729f19da63103de4a31285902a5195b87762921a905adb91acf5674a19e1b0e90a9b3c5f6d
7
- data.tar.gz: 17a2048555b604f03a55ab8756c9a33a8b1324b8c2db8944868264d06526e1e01fd2ced69b3fb06746be8252e32aaeb0d7b2a28ae005b0ccd082986f5b408d4a
6
+ metadata.gz: 635eaae4b3ce872688184197dd240be9751f6d9286680f324a876cea3d00a9bfa0b6037b5817fbf58a66d319510dcbca747ff5c7bc69e5d76a7c33cb345963cb
7
+ data.tar.gz: 595feac64b2542ef4ff5cb669e7e12462cea78d250cb0d44f01312de9297379d0e2c9f4d8bff0ab75a59a3b523fd6d801df93518f4c407c600b87695c17c1ea8
@@ -2,4 +2,5 @@
2
2
  //= require_tree .
3
3
  //= require ../govuk_publishing_components/dependencies
4
4
  //= require ../govuk_publishing_components/components/accordion
5
+ //= require ../govuk_publishing_components/components/intervention
5
6
  //= require ../govuk_publishing_components/components/tabs
@@ -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
@@ -268,6 +273,31 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
268
273
  index_link: parseInt(index[2])
269
274
  }
270
275
  }
276
+ },
277
+
278
+ addAttributesToElements: function (selector, dataAttributes) {
279
+ var targetElements = document.querySelectorAll(selector)
280
+
281
+ for (var i = 0; i < targetElements.length; i++) {
282
+ var element = targetElements[i]
283
+
284
+ for (var j = 0; j < dataAttributes.length; j++) {
285
+ var key = dataAttributes[j].key
286
+ var value = dataAttributes[j].value
287
+
288
+ // value must check for undefined only as it would return false on an empty string, the number 0, etc.
289
+ if (key && value !== undefined) {
290
+ var existingAttributeValue = element.getAttribute(key)
291
+
292
+ if (key === 'data-module' && existingAttributeValue) {
293
+ // Combines values to prevent replacing any existing data-module values.
294
+ element.setAttribute(key, existingAttributeValue + ' ' + value)
295
+ } else {
296
+ element.setAttribute(key, value)
297
+ }
298
+ }
299
+ }
300
+ }
271
301
  }
272
302
  },
273
303
 
@@ -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,24 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
108
107
  }
109
108
  }
110
109
 
110
+ Ga4LinkTracker.prototype.setIndex = function (indexData, target) {
111
+ var index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(indexData)
112
+
113
+ if (target.getAttribute('data-ga4-index')) {
114
+ try {
115
+ var indexLink = JSON.parse(target.getAttribute('data-ga4-index'))
116
+
117
+ // Check whether the index object already exists on a parent element, as is the case with tracking accordion links.
118
+ // If true, combine data-ga4-index with the index object. Otherwise, just return indexLink
119
+ index = index ? window.GOVUK.extendObject(index, indexLink) : indexLink
120
+ } catch (e) {
121
+ console.error('Unable to parse index as JSON: ' + e.message, window.location)
122
+ return
123
+ }
124
+ }
125
+
126
+ return index
127
+ }
128
+
111
129
  Modules.Ga4LinkTracker = Ga4LinkTracker
112
130
  })(window.GOVUK.Modules)
@@ -8,6 +8,11 @@ var initFunction = function () {
8
8
  window.GOVUK.analyticsGa4.vars.internalDomains = []
9
9
  window.GOVUK.analyticsGa4.vars.internalDomains.push(window.GOVUK.analyticsGa4.core.trackFunctions.getHostname())
10
10
  window.GOVUK.analyticsGa4.core.trackFunctions.appendDomainsWithoutWWW(window.GOVUK.analyticsGa4.vars.internalDomains)
11
+ var attachmentLinkData = [
12
+ { key: 'data-module', value: 'ga4-link-tracker' },
13
+ { key: 'data-ga4-track-links-only', value: '' },
14
+ { key: 'data-ga4-link', value: JSON.stringify({ event_name: 'navigation', type: 'html attachment' }) }]
15
+ window.GOVUK.analyticsGa4.core.trackFunctions.addAttributesToElements('[data-ga4-attachment-link]', attachmentLinkData)
11
16
  window.GOVUK.analyticsGa4.core.load()
12
17
 
13
18
  var analyticsModules = window.GOVUK.analyticsGa4.analyticsModules
@@ -0,0 +1,69 @@
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
+
4
+ (function (Modules) {
5
+ function Intervention ($module) {
6
+ this.$module = $module
7
+ this.$closeLink = this.$module.querySelector('.js-dismiss-link')
8
+ this.$campaignName = this.$module.getAttribute('data-intervention-name')
9
+ this.$campaignCookie = window.GOVUK.cookie('intervention_campaign') || ''
10
+ }
11
+
12
+ Intervention.prototype.init = function () {
13
+ this.$cookieHasCampaign = this.cookieHasCampaign()
14
+
15
+ if (this.$closeLink) {
16
+ this.$module.close = this.handleClose.bind(this)
17
+ this.$closeLink.addEventListener('click', this.$module.close)
18
+ }
19
+
20
+ if (this.$cookieHasCampaign) {
21
+ this.hideBanner()
22
+ }
23
+ }
24
+
25
+ Intervention.prototype.handleClose = function (event) {
26
+ event.preventDefault()
27
+
28
+ if (this.$cookieHasCampaign) {
29
+ this.setCookies()
30
+ }
31
+ this.hideBanner()
32
+ }
33
+
34
+ Intervention.prototype.cookieHasCampaign = function () {
35
+ if (this.$campaignCookie) {
36
+ return this.cookieValues().includes(this.$campaignName)
37
+ }
38
+ return false
39
+ }
40
+
41
+ Intervention.prototype.cookieValues = function () {
42
+ if (this.$campaignCookie !== null && this.$campaignCookie.length > 0) {
43
+ return this.$campaignCookie.split(',')
44
+ }
45
+ }
46
+
47
+ Intervention.prototype.appendCookieValues = function () {
48
+ return this.$campaignCookie + ',' + this.$campaignName
49
+ }
50
+
51
+ Intervention.prototype.setCookies = function () {
52
+ if (this.$campaignCookie) {
53
+ window.GOVUK.setCookie('intervention_campaign', this.appendCookieValues(), { days: 30 })
54
+ } else {
55
+ window.GOVUK.setCookie('intervention_campaign', this.$campaignName, { days: 30 })
56
+ }
57
+ }
58
+
59
+ Intervention.prototype.hideBanner = function () {
60
+ if (!this.$cookieHasCampaign) {
61
+ this.setCookies()
62
+ }
63
+
64
+ this.$module.hidden = true
65
+ this.$module.style.display = 'none'
66
+ }
67
+
68
+ Modules.Intervention = Intervention
69
+ })(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')
@@ -17,6 +17,7 @@
17
17
  cookie_preferences_set: 'essential',
18
18
  cookies_preferences_set: 'essential',
19
19
  '_email-alert-frontend_session': 'essential',
20
+ intervention_campaign: 'essential',
20
21
  licensing_session: 'essential',
21
22
  govuk_contact_referrer: 'essential',
22
23
  multivariatetest_cohort_coronavirus_extremely_vulnerable_rate_limit: 'essential',