govuk_publishing_components 35.13.1 → 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: 1337364c8c59cc2f98de9c4919d17bbb17356257fcc90eb90f25e15db301a0ae
4
- data.tar.gz: 70b99e1a524455dc905f457addfb78aa46f0a4fa7be0a69c64a5e34952228be3
3
+ metadata.gz: d89a426d686fe0891582f8851ff7b27c57a457b838dccd81aa07a4868a9a9975
4
+ data.tar.gz: b267048c6e6bd91689fcedbad4e16835de62ff50aee68e94684ec4533ad7c5ab
5
5
  SHA512:
6
- metadata.gz: 9a85f01e30436be8cb8f2131f851353e28a8cbad3c0269758789991491ad5ed232ae1e2e9d782e2fa8349c4863c38faadb254a788abb416e3b4ba35f32d196d7
7
- data.tar.gz: 103018230befe8fca5796df4f9d2ebff20f255584253d37d5e3aa2c9cd997b7a17a6fdb719932c758f31647a84fb1c85329fc33082bf68ac1ca99fa48fcd7b36
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)
@@ -29,6 +29,9 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
29
29
  content_id: this.getMetaContent('content-id'),
30
30
 
31
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'),
32
35
  taxonomy_level1: this.getMetaContent('themes'),
33
36
  taxonomy_main: this.getMetaContent('taxon-slug'),
34
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",
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "35.13.1".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.1
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-08-01 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