Skip to content

Commit

Permalink
Add tests to GA4 feedback tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Apr 18, 2024
1 parent 171fe91 commit 6fa7134
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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
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

0 comments on commit 6fa7134

Please sign in to comment.