govuk_publishing_components 37.0.0 → 37.1.0

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: fe726cba8402c5e0b082b9183eb50b531bc4024e0a8d8420e8aa9bc01bf792ee
4
- data.tar.gz: a0ca9fdb633e3f78bacd25fe5f6b1d10353d3ec70b49c8881f65c667c8cb5a6f
3
+ metadata.gz: 43da95e575a63b626abef7368fbe99d286682778b3933f9b021768277b3a8d17
4
+ data.tar.gz: a2959e0efd156b0c5d5a70b61561725d55a4c67e58f0e60537970439af0088db
5
5
  SHA512:
6
- metadata.gz: 983fb3da1f16193554ae6f850a6da73ce0a3a4a92df1e430ab8ccc028e50739188f8225a79cfeefd5aca477632b70105349b853e0bce55b704bba91947700dc4
7
- data.tar.gz: bdcc215e867f598b8afd6d502ef393656b4bbca8e2059aa21f15bce7838d4a6ff9f02319f13c365c684f780b544272034d6fd0233e4aa7a5f978d3e6529eda50
6
+ metadata.gz: 60593190a4219cf35788d97f6f491c9f36ad873772d2b3908bcb21c347fcadcd061e35c25225acaa89199f5cabb6f0769376847521738cc26ff23eb088febce5
7
+ data.tar.gz: 22a37d5ff61c2164ef441774aae4f9268a9a46b19e7d5dbc847b7e290af706ce038894cd70a992ffe525a17e61ad205476bdb1d4eedc5e486a9f006a38532183
@@ -0,0 +1,55 @@
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 Ga4CopyTracker = {
9
+ init: function () {
10
+ window.addEventListener('copy', this.trackCopy.bind(this))
11
+ },
12
+
13
+ trackCopy: function (event) {
14
+ try {
15
+ var text = this.getSelectedText()
16
+ if (!text) {
17
+ return // do nothing if no text has been selected
18
+ }
19
+ var target = event.target.tagName
20
+ if (target === 'INPUT' || target === 'TEXTAREA') {
21
+ return // do nothing if text is being copied from an input
22
+ }
23
+
24
+ var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
25
+ text = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(text)
26
+ text = PIIRemover.stripPIIWithOverride(text, true, true)
27
+ var length = text.length
28
+ text = text.substring(0, 30)
29
+
30
+ var data = {
31
+ event_name: 'copy',
32
+ type: 'copy',
33
+ action: 'copy',
34
+ method: 'browser copy',
35
+ text: text,
36
+ length: length
37
+ }
38
+ window.GOVUK.analyticsGa4.core.applySchemaAndSendData(data, 'event_data')
39
+ } catch (e) {
40
+ console.warn('GA4 copy tracker error: ' + e.message, window.location)
41
+ }
42
+ },
43
+
44
+ getSelectedText: function () {
45
+ if (window.getSelection) {
46
+ return window.getSelection().toString()
47
+ } else if (document.selection) {
48
+ return document.selection.createRange().text
49
+ }
50
+ return false
51
+ }
52
+ }
53
+
54
+ analyticsModules.Ga4CopyTracker = Ga4CopyTracker
55
+ })(window.GOVUK.analyticsGa4.analyticsModules)
@@ -30,7 +30,7 @@
30
30
  tool_name: this.undefined,
31
31
  percent_scrolled: this.undefined,
32
32
  video_current_time: this.undefined,
33
- video_duration: this.undefined,
33
+ length: this.undefined,
34
34
  video_percent: this.undefined
35
35
  }
36
36
  }
@@ -78,7 +78,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
78
78
  data.url = this.handlers['video-' + player.id + '-url']
79
79
  data.text = this.handlers['video-' + player.id + '-title']
80
80
  data.video_current_time = Math.round(player.getCurrentTime())
81
- data.video_duration = this.handlers['video-' + player.id + '-duration']
81
+ data.length = this.handlers['video-' + player.id + '-duration']
82
82
  data.video_percent = position
83
83
 
84
84
  window.GOVUK.analyticsGa4.core.applySchemaAndSendData(data, 'event_data')
@@ -4,6 +4,7 @@
4
4
  //= require ./analytics-ga4/pii-remover
5
5
  //= require ./analytics-ga4/ga4-page-views
6
6
  //= require ./analytics-ga4/ga4-print-intent-tracker
7
+ //= require ./analytics-ga4/ga4-copy-tracker
7
8
  //= require ./analytics-ga4/ga4-specialist-link-tracker
8
9
  //= require ./analytics-ga4/ga4-link-tracker
9
10
  //= require ./analytics-ga4/ga4-event-tracker
@@ -172,7 +172,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
172
172
  try {
173
173
  buttonAttributes = JSON.parse(buttonAttributes)
174
174
  for (var rawKey in buttonAttributes) {
175
- var key = rawKey.replace(/_/i, '-').toLowerCase()
175
+ var key = rawKey.replace(/_/g, '-').toLowerCase()
176
176
  var rawValue = buttonAttributes[rawKey]
177
177
  var value = typeof rawValue === 'object' ? JSON.stringify(rawValue) : rawValue
178
178
  button.setAttribute('data-' + key, value)
@@ -1,3 +1,4 @@
1
+ @import "govuk_publishing_components/individual_component_support";
1
2
  @import "govuk_publishing_components/components/search";
2
3
  @import "govuk_publishing_components/components/skip-link";
3
4
  @import "govuk/components/header/header";
@@ -9,10 +9,14 @@
9
9
  email_regex = /[^\s=\/?&]+(?:@|%40)[^\s=\/?&]+/
10
10
  url_without_pii = utf_encode(request.original_url.gsub(email_regex, '[email]'))
11
11
  path_without_pii = utf_encode(request.fullpath.gsub(email_regex, '[email]'))
12
+
13
+ disable_ga4 ||= false
14
+ data_module = "feedback"
15
+ data_module << " ga4-event-tracker" unless disable_ga4
12
16
  %>
13
17
 
14
- <div class="gem-c-feedback govuk-!-display-none-print" data-module="feedback ga4-event-tracker">
15
- <%= render "govuk_publishing_components/components/feedback/yes_no_banner" %>
16
- <%= render "govuk_publishing_components/components/feedback/problem_form", url_without_pii: url_without_pii %>
17
- <%= render "govuk_publishing_components/components/feedback/survey_signup_form", path_without_pii: path_without_pii %>
18
+ <div class="gem-c-feedback govuk-!-display-none-print" data-module="<%= data_module %>">
19
+ <%= render "govuk_publishing_components/components/feedback/yes_no_banner", disable_ga4: %>
20
+ <%= render "govuk_publishing_components/components/feedback/problem_form", url_without_pii: url_without_pii, disable_ga4: %>
21
+ <%= render "govuk_publishing_components/components/feedback/survey_signup_form", path_without_pii: path_without_pii, disable_ga4: %>
18
22
  </div>
@@ -25,3 +25,8 @@ shared_accessibility_criteria:
25
25
  examples:
26
26
  default:
27
27
  data: {}
28
+ with_ga4_tracking_disabled:
29
+ description: |
30
+ Disables GA4 tracking on the feedback component. Tracking is enabled by default, which adds a data module and data-attributes with JSONs to the feedback buttons. See the [ga4-event-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-event-tracker.md) for more information.
31
+ data:
32
+ disable_ga4: true
@@ -38,15 +38,21 @@
38
38
  rows: 3
39
39
  } %>
40
40
 
41
+ <%
42
+ unless disable_ga4
43
+ ga4_submit_button_event = {
44
+ event_name: "form_submit",
45
+ type: "feedback",
46
+ text: t("components.feedback.send", locale: :en),
47
+ section: t("components.feedback.help_us_improve_govuk", locale: :en),
48
+ }.to_json
49
+ end
50
+ %>
51
+
41
52
  <%= render "govuk_publishing_components/components/button", {
42
53
  text: t("components.feedback.send"),
43
54
  data_attributes: {
44
- ga4_event: {
45
- event_name: "form_submit",
46
- type: "feedback",
47
- text: "Send",
48
- section: "Help us improve GOV.UK",
49
- }
55
+ ga4_event: ga4_submit_button_event
50
56
  }
51
57
  } %>
52
58
 
@@ -25,15 +25,21 @@
25
25
  describedby: "survey_explanation"
26
26
  } %>
27
27
 
28
+ <%
29
+ unless disable_ga4
30
+ ga4_send_button_event = {
31
+ event_name: "form_submit",
32
+ type: "feedback",
33
+ text: t("components.feedback.send_me_survey", locale: :en),
34
+ section: t("components.feedback.help_us_improve_govuk", locale: :en),
35
+ }.to_json
36
+ end
37
+ %>
38
+
28
39
  <%= render "govuk_publishing_components/components/button", {
29
40
  text: t("components.feedback.send_me_survey"),
30
41
  data_attributes: {
31
- ga4_event: {
32
- event_name: "form_submit",
33
- type: "feedback",
34
- text: "Send me the survey",
35
- section: "Help us improve GOV.UK",
36
- }
42
+ ga4_event: ga4_send_button_event
37
43
  }
38
44
  } %>
39
45
 
@@ -1,3 +1,28 @@
1
+ <%
2
+ unless disable_ga4
3
+ ga4_yes_button_event = {
4
+ "event_name": "form_submit",
5
+ "type": "feedback",
6
+ "text": t("components.feedback.yes", locale: :en),
7
+ "section": t("components.feedback.is_this_page_useful", locale: :en),
8
+ }.to_json
9
+
10
+ ga4_no_button_event = {
11
+ "event_name": "form_submit",
12
+ "type": "feedback",
13
+ "text": t("components.feedback.no", locale: :en),
14
+ "section": t("components.feedback.is_this_page_useful", locale: :en)
15
+ }.to_json
16
+
17
+ ga4_problem_button_event = {
18
+ "event_name": "form_submit",
19
+ "type": "feedback",
20
+ "text": t("components.feedback.something_wrong", locale: :en),
21
+ "section": t("components.feedback.is_this_page_useful", locale: :en)
22
+ }.to_json
23
+ end
24
+ %>
25
+
1
26
  <div class="gem-c-feedback__prompt gem-c-feedback__js-show js-prompt" tabindex="-1">
2
27
  <div class="gem-c-feedback__prompt-content">
3
28
  <div class="gem-c-feedback__prompt-questions js-prompt-questions" hidden>
@@ -20,14 +45,31 @@
20
45
  <% end %>
21
46
  </li>
22
47
  <li class="gem-c-feedback__option-list-item">
23
- <button class="govuk-button gem-c-feedback__prompt-link js-page-is-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffYesClick" data-ga4-event='{"event_name":"form_submit","type":"feedback","text":"Yes", "section": "Is this page useful?"}'>
48
+ <%= tag.button(
49
+ class: "govuk-button gem-c-feedback__prompt-link js-page-is-useful",
50
+ data: {
51
+ track_category: "yesNoFeedbackForm",
52
+ track_action: "ffYesClick",
53
+ ga4_event: ga4_yes_button_event,
54
+ }) do %>
24
55
  <%= t("components.feedback.yes") %> <span class="govuk-visually-hidden"><%= t("components.feedback.is_useful") %></span>
25
- </button>
56
+ <% end %>
26
57
  </li>
27
58
  <li class="gem-c-feedback__option-list-item">
28
- <button class="govuk-button gem-c-feedback__prompt-link js-toggle-form js-page-is-not-useful" data-track-category="yesNoFeedbackForm" data-track-action="ffNoClick" aria-controls="page-is-not-useful" aria-expanded="false" data-ga4-event='{"event_name":"form_submit","type":"feedback","text":"No", "section": "Is this page useful?"}'>
59
+
60
+ <%= tag.button(
61
+ class: "govuk-button gem-c-feedback__prompt-link js-toggle-form js-page-is-not-useful",
62
+ aria: {
63
+ controls: "page-is-not-useful",
64
+ expanded: "false",
65
+ },
66
+ data: {
67
+ track_category: "yesNoFeedbackForm",
68
+ track_action: "ffNoClick",
69
+ ga4_event: ga4_no_button_event,
70
+ }) do %>
29
71
  <%= t("components.feedback.no") %> <span class="govuk-visually-hidden"><%= t("components.feedback.is_not_useful") %></span>
30
- </button>
72
+ <% end %>
31
73
  </li>
32
74
  </ul>
33
75
  </div>
@@ -38,9 +80,19 @@
38
80
  </div>
39
81
 
40
82
  <div class="gem-c-feedback__prompt-questions gem-c-feedback__prompt-questions--something-is-wrong js-prompt-questions" hidden>
41
- <button class="govuk-button gem-c-feedback__prompt-link js-toggle-form js-something-is-wrong" data-track-category="Onsite Feedback" data-track-action="GOV-UK Open Form" aria-controls="something-is-wrong" aria-expanded="false" data-ga4-event='{"event_name":"form_submit","type":"feedback","text":"Report a problem with this page", "section": "Is this page useful?"}'>
83
+ <%= tag.button(
84
+ class: "govuk-button gem-c-feedback__prompt-link js-toggle-form js-something-is-wrong",
85
+ aria: {
86
+ expanded: "false",
87
+ controls: "something-is-wrong"
88
+ },
89
+ data: {
90
+ track_category: "Onsite Feedback",
91
+ track_action: "GOV-UK Open Form",
92
+ ga4_event: ga4_problem_button_event,
93
+ }) do %>
42
94
  <%= t("components.feedback.something_wrong") %>
43
- </button>
95
+ <% end %>
44
96
  </div>
45
97
  </div>
46
98
  </div>
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.0.0".freeze
2
+ VERSION = "37.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: 37.0.0
4
+ version: 37.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: 2023-12-12 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -452,6 +452,7 @@ files:
452
452
  - app/assets/javascripts/govuk_publishing_components/all_components.js
453
453
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
454
454
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js
455
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-copy-tracker.js
455
456
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js
456
457
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js
457
458
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js