From 171fe91ce60ac6ff3d1cacae8839f5c2ebc60aa9 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:05:27 +0100 Subject: [PATCH 1/2] Add tool name to GA4 feedback component --- .../components/feedback/_problem_form.html.erb | 4 +++- .../components/feedback/_survey_signup_form.html.erb | 4 +++- .../components/feedback/_yes_no_banner.html.erb | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb b/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb index 10a087e9b4..5431760719 100644 --- a/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +++ b/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb @@ -44,11 +44,13 @@ <% unless disable_ga4 + heading_text = t("components.feedback.help_us_improve_govuk", locale: :en) ga4_submit_button_event = { event_name: "form_submit", type: "feedback", text: t("components.feedback.send", locale: :en), - section: t("components.feedback.help_us_improve_govuk", locale: :en), + section: heading_text, + tool_name: heading_text }.to_json end %> diff --git a/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb b/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb index 8b30be6dde..68d5802e0a 100644 --- a/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +++ b/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb @@ -31,11 +31,13 @@ <% unless disable_ga4 + heading_text = t("components.feedback.help_us_improve_govuk", locale: :en) ga4_send_button_event = { event_name: "form_submit", type: "feedback", text: t("components.feedback.send_me_survey", locale: :en), - section: t("components.feedback.help_us_improve_govuk", locale: :en), + section: heading_text, + tool_name: heading_text }.to_json end %> diff --git a/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb b/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb index 10f7a5f95c..68354833b1 100644 --- a/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +++ b/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb @@ -1,24 +1,28 @@ <% unless disable_ga4 + heading_text = t("components.feedback.is_this_page_useful", locale: :en) ga4_yes_button_event = { "event_name": "form_submit", "type": "feedback", - "text": t("components.feedback.yes", locale: :en), - "section": t("components.feedback.is_this_page_useful", locale: :en), + "text": t("components.feedback.yes", locale: :en), + "section": heading_text, + "tool_name": heading_text, }.to_json ga4_no_button_event = { "event_name": "form_submit", "type": "feedback", "text": t("components.feedback.no", locale: :en), - "section": t("components.feedback.is_this_page_useful", locale: :en) + "section": heading_text, + "tool_name": heading_text, }.to_json ga4_problem_button_event = { "event_name": "form_submit", "type": "feedback", "text": t("components.feedback.something_wrong", locale: :en), - "section": t("components.feedback.is_this_page_useful", locale: :en) + "section": heading_text, + "tool_name": heading_text, }.to_json end %> From 6fa713403ab86c622ecc84cdc2f1fd031fa9b480 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:27:33 +0100 Subject: [PATCH 2/2] Add tests to GA4 feedback tracking --- CHANGELOG.md | 1 + spec/components/feedback_spec.rb | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f76b65b0b5..df624922b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ## Unreleased * Add the hidden attribute to mobile menu button ([PR #3975](https://github.com/alphagov/govuk_publishing_components/pull/3975)) +* Add tool_name to GA4 feedback component tracking ([PR #3984](https://github.com/alphagov/govuk_publishing_components/pull/3984)) ## 38.0.1 diff --git a/spec/components/feedback_spec.rb b/spec/components/feedback_spec.rb index 8980910f73..930af5a4ed 100644 --- a/spec/components/feedback_spec.rb +++ b/spec/components/feedback_spec.rb @@ -40,4 +40,43 @@ def component_name expect(response.body).to include(utf8_url) end end + + it "has GA4 tracking" do + render_component({}) + + assert_select ".gem-c-feedback[data-module='feedback ga4-event-tracker']" + + # Yes button + assert_select ".js-page-is-useful[data-ga4-event='{\"event_name\":\"form_submit\",\"type\":\"feedback\",\"text\":\"Yes\",\"section\":\"Is this page useful?\",\"tool_name\":\"Is this page useful?\"}']" + + # No button + assert_select ".js-page-is-not-useful[data-ga4-event='{\"event_name\":\"form_submit\",\"type\":\"feedback\",\"text\":\"No\",\"section\":\"Is this page useful?\",\"tool_name\":\"Is this page useful?\"}']" + + # Report a problem button + assert_select ".js-something-is-wrong[data-ga4-event='{\"event_name\":\"form_submit\",\"type\":\"feedback\",\"text\":\"Report a problem with this page\",\"section\":\"Is this page useful?\",\"tool_name\":\"Is this page useful?\"}']" + + # Report a problem submit + assert_select ".govuk-button[data-ga4-event='{\"event_name\":\"form_submit\",\"type\":\"feedback\",\"text\":\"Send\",\"section\":\"Help us improve GOV.UK\",\"tool_name\":\"Help us improve GOV.UK\"}']" + + # Send me the survey submit + assert_select ".govuk-button[data-ga4-event='{\"event_name\":\"form_submit\",\"type\":\"feedback\",\"text\":\"Send me the survey\",\"section\":\"Help us improve GOV.UK\",\"tool_name\":\"Help us improve GOV.UK\"}']" + end + + it "can have its GA4 tracking disabled" do + render_component({ disable_ga4: true }) + + assert_select ".gem-c-feedback[data-module='feedback ga4-event-tracker']", false + + # Yes button + assert_select ".js-page-is-useful[data-ga4-event]", false + + # No button + assert_select ".js-page-is-not-useful[data-ga4-event]", false + + # Report a problem button + assert_select ".js-something-is-wrong[data-ga4-event]", false + + # Report a problem submit / Send me the survey submit + assert_select ".govuk-button[data-ga4-event]", false + end end