govuk_publishing_components 40.1.0 → 41.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +1 -79
  3. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +1 -34
  4. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +0 -17
  5. data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +0 -6
  6. data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +0 -7
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +8 -74
  8. data/app/assets/javascripts/govuk_publishing_components/dependencies.js +0 -4
  9. data/app/assets/javascripts/govuk_publishing_components/domain-config.js +0 -8
  10. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +0 -4
  11. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js +0 -14
  12. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +0 -20
  13. data/app/assets/javascripts/govuk_publishing_components/lib/toggle.js +0 -33
  14. data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +0 -25
  15. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +192 -171
  16. data/app/assets/stylesheets/component_guide/application.scss +10 -11
  17. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +1 -1
  18. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +2 -3
  19. data/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss +3 -3
  20. data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +1 -1
  21. data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +2 -2
  22. data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +47 -22
  23. data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +3 -3
  24. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-guidance.scss +1 -3
  25. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +2 -1
  26. data/app/assets/stylesheets/govuk_publishing_components/components/_cross-service-header.scss +19 -19
  27. data/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +14 -10
  28. data/app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss +3 -3
  29. data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +2 -2
  30. data/app/assets/stylesheets/govuk_publishing_components/components/_error-summary.scss +1 -1
  31. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +8 -8
  32. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +16 -10
  33. data/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss +2 -2
  34. data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +2 -2
  35. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +33 -35
  36. data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +3 -3
  37. data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +1 -1
  38. data/app/assets/stylesheets/govuk_publishing_components/components/_notice.scss +1 -1
  39. data/app/assets/stylesheets/govuk_publishing_components/components/_option-select.scss +3 -3
  40. data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +13 -3
  41. data/app/assets/stylesheets/govuk_publishing_components/components/_panel.scss +1 -1
  42. data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +6 -6
  43. data/app/assets/stylesheets/govuk_publishing_components/components/_reorderable-list.scss +2 -3
  44. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +4 -3
  45. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +2 -3
  46. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +3 -4
  47. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +3 -3
  48. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +10 -10
  49. data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +1 -1
  50. data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +1 -1
  51. data/app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss +3 -3
  52. data/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss +1 -1
  53. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_attachment.scss +5 -4
  54. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +1 -1
  55. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_highlight-answer.scss +2 -2
  56. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_stat-headline.scss +2 -2
  57. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +1 -1
  58. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_warning-callout.scss +1 -1
  59. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +5 -5
  60. data/app/views/govuk_publishing_components/components/_accordion.html.erb +1 -8
  61. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +1 -1
  62. data/app/views/govuk_publishing_components/components/_cards.html.erb +6 -11
  63. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +2 -15
  64. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +3 -19
  65. data/app/views/govuk_publishing_components/components/_details.html.erb +9 -11
  66. data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -5
  67. data/app/views/govuk_publishing_components/components/_intervention.html.erb +4 -4
  68. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +7 -21
  69. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +1 -26
  70. data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -5
  71. data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -7
  72. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +0 -10
  73. data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +1 -3
  74. data/app/views/govuk_publishing_components/components/_search.html.erb +0 -1
  75. data/app/views/govuk_publishing_components/components/_select.html.erb +1 -2
  76. data/app/views/govuk_publishing_components/components/_share_links.html.erb +1 -10
  77. data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +0 -1
  78. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +1 -1
  79. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +1 -24
  80. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +1 -14
  81. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +1 -4
  82. data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +0 -1
  83. data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +1 -7
  84. data/app/views/govuk_publishing_components/components/docs/accordion.yml +1 -60
  85. data/app/views/govuk_publishing_components/components/docs/big_number.yml +2 -6
  86. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +0 -1
  87. data/app/views/govuk_publishing_components/components/docs/button.yml +1 -1
  88. data/app/views/govuk_publishing_components/components/docs/cards.yml +41 -20
  89. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +0 -33
  90. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -2
  91. data/app/views/govuk_publishing_components/components/docs/details.yml +0 -15
  92. data/app/views/govuk_publishing_components/components/docs/document_list.yml +11 -18
  93. data/app/views/govuk_publishing_components/components/docs/error_alert.yml +1 -1
  94. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +0 -11
  95. data/app/views/govuk_publishing_components/components/docs/image_card.yml +0 -31
  96. data/app/views/govuk_publishing_components/components/docs/intervention.yml +0 -26
  97. data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +2 -2
  98. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +0 -2
  99. data/app/views/govuk_publishing_components/components/docs/option_select.yml +4 -16
  100. data/app/views/govuk_publishing_components/components/docs/organisation_logo.yml +0 -15
  101. data/app/views/govuk_publishing_components/components/docs/print_link.yml +2 -9
  102. data/app/views/govuk_publishing_components/components/docs/select.yml +0 -36
  103. data/app/views/govuk_publishing_components/components/docs/share_links.yml +2 -4
  104. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +2 -25
  105. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +0 -23
  106. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +0 -10
  107. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +3 -15
  108. data/app/views/govuk_publishing_components/components/docs/table.yml +1 -1
  109. data/app/views/govuk_publishing_components/components/docs/tabs.yml +1 -1
  110. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +3 -27
  111. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +1 -5
  112. data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +0 -2
  113. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +0 -10
  114. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  115. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +0 -5
  116. data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +0 -7
  117. data/lib/govuk_publishing_components/presenters/breadcrumbs_helper.rb +1 -19
  118. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +1 -15
  119. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +2 -24
  120. data/lib/govuk_publishing_components/presenters/select_helper.rb +0 -4
  121. data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +0 -5
  122. data/lib/govuk_publishing_components/presenters/translation_nav_helper.rb +0 -7
  123. data/lib/govuk_publishing_components/version.rb +1 -1
  124. metadata +4 -26
  125. data/app/assets/javascripts/govuk_publishing_components/analytics/analytics.js +0 -92
  126. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +0 -221
  127. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +0 -30
  128. data/app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js +0 -55
  129. data/app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js +0 -133
  130. data/app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js +0 -46
  131. data/app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js +0 -101
  132. data/app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js +0 -51
  133. data/app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js +0 -88
  134. data/app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js +0 -68
  135. data/app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js +0 -220
  136. data/app/assets/javascripts/govuk_publishing_components/analytics/init.js +0 -60
  137. data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +0 -135
  138. data/app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js +0 -43
  139. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +0 -160
  140. data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +0 -115
  141. data/app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js +0 -39
  142. data/app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js +0 -132
  143. data/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +0 -75
  144. data/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +0 -56
  145. data/app/assets/javascripts/govuk_publishing_components/analytics.js +0 -23
  146. data/app/assets/javascripts/govuk_publishing_components/components/details.js +0 -48
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: 40.1.0
4
+ version: 41.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: 2024-07-30 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -432,27 +432,6 @@ files:
432
432
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-video-tracker.js
433
433
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
434
434
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js
435
- - app/assets/javascripts/govuk_publishing_components/analytics.js
436
- - app/assets/javascripts/govuk_publishing_components/analytics/analytics.js
437
- - app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js
438
- - app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js
439
- - app/assets/javascripts/govuk_publishing_components/analytics/cross-domain-tracking.js
440
- - app/assets/javascripts/govuk_publishing_components/analytics/custom-dimensions.js
441
- - app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
442
- - app/assets/javascripts/govuk_publishing_components/analytics/ecommerce.js
443
- - app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
444
- - app/assets/javascripts/govuk_publishing_components/analytics/explicit-cross-domain-links.js
445
- - app/assets/javascripts/govuk_publishing_components/analytics/external-link-tracker.js
446
- - app/assets/javascripts/govuk_publishing_components/analytics/google-analytics-universal-tracker.js
447
- - app/assets/javascripts/govuk_publishing_components/analytics/init.js
448
- - app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js
449
- - app/assets/javascripts/govuk_publishing_components/analytics/mailto-link-tracker.js
450
- - app/assets/javascripts/govuk_publishing_components/analytics/page-content.js
451
- - app/assets/javascripts/govuk_publishing_components/analytics/pii.js
452
- - app/assets/javascripts/govuk_publishing_components/analytics/print-intent.js
453
- - app/assets/javascripts/govuk_publishing_components/analytics/static-analytics.js
454
- - app/assets/javascripts/govuk_publishing_components/analytics/track-click.js
455
- - app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js
456
435
  - app/assets/javascripts/govuk_publishing_components/components/accordion.js
457
436
  - app/assets/javascripts/govuk_publishing_components/components/button.js
458
437
  - app/assets/javascripts/govuk_publishing_components/components/character-count.js
@@ -461,7 +440,6 @@ files:
461
440
  - app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js
462
441
  - app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js
463
442
  - app/assets/javascripts/govuk_publishing_components/components/cross-service-header.js
464
- - app/assets/javascripts/govuk_publishing_components/components/details.js
465
443
  - app/assets/javascripts/govuk_publishing_components/components/error-summary.js
466
444
  - app/assets/javascripts/govuk_publishing_components/components/feedback.js
467
445
  - app/assets/javascripts/govuk_publishing_components/components/govspeak.js
@@ -1859,14 +1837,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
1859
1837
  requirements:
1860
1838
  - - ">="
1861
1839
  - !ruby/object:Gem::Version
1862
- version: '3.1'
1840
+ version: '3.2'
1863
1841
  required_rubygems_version: !ruby/object:Gem::Requirement
1864
1842
  requirements:
1865
1843
  - - ">="
1866
1844
  - !ruby/object:Gem::Version
1867
1845
  version: '0'
1868
1846
  requirements: []
1869
- rubygems_version: 3.5.16
1847
+ rubygems_version: 3.5.17
1870
1848
  signing_key:
1871
1849
  specification_version: 4
1872
1850
  summary: A gem to document components in GOV.UK frontend applications
@@ -1,92 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
- // For usage and initialisation see:
6
- // https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics/analytics.md
7
-
8
- var Analytics = function (config) {
9
- this.pii = new GOVUK.Pii()
10
- this.trackers = []
11
- if (typeof config.universalId !== 'undefined') {
12
- var universalId = config.universalId
13
- delete config.universalId
14
- this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
15
- }
16
- }
17
-
18
- var PIISafe = function (value) {
19
- this.value = value
20
- }
21
- Analytics.PIISafe = PIISafe
22
-
23
- Analytics.prototype.sendToTrackers = function (method, args) {
24
- // Allows us to stop sending tracking at the moment a user sets their usage cookies to "false" on the cookie settings page.
25
- if (window.GOVUK.stopSendingAnalytics) {
26
- return false
27
- }
28
-
29
- for (var i = 0, l = this.trackers.length; i < l; i++) {
30
- var tracker = this.trackers[i]
31
- var fn = tracker[method]
32
-
33
- if (typeof fn === 'function') {
34
- fn.apply(tracker, args)
35
- }
36
- }
37
- }
38
-
39
- Analytics.load = function () {
40
- GOVUK.GoogleAnalyticsUniversalTracker.load()
41
- }
42
-
43
- Analytics.prototype.defaultPathForTrackPageview = function (location) {
44
- // Get the page path including querystring, but ignoring the anchor
45
- // as per default behaviour of GA (see: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages#overview)
46
- // we ignore the possibility of there being campaign variables in the
47
- // anchor because we wouldn't know how to detect and parse them if they
48
- // were present
49
- // IE can't access window.location.origin, so we have to do this slightly complex thing
50
- var root = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '')
51
- return this.pii.stripPIIFromString(location.href.substring(root.length).split('#')[0])
52
- }
53
-
54
- Analytics.prototype.trackPageview = function (path, title, options) {
55
- arguments[0] = arguments[0] || this.defaultPathForTrackPageview(window.location)
56
- if (arguments.length === 0) { arguments.length = 1 }
57
- return this.sendToTrackers('trackPageview', this.pii.stripPII(arguments))
58
- }
59
-
60
- /*
61
- https://developers.google.com/analytics/devguides/collection/analyticsjs/events
62
- options.label – Useful for categorizing events (eg nav buttons)
63
- options.value – Values must be non-negative. Useful to pass counts
64
- options.nonInteraction – Prevent event from impacting bounce rate
65
- */
66
- Analytics.prototype.trackEvent = function (category, action, options) {
67
- return this.sendToTrackers('trackEvent', this.pii.stripPII(arguments))
68
- }
69
-
70
- Analytics.prototype.trackShare = function (network, options) {
71
- return this.sendToTrackers('trackSocial', this.pii.stripPII([network, 'share', global.location.pathname, options]))
72
- }
73
-
74
- /*
75
- The custom dimension index must be configured within the
76
- Universal Analytics profile
77
- */
78
- Analytics.prototype.setDimension = function (index, value) {
79
- return this.sendToTrackers('setDimension', this.pii.stripPII(arguments))
80
- }
81
-
82
- /*
83
- Add a beacon to track a page in another GA account on another domain.
84
- */
85
- Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
86
- return this.sendToTrackers('addLinkedTrackerDomain', arguments)
87
- }
88
-
89
- GOVUK.Analytics = Analytics
90
-
91
- global.GOVUK = GOVUK
92
- })(window)
@@ -1,221 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {}
3
- window.GOVUK.analyticsVars = window.GOVUK.analyticsVars || {};
4
-
5
- (function (Modules) {
6
- function AutoScrollTracker ($module) {
7
- this.$module = $module
8
- this.pageHeight = document.querySelector('body').clientHeight
9
- this.trackedNodes = []
10
- this.config = {
11
- allowHeadingsInside: ['main'],
12
- percentages: [20, 40, 60, 80, 100],
13
- scrollTimeoutDelay: 20,
14
- resizeTimeoutDelay: 100,
15
- pageHeightTimeoutDelay: 500
16
- }
17
- }
18
-
19
- AutoScrollTracker.prototype.init = function () {
20
- var consentCookie = window.GOVUK.getConsentCookie()
21
-
22
- if (consentCookie && consentCookie.usage) {
23
- this.startModule()
24
- } else {
25
- this.start = this.startModule.bind(this)
26
- window.addEventListener('cookie-consent', this.start)
27
- }
28
- }
29
-
30
- AutoScrollTracker.prototype.startModule = function () {
31
- window.removeEventListener('cookie-consent', this.start)
32
- if (window.GOVUK.analyticsVars.scrollTrackerStarted) {
33
- return
34
- }
35
-
36
- this.trackType = this.$module.getAttribute('data-track-type')
37
- var trackHeadings = this.$module.getAttribute('data-track-headings')
38
- if (trackHeadings) {
39
- try {
40
- this.config.trackHeadings = JSON.parse(trackHeadings)
41
- } catch (e) {
42
- // if there's a problem with the config, don't start the tracker
43
- console.error('Scroll tracker configuration error: ' + e.message, window.location)
44
- window.GOVUK.analyticsVars.scrollTrackerStarted = false
45
- return
46
- }
47
- }
48
-
49
- window.GOVUK.analyticsVars.scrollTrackerStarted = true
50
-
51
- if (this.trackType === 'headings') {
52
- this.track = new AutoScrollTracker.Heading(this.config)
53
- } else {
54
- this.track = new AutoScrollTracker.Percentage(this.config)
55
- }
56
-
57
- this.getWindowDetails()
58
- // if the URL has a hash we want to prevent tracking on initial page load
59
- // until the browser jumps down the page, at which point a scroll event
60
- // will happen and tracking will continue normally
61
- var windowHash = window.location.hash
62
- var dontTrackOnLoad = windowHash && document.getElementById(windowHash.substring(1))
63
- if (!dontTrackOnLoad) {
64
- this.trackVisibleNodes()
65
- }
66
-
67
- if (this.trackedNodes.length) {
68
- // store event listener functions as variables so they can be removed if needed
69
- this.scrollEvent = this.onScroll.bind(this)
70
- window.addEventListener('scroll', this.scrollEvent)
71
- this.resizeEvent = this.onResize.bind(this)
72
- window.addEventListener('resize', this.resizeEvent)
73
-
74
- // check if the page height changes e.g. accordion opened
75
- this.interval = window.setInterval(function () {
76
- var pageHeight = document.querySelector('body').clientHeight
77
- if (pageHeight !== this.pageHeight) {
78
- this.pageHeight = pageHeight
79
- this.getWindowDetails()
80
- this.trackVisibleNodes()
81
- }
82
- }.bind(this), this.config.pageHeightTimeoutDelay)
83
- }
84
- }
85
-
86
- AutoScrollTracker.prototype.onScroll = function () {
87
- clearTimeout(this.scrollTimeout)
88
- this.scrollTimeout = setTimeout(function () {
89
- this.trackVisibleNodes()
90
- }.bind(this), this.config.scrollTimeoutDelay)
91
- }
92
-
93
- AutoScrollTracker.prototype.onResize = function () {
94
- clearTimeout(this.resizeTimeout)
95
- this.resizeTimeout = setTimeout(function () {
96
- this.getWindowDetails()
97
- this.trackVisibleNodes()
98
- }.bind(this), this.config.resizeTimeoutDelay)
99
- }
100
-
101
- AutoScrollTracker.prototype.getWindowDetails = function () {
102
- this.pageHeight = document.querySelector('body').clientHeight
103
- this.windowHeight = window.innerHeight
104
- this.trackedNodes = this.track.getTrackingNodes(this.trackedNodes)
105
- }
106
-
107
- AutoScrollTracker.prototype.trackVisibleNodes = function () {
108
- for (var i = 0; i < this.trackedNodes.length; i++) {
109
- var node = this.trackedNodes[i]
110
- if (this.isVisible(node.top, node.bottom) && !node.alreadySeen) {
111
- node.alreadySeen = true
112
- // we store whether a heading has been tracked or not on the heading
113
- // because if headings appear/disapper (e.g. inside an accordion)
114
- // the order changes, so we can't refer to the previous trackedNodes
115
- // as we do with percentages
116
- if (node.node) {
117
- node.node.setAttribute('data-autoscrolltracker-already-seen', true)
118
- }
119
-
120
- var action = node.eventData.action
121
- var label = node.eventData.label
122
-
123
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
124
- window.GOVUK.analytics.trackEvent('ScrollTo', action, { label: label, nonInteraction: true })
125
- }
126
- }
127
- }
128
- }
129
-
130
- AutoScrollTracker.prototype.isVisible = function (top, bottom) {
131
- var scroll = window.scrollY || document.documentElement.scrollTop // IE fallback
132
- return scroll <= top && (scroll + this.windowHeight) >= bottom
133
- }
134
-
135
- AutoScrollTracker.Heading = function (config) {
136
- this.config = config
137
- }
138
-
139
- AutoScrollTracker.Heading.prototype.getTrackingNodes = function () {
140
- var headingsDetails = []
141
- var headingsFound = this.findAllowedHeadings()
142
-
143
- for (var i = 0; i < headingsFound.length; i++) {
144
- var heading = headingsFound[i]
145
- // only track headings that are visible i.e. not inside display: none
146
- if (this.visible(heading)) {
147
- var pos = heading.getBoundingClientRect()
148
- headingsDetails.push({
149
- node: heading,
150
- alreadySeen: heading.getAttribute('data-autoscrolltracker-already-seen'),
151
- top: pos.top + document.documentElement.scrollTop,
152
- bottom: pos.bottom + document.documentElement.scrollTop,
153
- eventData: { action: 'Heading', label: heading.textContent.replace(/\s+/g, ' ').trim() }
154
- })
155
- }
156
- }
157
- return headingsDetails
158
- }
159
-
160
- // check heading is inside allowed elements, generally ignores everything outside of page content
161
- AutoScrollTracker.Heading.prototype.findAllowedHeadings = function () {
162
- var headingsFound = []
163
- var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
164
- var trackHeadings = this.config.trackHeadings
165
-
166
- // this is a loop that only happens once as we currently only have one
167
- // allowed element for headings to be in - 'main'
168
- for (var h = 0; h < this.config.allowHeadingsInside.length; h++) {
169
- var insideElements = document.querySelectorAll(this.config.allowHeadingsInside[h])
170
- for (var e = 0; e < insideElements.length; e++) {
171
- var found = insideElements[e].querySelectorAll(headings)
172
- for (var f = 0; f < found.length; f++) {
173
- if (trackHeadings) {
174
- if (trackHeadings.includes(found[f].textContent.trim())) {
175
- headingsFound.push(found[f])
176
- }
177
- } else {
178
- headingsFound.push(found[f])
179
- }
180
- }
181
- }
182
- }
183
- return headingsFound
184
- }
185
-
186
- // this is bit more verbose than checking offsetParent !== null but more reliable for IE10+
187
- AutoScrollTracker.Heading.prototype.visible = function (el) {
188
- return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length)
189
- }
190
-
191
- AutoScrollTracker.Percentage = function (config) {
192
- this.config = config
193
- }
194
-
195
- AutoScrollTracker.Percentage.prototype.getTrackingNodes = function (trackedNodes) {
196
- var body = document.body
197
- var html = document.documentElement
198
- var pageHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight)
199
-
200
- var percentDetails = []
201
-
202
- for (var i = 0; i < this.config.percentages.length; i++) {
203
- var percent = this.config.percentages[i]
204
- // subtract 1 pixel to solve a bug where 100% can't be reached in some cases
205
- var pos = ((pageHeight / 100) * percent) - 1
206
- var alreadySeen = false
207
- if (trackedNodes.length) {
208
- alreadySeen = trackedNodes[i].alreadySeen
209
- }
210
- percentDetails.push({
211
- alreadySeen: alreadySeen,
212
- top: pos,
213
- bottom: pos,
214
- eventData: { action: 'Percent', label: String(percent) }
215
- })
216
- }
217
- return percentDetails
218
- }
219
-
220
- Modules.AutoScrollTracker = AutoScrollTracker
221
- })(window.GOVUK.Modules)
@@ -1,30 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {};
3
-
4
- (function (Modules) {
5
- function AutoTrackEvent ($module) {
6
- this.$module = $module
7
- }
8
-
9
- AutoTrackEvent.prototype.init = function () {
10
- var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
11
- var category = this.$module.getAttribute('data-track-category')
12
- var action = this.$module.getAttribute('data-track-action')
13
- var label = this.$module.getAttribute('data-track-label')
14
- var value = parseInt(this.$module.getAttribute('data-track-value'))
15
-
16
- if (typeof label === 'string') {
17
- options.label = label
18
- }
19
-
20
- if (value || value === 0) {
21
- options.value = value
22
- }
23
-
24
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
25
- window.GOVUK.analytics.trackEvent(category, action, options)
26
- }
27
- }
28
-
29
- Modules.AutoTrackEvent = AutoTrackEvent
30
- })(window.GOVUK.Modules)
@@ -1,55 +0,0 @@
1
- window.GOVUK = window.GOVUK || {}
2
- window.GOVUK.Modules = window.GOVUK.Modules || {};
3
-
4
- (function (Modules) {
5
- function CrossDomainTracking ($module) {
6
- this.$module = $module
7
- Modules.crossDomainLinkedTrackers = Modules.crossDomainLinkedTrackers || []
8
- }
9
-
10
- CrossDomainTracking.prototype.init = function () {
11
- if (this.isTrackable(this.$module)) {
12
- this.addLinkedTrackerDomain(this.$module)
13
- } else {
14
- this.findTrackableElements()
15
- }
16
- }
17
-
18
- CrossDomainTracking.prototype.isTrackable = function (element) {
19
- if (element.getAttribute('href') && element.getAttribute('data-tracking-code') && element.getAttribute('data-tracking-name')) {
20
- return true
21
- }
22
- }
23
-
24
- CrossDomainTracking.prototype.findTrackableElements = function () {
25
- var links = this.$module.querySelectorAll('a')
26
- for (var i = 0; i < links.length; i++) {
27
- if (this.isTrackable(links[i])) {
28
- this.addLinkedTrackerDomain(links[i])
29
- }
30
- }
31
- }
32
-
33
- CrossDomainTracking.prototype.addLinkedTrackerDomain = function (element) {
34
- var name = element.getAttribute('data-tracking-name')
35
- var code = element.getAttribute('data-tracking-code')
36
- var trackEvent = (element.getAttribute('data-tracking-track-event') === 'true')
37
-
38
- if (window.GOVUK.analytics !== 'undefined') {
39
- if (Modules.crossDomainLinkedTrackers.indexOf(name) === -1) {
40
- var hostname = element.hostname
41
- window.GOVUK.analytics.addLinkedTrackerDomain(code, name, hostname)
42
- Modules.crossDomainLinkedTrackers.push(name)
43
- }
44
-
45
- if (trackEvent) {
46
- element.addEventListener('click', function (e) {
47
- var target = e.target
48
- window.GOVUK.analytics.trackEvent('External Link Clicked', target.textContent, { trackerName: name })
49
- })
50
- }
51
- }
52
- }
53
-
54
- Modules.CrossDomainTracking = CrossDomainTracking
55
- })(window.GOVUK.Modules)
@@ -1,133 +0,0 @@
1
- /* global GOVUK */
2
-
3
- (function () {
4
- 'use strict'
5
- window.GOVUK = window.GOVUK || {}
6
- var CustomDimensions = function () { }
7
-
8
- CustomDimensions.getAndExtendDefaultTrackingOptions = function (extraOptions) {
9
- var trackingOptions = this.customDimensions()
10
- return GOVUK.extendObject(trackingOptions, extraOptions)
11
- }
12
-
13
- CustomDimensions.customDimensions = function () {
14
- var dimensions = GOVUK.extendObject(
15
- {},
16
- customDimensionsFromBrowser(),
17
- customDimensionsFromMetaTags(),
18
- customDimensionsFromDom(),
19
- abTestCustomDimensions()
20
- )
21
-
22
- for (var key in dimensions) {
23
- dimensions[key] = new GOVUK.Analytics.PIISafe(String(dimensions[key]))
24
- }
25
- return dimensions
26
- }
27
-
28
- function customDimensionsFromBrowser () {
29
- var customDimensions = {
30
- dimension15: window.httpStatusCode || 200,
31
- dimension16: GOVUK.cookie('TLSversion') || 'unknown',
32
- dimension95: GOVUK.analytics.gaClientId
33
- }
34
-
35
- if (window.devicePixelRatio) {
36
- customDimensions.dimension11 = window.devicePixelRatio
37
- } else {
38
- customDimensions.dimension11 = window.screen.deviceXDPI / window.screen.logicalXDPI
39
- }
40
-
41
- return customDimensions
42
- }
43
-
44
- function customDimensionsFromMetaTags () {
45
- var dimensionMappings = {
46
- section: { dimension: 1 },
47
- format: { dimension: 2 },
48
- themes: { dimension: 3, defaultValue: 'other' },
49
- 'content-id': { dimension: 4, defaultValue: '00000000-0000-0000-0000-000000000000' },
50
- 'search-result-count': { dimension: 5 },
51
- 'publishing-government': { dimension: 6 },
52
- 'political-status': { dimension: 7 },
53
- 'analytics:organisations': { dimension: 9 },
54
- 'analytics:world-locations': { dimension: 10 },
55
- withdrawn: { dimension: 12, defaultValue: 'not withdrawn' },
56
- 'schema-name': { dimension: 17 },
57
- 'rendering-application': { dimension: 20 },
58
- 'search-autocomplete-status': { dimension: 21 },
59
- 'navigation-legacy': { dimension: 30, defaultValue: 'none' },
60
- 'navigation-list-type': { dimension: 31, defaultValue: 'none' },
61
- 'navigation-page-type': { dimension: 32, defaultValue: 'none' },
62
- 'taxon-slug': { dimension: 56, defaultValue: 'other' },
63
- 'taxon-id': { dimension: 57, defaultValue: 'other' },
64
- 'taxon-slugs': { dimension: 58, defaultValue: 'other' },
65
- 'taxon-ids': { dimension: 59, defaultValue: 'other' },
66
- 'content-has-history': { dimension: 39, defaultValue: 'false' },
67
- 'publishing-app': { dimension: 89 },
68
- 'brexit-audience': { dimension: 112 },
69
- 'brexit-superbreadcrumb': { dimension: 111 },
70
- stepnavs: { dimension: 96 },
71
- 'relevant-result-shown': { dimension: 83 },
72
- 'spelling-suggestion': { dimension: 81 }
73
- }
74
-
75
- var metas = document.querySelectorAll("meta[name^='govuk']")
76
- var customDimensions = {}
77
- var tags = {}
78
-
79
- for (var i = 0; i < metas.length; i++) {
80
- var meta = metas[i]
81
- var metaKey = meta.getAttribute('name').split('govuk:')[1]
82
- var dimension = dimensionMappings[metaKey]
83
- if (dimension) {
84
- tags[metaKey] = meta.getAttribute('content')
85
- }
86
- }
87
-
88
- for (var key in dimensionMappings) {
89
- var value = tags[key] || dimensionMappings[key].defaultValue
90
- if (typeof value !== 'undefined') {
91
- customDimensions['dimension' + dimensionMappings[key].dimension] = value
92
- }
93
- }
94
-
95
- return customDimensions
96
- }
97
-
98
- function customDimensionsFromDom () {
99
- var mainLang = document.getElementById('content')
100
- if (mainLang) {
101
- mainLang = mainLang.getAttribute('lang')
102
- }
103
- var globalBar = document.querySelector('[data-module="global-bar"]') || false
104
- if (globalBar) {
105
- globalBar = globalBar.style.display !== 'none'
106
- }
107
- return {
108
- dimension26: GOVUK.PageContent.getNumberOfSections(),
109
- dimension27: GOVUK.PageContent.getNumberOfLinks(),
110
- dimension23: mainLang || 'unknown',
111
- dimension38: globalBar && 'Global Banner viewed'
112
- }
113
- }
114
-
115
- function abTestCustomDimensions () {
116
- var abMetas = document.querySelectorAll("meta[name^='govuk:ab-test']")
117
- var customDimensions = {}
118
-
119
- for (var i = 0; i < abMetas.length; i++) {
120
- var meta = abMetas[i]
121
- var dimension = parseInt(meta.getAttribute('data-analytics-dimension'))
122
- var testNameAndBucket = meta.getAttribute('content')
123
-
124
- if (dimension) {
125
- customDimensions['dimension' + dimension] = testNameAndBucket
126
- }
127
- }
128
-
129
- return customDimensions
130
- }
131
-
132
- GOVUK.CustomDimensions = CustomDimensions
133
- })()
@@ -1,46 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var GOVUK = global.GOVUK || {}
5
-
6
- GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
7
- GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
8
- options = options || {}
9
- var downloadLinkSelector = options.selector
10
- var selectors = downloadLinkSelector.split(',')
11
-
12
- if (downloadLinkSelector) {
13
- document.querySelector('body').addEventListener('click', function (event) {
14
- var element = event.target
15
- if (element.tagName !== 'A') {
16
- element = element.closest('a')
17
- }
18
-
19
- if (!element) {
20
- return
21
- }
22
-
23
- for (var i = 0; i < selectors.length; i++) {
24
- if (element.matches(selectors[i].trim())) {
25
- trackDownload(element)
26
- break
27
- }
28
- }
29
- })
30
- }
31
-
32
- function trackDownload (element) {
33
- var href = element.getAttribute('href')
34
- var evtOptions = { transport: 'beacon' }
35
- var linkText = element.textContent.trim()
36
-
37
- if (linkText) {
38
- evtOptions.label = linkText
39
- }
40
-
41
- GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
42
- }
43
- }
44
-
45
- global.GOVUK = GOVUK
46
- })(window)