Skip to content

Commit

Permalink
Add action to GA4 form event error
Browse files Browse the repository at this point in the history
- adds a missing attribute for 'action' to the GA4 tracking event on the contact form error message ('error')
  • Loading branch information
andysellick committed Mar 28, 2024
1 parent f90082a commit 4a04554
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/contact/govuk/new.html.erb
Expand Up @@ -45,6 +45,7 @@
ga4_auto_tracker_json = {
event_name: 'form_error',
type: 'contact',
action: 'error',
text: @errors.values.map { | error_hash | error_hash.first }.join(', '),
section: ga4_erroring_sections,
tool_name: ga4_english_strings[:page_title]
Expand Down
1 change: 1 addition & 0 deletions spec/requests/contact_spec.rb
Expand Up @@ -415,6 +415,7 @@ def response_contains(request, field, expected_value)
ga4_data = JSON.parse(ga4_auto_element["data-ga4-auto"])

expect(ga4_data["event_name"]).to eq "form_error"
expect(ga4_data["action"]).to eq "error"
expect(ga4_data["type"]).to eq "contact"
expect(ga4_data["text"]).to eq "The link field cannot be empty, The message field cannot be empty, The email address must be valid, The name field cannot be empty"
expect(ga4_data["section"]).to eq "What's it to do with?, What are the details?, If you want a reply (optional), If you want a reply (optional)"
Expand Down

0 comments on commit 4a04554

Please sign in to comment.