govuk_publishing_components 35.13.0 → 35.13.2

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: b6417c1bd3d66d89500aac39c49427caa95791623fe26f1ee4844c025ef3f3c7
4
- data.tar.gz: d21986e9895007dc2560b4aacd1eb28ff7f43251519029672b85d13d91211d94
3
+ metadata.gz: d89a426d686fe0891582f8851ff7b27c57a457b838dccd81aa07a4868a9a9975
4
+ data.tar.gz: b267048c6e6bd91689fcedbad4e16835de62ff50aee68e94684ec4533ad7c5ab
5
5
  SHA512:
6
- metadata.gz: 7ca4a123db1c519256eb7ee46ff97e940d69c161f687611fb3b46915acee3454b995f2793e763ed82f5d87ae8a32d2df074b4c72587ca5c0a3c02ee858026a79
7
- data.tar.gz: b1cc9c87e984de69229d5b6807d81eca27802b35a3be15caaaea249388fc0ce9934be7a4d75006e2a93c5374fc48738d9f8e8dbbc624955b2a14da78a01df8a8
6
+ metadata.gz: 9dcd81b321da508d0475825320afa9674bfbac1bf1ef73f5ce32ccd66d0f5225e08b569a9819ca34672c13e919e154e02570b51109613e53d9bc79945a0f3482
7
+ data.tar.gz: 24bf0744fc140a4644c5b12d0de816869298a1927a25e3b1e126d0644b4bae78cd6ae5409d194e48465429e049517440321d39b12edd1ee783e717f54446659f
@@ -241,7 +241,8 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
241
241
 
242
242
  try {
243
243
  var ga4LinkData = JSON.parse(module.getAttribute('data-ga4-link'))
244
- ga4LinkData.index_total = totalLinks
244
+ // use index_total if it already exists, otherwise calculate it and set it
245
+ ga4LinkData.index_total = ga4LinkData.index_total || totalLinks
245
246
  module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
246
247
  } catch (e) {
247
248
  // if there's a problem with the config, don't start the tracker
@@ -84,12 +84,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
84
84
  var labelText = input.label.innerText || input.label.textContent
85
85
  var inputType = elem.getAttribute('type')
86
86
  var inputNodename = elem.nodeName
87
+ var inputTypes = ['text', 'search', 'email', 'number']
87
88
 
88
89
  if (inputType === 'checkbox' && elem.checked) {
89
90
  input.answer = labelText
90
91
  } else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex].value) {
91
92
  input.answer = elem.options[elem.selectedIndex].text
92
- } else if ((inputType === 'text' || inputType === 'search') && elem.value) {
93
+ } else if (inputTypes.indexOf(inputType) !== -1 && elem.value) {
93
94
  if (this.includeTextInputValues) {
94
95
  var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
95
96
  input.answer = PIIRemover.stripPIIWithOverride(elem.value, true, true)
@@ -21,6 +21,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
21
21
  title: this.getTitle(),
22
22
  status_code: this.getStatusCode(),
23
23
 
24
+ ab_test: this.getMetaContent('ab-test'),
24
25
  document_type: this.getMetaContent('format'),
25
26
  publishing_app: this.getMetaContent('publishing-app'),
26
27
  rendering_app: this.getMetaContent('rendering-app'),
@@ -28,6 +29,9 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
28
29
  content_id: this.getMetaContent('content-id'),
29
30
 
30
31
  browse_topic: this.getMetaContent('section'),
32
+ navigation_page_type: this.getMetaContent('navigation-page-type'),
33
+ navigation_list_type: this.getMetaContent('navigation-list-type'),
34
+ step_navs: this.getMetaContent('stepnavs'),
31
35
  taxonomy_level1: this.getMetaContent('themes'),
32
36
  taxonomy_main: this.getMetaContent('taxon-slug'),
33
37
  taxonomy_main_id: this.getMetaContent('taxon-id'),
@@ -29,7 +29,10 @@
29
29
  link_domain: this.undefined,
30
30
  link_path_parts: this.undefined,
31
31
  tool_name: this.undefined,
32
- percent_scrolled: this.undefined
32
+ percent_scrolled: this.undefined,
33
+ video_current_time: this.undefined,
34
+ video_duration: this.undefined,
35
+ video_percent: this.undefined
33
36
  }
34
37
  }
35
38
  }
@@ -60,6 +60,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
60
60
  window.addEventListener('scroll', this.scrollEvent)
61
61
  this.resizeEvent = this.onResize.bind(this)
62
62
  window.addEventListener('resize', this.resizeEvent)
63
+ this.resetEvent = this.onReset.bind(this)
64
+ window.addEventListener('dynamic-page-update', this.resetEvent)
63
65
 
64
66
  // check if the page height changes e.g. accordion opened
65
67
  this.interval = window.setInterval(function () {
@@ -115,6 +117,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
115
117
  data.type = node.eventData.type
116
118
  // following will be undefined if tracking percentages
117
119
  data.text = node.eventData.text
120
+ data.section = node.eventData.text
118
121
  data.index = node.eventData.index
119
122
  // following will be undefined if tracking headings
120
123
  data.percent_scrolled = node.eventData.percent_scrolled
@@ -131,6 +134,14 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
131
134
  return scroll <= top && (scroll + this.windowHeight) >= bottom
132
135
  }
133
136
 
137
+ // if reset, we set all nodes 'alreadySeen' to false
138
+ // used when the page content is dynamically updated e.g. search
139
+ Ga4ScrollTracker.prototype.onReset = function () {
140
+ for (var i = 0; i < this.trackedNodes.length; i++) {
141
+ this.trackedNodes[i].alreadySeen = false
142
+ }
143
+ }
144
+
134
145
  Ga4ScrollTracker.Heading = function (config) {
135
146
  this.config = config
136
147
  }
@@ -0,0 +1,88 @@
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
3
+ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
4
+
5
+ (function (analyticsModules) {
6
+ 'use strict'
7
+
8
+ var VideoTracker = {
9
+ init: function () {
10
+ this.handlers = {}
11
+ },
12
+
13
+ configureVideo: function (event) {
14
+ var player = event.target
15
+ var videoId = player.id
16
+ var duration = player.getDuration()
17
+ var percentages = [25, 50, 75]
18
+
19
+ for (var i = 0; i < percentages.length; i++) {
20
+ var percent = percentages[i]
21
+ var position = (duration / 100) * percent
22
+ this.handlers['video-' + videoId + '-' + percent + '-percent-begin'] = position
23
+ // interval is once a second, so end point must be at least one second beyond begin point
24
+ this.handlers['video-' + videoId + '-' + percent + '-percent-end'] = position + 2
25
+ }
26
+ },
27
+
28
+ trackVideo: function (event, state) {
29
+ var videoTracker = window.GOVUK.analyticsGa4.analyticsModules.VideoTracker
30
+ var player = event.target
31
+ var videoId = player.id
32
+ clearInterval(videoTracker.handlers['video-' + videoId])
33
+
34
+ if (state === 'VideoUnstarted') {
35
+ videoTracker.handlers['video-' + videoId] = setInterval(videoTracker.checkProgress, 1000, player)
36
+ videoTracker.sendData(player, 'start', 0) // VideoUnstarted seems to only happen the first time video is played
37
+ } else if (state === 'VideoPlaying') {
38
+ videoTracker.handlers['video-' + videoId] = setInterval(videoTracker.checkProgress, 1000, player)
39
+ } else if (state === 'VideoEnded') {
40
+ if (!videoTracker.handlers['video-' + videoId + '-100']) {
41
+ videoTracker.sendData(player, 'complete', 100)
42
+ videoTracker.handlers['video-' + videoId + '-100'] = true
43
+ }
44
+ }
45
+ },
46
+
47
+ checkProgress: function (player) {
48
+ var videoId = player.id
49
+ var videoTracker = window.GOVUK.analyticsGa4.analyticsModules.VideoTracker
50
+ var pos = player.getCurrentTime()
51
+ var percentages = [25, 50, 75]
52
+
53
+ // this looks really clunky and long hand
54
+ // but we have to do this once a second so doing the minimum before dropping out
55
+ // of an if statement is more efficient than combining all these statements into one
56
+ for (var i = 0; i < percentages.length; i++) {
57
+ if (pos >= videoTracker.handlers['video-' + videoId + '-' + percentages[i] + '-percent-begin']) {
58
+ if (pos < videoTracker.handlers['video-' + videoId + '-' + percentages[i] + '-percent-end']) {
59
+ if (!videoTracker.handlers['video-' + videoId + '-' + percentages[i]]) {
60
+ videoTracker.sendData(player, 'progress', percentages[i])
61
+ videoTracker.handlers['video-' + videoId + '-' + percentages[i]] = true
62
+ }
63
+ return
64
+ }
65
+ }
66
+ }
67
+ },
68
+
69
+ sendData: function (player, event, position) {
70
+ var data = {}
71
+ data.event_name = 'video_' + event
72
+ data.type = 'video'
73
+ data.url = player.getVideoUrl()
74
+ data.text = player.videoTitle
75
+ data.action = event
76
+ data.video_current_time = Math.round(player.getCurrentTime())
77
+ data.video_duration = Math.ceil(player.getDuration()) // number returned from the API varies, so round up
78
+ data.video_percent = position
79
+
80
+ var schemas = new window.GOVUK.analyticsGa4.Schemas()
81
+ var schema = schemas.mergeProperties(data, 'event_data')
82
+
83
+ window.GOVUK.analyticsGa4.core.sendData(schema)
84
+ }
85
+ }
86
+
87
+ analyticsModules.VideoTracker = VideoTracker
88
+ })(window.GOVUK.analyticsGa4.analyticsModules)
@@ -11,4 +11,5 @@
11
11
  //= require ./analytics-ga4/ga4-auto-tracker
12
12
  //= require ./analytics-ga4/ga4-smart-answer-results-tracker
13
13
  //= require ./analytics-ga4/ga4-scroll-tracker
14
+ //= require ./analytics-ga4/ga4-video-tracker
14
15
  //= require ./analytics-ga4/init-ga4
@@ -116,6 +116,9 @@
116
116
  // https://github.com/alphagov/govuk_publishing_components/pull/908#discussion_r302913995
117
117
  var videoTitle = options.title
118
118
  event.target.getIframe().title = videoTitle + ' (video)'
119
+ if (window.GOVUK.analyticsGa4.analyticsModules.VideoTracker) {
120
+ window.GOVUK.analyticsGa4.analyticsModules.VideoTracker.configureVideo(event)
121
+ }
119
122
  },
120
123
  onStateChange: function (event) {
121
124
  var eventData = event.data
@@ -140,6 +143,10 @@
140
143
 
141
144
  window.GOVUK.analytics.trackEvent(tracking.category, tracking.action, tracking.label)
142
145
  }
146
+
147
+ if (window.GOVUK.analyticsGa4.analyticsModules.VideoTracker) {
148
+ window.GOVUK.analyticsGa4.analyticsModules.VideoTracker.trackVideo(event, states[eventData])
149
+ }
143
150
  }
144
151
  }
145
152
  })
@@ -2,5 +2,6 @@
2
2
  @import "govuk/components/select/select";
3
3
 
4
4
  .gem-c-select__select--full-width {
5
- width: 100%;
5
+ min-width: 100%;
6
+ max-width: 100%;
6
7
  }
@@ -43,8 +43,6 @@
43
43
  "HTML",
44
44
  class: "gem-c-attachment__attribute",
45
45
  )
46
- data_attributes[:module] ? data_attributes[:module] << " ga4-link-tracker" : data_attributes[:module] = "ga4-link-tracker"
47
- data_attributes[:ga4_link] = { "event_name": "navigation", "type": "attachment" }.to_json
48
46
  when "external"
49
47
  attributes << tag.span(
50
48
  attachment.url,
@@ -53,7 +51,7 @@
53
51
  end
54
52
 
55
53
  %>
56
- <%= tag.section class: class_names(container_class_names) do %>
54
+ <%= tag.section class: class_names(container_class_names), data: { module: "ga4-link-tracker", ga4_track_links_only: "", ga4_link: { 'event_name': 'navigation', 'type': 'attachment' } } do %>
57
55
  <%= tag.div class: "gem-c-attachment__thumbnail" do %>
58
56
  <%= link_to attachment.url,
59
57
  class: "govuk-link",
@@ -8,7 +8,9 @@
8
8
  %>
9
9
 
10
10
  <% start_button_text = capture do %>
11
- <%= button.text %>
11
+ <span>
12
+ <%= button.text %>
13
+ </span>
12
14
  <svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" focusable="false" aria-hidden="true">
13
15
  <path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z" />
14
16
  </svg>
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "35.13.0".freeze
2
+ VERSION = "35.13.2".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: 35.13.0
4
+ version: 35.13.2
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: 2023-07-27 00:00:00.000000000 Z
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -451,6 +451,7 @@ files:
451
451
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-scroll-tracker.js
452
452
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.js
453
453
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js
454
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-video-tracker.js
454
455
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
455
456
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js
456
457
  - app/assets/javascripts/govuk_publishing_components/analytics.js
@@ -1467,7 +1468,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1467
1468
  - !ruby/object:Gem::Version
1468
1469
  version: '0'
1469
1470
  requirements: []
1470
- rubygems_version: 3.4.17
1471
+ rubygems_version: 3.4.18
1471
1472
  signing_key:
1472
1473
  specification_version: 4
1473
1474
  summary: A gem to document components in GOV.UK frontend applications