Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tool_name to GA4 feedback component tracking #3984

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
%>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
%>
Expand Down
39 changes: 39 additions & 0 deletions spec/components/feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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