govuk_publishing_components 30.7.3 → 31.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (18) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{ga4-core.js.erb → ga4-core.js} +12 -21
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{ga4-enhanced-ecommerce-tracker.js → ga4-ecommerce-tracker.js} +7 -5
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +2 -2
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +5 -5
  6. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +5 -5
  7. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js +2 -2
  8. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +5 -5
  9. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js +2 -2
  10. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -1
  11. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +5 -5
  12. data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +2 -2
  13. data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -1
  14. data/lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb +1 -1
  15. data/lib/govuk_publishing_components/presenters/machine_readable/page.rb +1 -1
  16. data/lib/govuk_publishing_components/presenters/machine_readable/potential_search_action_schema.rb +1 -1
  17. data/lib/govuk_publishing_components/version.rb +1 -1
  18. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a0126e6016869d447d661d4e1c4777d68a10292c19e388bcb22477021877b7b
4
- data.tar.gz: e83f7124df4f9126819c1f11310bfda63dde08be6c57749ead9395eef1d58ea0
3
+ metadata.gz: 23492ecba6eaaa3ed895868bf827524702313449a11c8ca79eed1e0d25565122
4
+ data.tar.gz: fddbfc77800da9f9999b164930528661bffaed54e70849e14d6ef9e1b1ab549d
5
5
  SHA512:
6
- metadata.gz: 03ac390a2a2a9fa5378699daac0dab1a55551bee3ab995f159487c5a5d295a3ff139629fab6b9f0b95dc52bc4d89d5b941f867e00c20fe9562eafbb5d5af43ef
7
- data.tar.gz: ee961b5da8eacf0d47567ae446a1c1741ea65576affbdeb84916bb48a64064de8383c1ad64de86da84def9ad5f13c034c7893dca904a7a64e8405b0133754e37
6
+ metadata.gz: f40277a05d20137b4695853f5c2a80bfab0ee90fb01ccf73d961e4e4c3e59a3c31c917022ed048c5e8ceff38bc1cc5a8fd9d62ceb5c5b7eef57893c30a3d4257
7
+ data.tar.gz: 0dc8abb57df600b8309abf46571ccb864a41b82f3f7b4cf6a2e3dcab4124777719d017719a87f51dde41855472b9d15b9920040a94a267acdf56d8222b51a472
@@ -1,39 +1,31 @@
1
- // note that because this file is .js.erb it is not linted
2
- // temporarily rename to .js to check with the linter
3
1
  window.GOVUK = window.GOVUK || {}
4
- window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {};
2
+ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
5
3
 
6
4
  (function (analytics) {
7
5
  'use strict'
8
6
 
9
7
  var core = {
10
8
  load: function () {
11
- var firstScript
12
- var newScript
9
+ var firstScript = document.getElementsByTagName('script')[0]
10
+ var newScript = document.createElement('script')
11
+ newScript.async = true
13
12
 
14
- if (window.GOVUK.analyticsGA4.vars.gtag_id) {
13
+ if (window.GOVUK.analyticsGa4.vars.gtag_id) {
15
14
  // initialise gtag
16
15
  window.dataLayer = window.dataLayer || []
17
16
  var gtag = function () { window.dataLayer.push(arguments) }
18
17
  gtag('js', new Date())
19
- gtag('config', window.GOVUK.analyticsGA4.vars.gtag_id)
18
+ gtag('config', window.GOVUK.analyticsGa4.vars.gtag_id)
20
19
 
21
- firstScript = document.getElementsByTagName('script')[0]
22
- newScript = document.createElement('script')
23
-
24
- newScript.async = true
25
- newScript.src = '//www.googletagmanager.com/gtag/js?id=' + window.GOVUK.analyticsGA4.vars.gtag_id
20
+ newScript.src = '//www.googletagmanager.com/gtag/js?id=' + window.GOVUK.analyticsGa4.vars.gtag_id
26
21
  firstScript.parentNode.insertBefore(newScript, firstScript)
27
22
  } else {
28
23
  // initialise GTM
29
24
  window.dataLayer = window.dataLayer || []
30
25
  window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' })
31
26
 
32
- firstScript = document.getElementsByTagName('script')[0]
33
- newScript = document.createElement('script')
34
-
35
- var auth = window.GOVUK.analyticsGA4.vars.auth || ''
36
- var preview = window.GOVUK.analyticsGA4.vars.preview || ''
27
+ var auth = window.GOVUK.analyticsGa4.vars.auth || ''
28
+ var preview = window.GOVUK.analyticsGa4.vars.preview || ''
37
29
  if (auth) {
38
30
  auth = '&gtm_auth=' + auth
39
31
  }
@@ -41,8 +33,7 @@ window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {};
41
33
  preview = '&gtm_preview=' + preview + '&gtm_cookies_win=x'
42
34
  }
43
35
 
44
- newScript.async = true
45
- this.googleSrc = 'https://www.googletagmanager.com/gtm.js?id=' + window.GOVUK.analyticsGA4.vars.id + auth + preview
36
+ this.googleSrc = 'https://www.googletagmanager.com/gtm.js?id=' + window.GOVUK.analyticsGa4.vars.id + auth + preview
46
37
  newScript.src = this.googleSrc
47
38
  firstScript.parentNode.insertBefore(newScript, firstScript)
48
39
  window.dataLayer.push({ 'gtm.blocklist': ['customPixels', 'customScripts', 'html', 'nonGoogleScripts'] })
@@ -55,9 +46,9 @@ window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {};
55
46
  },
56
47
 
57
48
  getGemVersion: function () {
58
- return '<%= GovukPublishingComponents::VERSION %>'
49
+ return window.GOVUK.analyticsGa4.vars.gem_version || 'not found'
59
50
  }
60
51
  }
61
52
 
62
53
  analytics.core = core
63
- })(window.GOVUK.analyticsGA4)
54
+ })(window.GOVUK.analyticsGa4)
@@ -3,14 +3,16 @@
3
3
  'use strict'
4
4
 
5
5
  var GOVUK = global.GOVUK || {}
6
- GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
6
+ GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
7
7
 
8
- GOVUK.analyticsGA4.Ga4EnhancedEcommerceTracker = {
9
- PIIRemover: new GOVUK.analyticsGA4.PIIRemover(),
8
+ GOVUK.analyticsGa4.Ga4EcommerceTracker = {
9
+ PIIRemover: new GOVUK.analyticsGa4.PIIRemover(),
10
10
  DEFAULT_LIST_TITLE: 'Site search results',
11
11
 
12
12
  init: function (isNewPageLoad) {
13
13
  if (window.dataLayer) {
14
+ /* The data-ga4-ecommerce attribute may be present on several DOM elements e.g. search results and spelling
15
+ suggestions, hence why document.querySelectorAll is required */
14
16
  this.searchResultsBlocks = document.querySelectorAll('[data-ga4-ecommerce]')
15
17
  this.isNewPageLoad = isNewPageLoad
16
18
 
@@ -22,7 +24,7 @@
22
24
  hence the pageView object push to the dataLayer. We do not need to send a pageView object on page load as
23
25
  this is handled elsewhere. */
24
26
  if (!this.isNewPageLoad) {
25
- var pageViewTracker = window.GOVUK.analyticsGA4.analyticsModules.PageViewTracker
27
+ var pageViewTracker = window.GOVUK.analyticsGa4.analyticsModules.PageViewTracker
26
28
 
27
29
  if (pageViewTracker) {
28
30
  pageViewTracker.init()
@@ -90,7 +92,7 @@
90
92
  })
91
93
 
92
94
  ecommerceObject.event_data = {
93
- external: GOVUK.analyticsGA4.analyticsModules.Ga4LinkTracker.isExternalLink(searchResult.getAttribute('data-ecommerce-path')) ? 'true' : 'false'
95
+ external: GOVUK.analyticsGa4.analyticsModules.Ga4LinkTracker.isExternalLink(searchResult.getAttribute('data-ecommerce-path')) ? 'true' : 'false'
94
96
  }
95
97
  } else {
96
98
  for (var i = 0; i < ecommerceRows.length; i++) {
@@ -31,7 +31,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
31
31
  Ga4EventTracker.prototype.trackClick = function (event) {
32
32
  var target = this.findTrackingAttributes(event.target)
33
33
  if (target) {
34
- var schema = new window.GOVUK.analyticsGA4.Schemas().eventSchema()
34
+ var schema = new window.GOVUK.analyticsGa4.Schemas().eventSchema()
35
35
 
36
36
  try {
37
37
  var data = target.getAttribute(this.trackingTrigger)
@@ -84,7 +84,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
84
84
  }
85
85
  }
86
86
 
87
- window.GOVUK.analyticsGA4.core.sendData(schema)
87
+ window.GOVUK.analyticsGa4.core.sendData(schema)
88
88
  }
89
89
  }
90
90
 
@@ -1,7 +1,7 @@
1
1
  // = require govuk/vendor/polyfills/Element/prototype/closest.js
2
2
  window.GOVUK = window.GOVUK || {}
3
- window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {}
4
- window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analyticsModules || {};
3
+ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
4
+ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
5
5
 
6
6
  (function (analyticsModules) {
7
7
  'use strict'
@@ -97,7 +97,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
97
97
  }
98
98
 
99
99
  if (Object.keys(clickData).length > 0) {
100
- var schema = new window.GOVUK.analyticsGA4.Schemas().eventSchema()
100
+ var schema = new window.GOVUK.analyticsGa4.Schemas().eventSchema()
101
101
  schema.event = 'event_data'
102
102
 
103
103
  // get attributes from the clickData object to send to GA
@@ -108,7 +108,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
108
108
  }
109
109
  }
110
110
 
111
- window.GOVUK.analyticsGA4.core.sendData(schema)
111
+ window.GOVUK.analyticsGa4.core.sendData(schema)
112
112
  }
113
113
  },
114
114
 
@@ -251,4 +251,4 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
251
251
  }
252
252
 
253
253
  analyticsModules.Ga4LinkTracker = Ga4LinkTracker
254
- })(window.GOVUK.analyticsGA4.analyticsModules)
254
+ })(window.GOVUK.analyticsGa4.analyticsModules)
@@ -1,12 +1,12 @@
1
1
  window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {}
3
- window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analyticsModules || {};
2
+ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
3
+ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
4
4
 
5
5
  (function (analyticsModules) {
6
6
  'use strict'
7
7
 
8
8
  var PageViewTracker = {
9
- PIIRemover: new window.GOVUK.analyticsGA4.PIIRemover(), // imported in analytics-ga4.js
9
+ PIIRemover: new window.GOVUK.analyticsGa4.PIIRemover(), // imported in analytics-ga4.js
10
10
  nullValue: undefined,
11
11
 
12
12
  init: function () {
@@ -45,7 +45,7 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
45
45
  world_locations: this.getMetaContent('analytics:world-locations')
46
46
  }
47
47
  }
48
- window.GOVUK.analyticsGA4.core.sendData(data)
48
+ window.GOVUK.analyticsGa4.core.sendData(data)
49
49
  }
50
50
  },
51
51
 
@@ -111,4 +111,4 @@ window.GOVUK.analyticsGA4.analyticsModules = window.GOVUK.analyticsGA4.analytics
111
111
  }
112
112
 
113
113
  analyticsModules.PageViewTracker = PageViewTracker
114
- })(window.GOVUK.analyticsGA4.analyticsModules)
114
+ })(window.GOVUK.analyticsGa4.analyticsModules)
@@ -26,8 +26,8 @@
26
26
  }
27
27
  }
28
28
 
29
- GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
30
- GOVUK.analyticsGA4.Schemas = Schemas
29
+ GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
30
+ GOVUK.analyticsGa4.Schemas = Schemas
31
31
 
32
32
  global.GOVUK = GOVUK
33
33
  })(window)
@@ -1,5 +1,5 @@
1
1
  window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {}
2
+ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
3
3
 
4
4
  var initFunction = function () {
5
5
  // to be added: digital identity consent mechanism
@@ -7,9 +7,9 @@ var initFunction = function () {
7
7
  var consentCookie = window.GOVUK.getConsentCookie()
8
8
 
9
9
  if (consentCookie && consentCookie.usage) {
10
- window.GOVUK.analyticsGA4.core.load()
10
+ window.GOVUK.analyticsGa4.core.load()
11
11
 
12
- var analyticsModules = window.GOVUK.analyticsGA4.analyticsModules
12
+ var analyticsModules = window.GOVUK.analyticsGa4.analyticsModules
13
13
  for (var property in analyticsModules) {
14
14
  var module = analyticsModules[property]
15
15
  if (typeof module.init === 'function') {
@@ -18,8 +18,8 @@ var initFunction = function () {
18
18
  }
19
19
  // to be added: cross domain tracking code
20
20
  } else {
21
- window.addEventListener('cookie-consent', window.GOVUK.analyticsGA4.init)
21
+ window.addEventListener('cookie-consent', window.GOVUK.analyticsGa4.init)
22
22
  }
23
23
  }
24
24
 
25
- window.GOVUK.analyticsGA4.init = initFunction
25
+ window.GOVUK.analyticsGa4.init = initFunction
@@ -128,8 +128,8 @@
128
128
  return string
129
129
  }
130
130
 
131
- GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
132
- GOVUK.analyticsGA4.PIIRemover = PIIRemover
131
+ GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
132
+ GOVUK.analyticsGa4.PIIRemover = PIIRemover
133
133
 
134
134
  global.GOVUK = GOVUK
135
135
  })(window)
@@ -5,5 +5,5 @@
5
5
  //= require ./analytics-ga4/ga4-page-views
6
6
  //= require ./analytics-ga4/ga4-link-tracker
7
7
  //= require ./analytics-ga4/ga4-event-tracker
8
- //= require ./analytics-ga4/ga4-enhanced-ecommerce-tracker
8
+ //= require ./analytics-ga4/ga4-ecommerce-tracker
9
9
  //= require ./analytics-ga4/init-ga4
@@ -59,11 +59,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
59
59
 
60
60
  // Navigate to and open accordions with anchored content on page load if a hash is present
61
61
  GemAccordion.prototype.openByAnchorOnLoad = function () {
62
+ if (!window.location.hash) return
62
63
  var splitHash = window.location.hash.split('#')[1]
63
-
64
- if (window.location.hash && document.getElementById(splitHash)) {
65
- this.openForAnchor(splitHash)
66
- }
64
+ this.openForAnchor(splitHash)
67
65
  }
68
66
 
69
67
  // Add event listeners for links to open accordion sections when navigated to using said anchor links on the page
@@ -80,7 +78,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
80
78
 
81
79
  // Find the parent accordion section for the given id and open it
82
80
  GemAccordion.prototype.openForAnchor = function (hash) {
83
- var target = document.getElementById(hash)
81
+ hash = hash.replace(':', '\\:')
82
+ var target = this.$module.querySelector('#' + hash)
83
+ if (!target) return
84
84
  var $section = this.getContainingSection(target)
85
85
  var $header = $section.querySelector(this.sectionHeader)
86
86
  var $expanded = this.getContainingSection($section)
@@ -28,11 +28,11 @@
28
28
 
29
29
  %>
30
30
 
31
- <%= content_tag('div', class: banner_classes, "aria-label": "emergency banner", "role": "region", "data-nosnippet": true ) do %>
31
+ <%= content_tag('section', class: banner_classes, "aria-labelledby": "emergency-banner-heading", "data-nosnippet": true ) do %>
32
32
  <div class="govuk-width-container">
33
33
  <div class="govuk-grid-row">
34
34
  <div class="govuk-grid-column-two-thirds">
35
- <%= content_tag('h2', class: heading_classes) do %>
35
+ <%= content_tag('h2', id: "emergency-banner-heading", class: heading_classes) do %>
36
36
  <%= heading %>
37
37
  <% end %>
38
38
  <% if short_description %>
@@ -187,7 +187,7 @@ examples:
187
187
 
188
188
  The `data_attributes` option applies attributes to the outermost element in the accordion. Each item can also have a `data_attributes` hash, which are placed on the `button` that triggers the opening and closing - useful for differentiating between each section of the accordion.
189
189
 
190
- Data attributes can be added to the 'Show/hide all' link using the `data_attributes_show_all` option, primarily where custom tracking is required. These attributes are read from the accordion markup and then added to the link by JavaScript (which is how the link is created). More details on how this can be used with the GA4 event tracking can be found in the 'Advanced' section of the [event tracking documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-gtm/ga4-event-tracker.md).
190
+ Data attributes can be added to the 'Show/hide all' link using the `data_attributes_show_all` option, primarily where custom tracking is required. These attributes are read from the accordion markup and then added to the link by JavaScript (which is how the link is created). More details on how this can be used with the GA4 event tracking can be found in the 'Advanced' section of the [event tracking documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-event-tracker.md).
191
191
 
192
192
  If `track_options` within `data_attributes_show_all` is set, then it is possible to pass a custom dimension when 'Show/Hide all' is clicked.
193
193
  data:
@@ -50,7 +50,7 @@ module GovukPublishingComponents
50
50
  "author" => {
51
51
  "@type" => "Organization",
52
52
  "name" => publishing_organisation["title"],
53
- "url" => Plek.current.website_root + publishing_organisation["base_path"],
53
+ "url" => Plek.new.website_root + publishing_organisation["base_path"],
54
54
  },
55
55
  }
56
56
  end
@@ -12,7 +12,7 @@ module GovukPublishingComponents
12
12
  end
13
13
 
14
14
  def canonical_url
15
- local_assigns[:canonical_url] || (Plek.current.website_root + content_item["base_path"])
15
+ local_assigns[:canonical_url] || (Plek.new.website_root + content_item["base_path"])
16
16
  end
17
17
 
18
18
  def body
@@ -5,7 +5,7 @@ module GovukPublishingComponents
5
5
  class PotentialSearchActionSchema
6
6
  attr_reader :facet_params, :description
7
7
 
8
- BASE_SEARCH_URL = "#{Plek.current.website_root}/search/all?keywords={query}&order=relevance".freeze
8
+ BASE_SEARCH_URL = "#{Plek.new.website_root}/search/all?keywords={query}&order=relevance".freeze
9
9
 
10
10
  def initialize(facet_params, description)
11
11
  @facet_params = facet_params
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "30.7.3".freeze
2
+ VERSION = "31.1.0".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: 30.7.3
4
+ version: 31.1.0
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: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -436,8 +436,8 @@ files:
436
436
  - app/assets/javascripts/component_guide/vendor/matches-polyfill.min.js
437
437
  - app/assets/javascripts/govuk_publishing_components/all_components.js
438
438
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
439
- - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js.erb
440
- - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-enhanced-ecommerce-tracker.js
439
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
440
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js
441
441
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
442
442
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js
443
443
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js
@@ -1361,7 +1361,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1361
1361
  - !ruby/object:Gem::Version
1362
1362
  version: '0'
1363
1363
  requirements: []
1364
- rubygems_version: 3.3.22
1364
+ rubygems_version: 3.3.23
1365
1365
  signing_key:
1366
1366
  specification_version: 4
1367
1367
  summary: A gem to document components in GOV.UK frontend applications