Skip to content

Conversation

DavidBiddle
Copy link
Contributor

@DavidBiddle DavidBiddle commented Oct 2, 2025

What problem does this pull request solve?

Trello card: https://trello.com/c/b6jmnphx/2288-track-branching-validation-errors

Our code for tracking validation errors in Google Analytics was returning null for the form name in many cases.

This is because the analytics logic was getting the form name from the input if it had form as an attribute, but some input objects - mainly those that change the page model - don't have the form attribute as they operate on draft_question instead.

This PR:

  • adds a method to the draft question so it can get the name of its parent form
  • uses the new method to populate the form_name field in the analytics for any input object that uses draft_question
  • updates Pages::RoutingPageInput to use a form attribute so it can be read by the analytics.

Testing instructions

  • Set analytics_enabled: true in your local settings (this isn't set in the review environment)
  • log in as any non-super admin user
  • go to any page with form fields within the form scope
  • cause a validation error
  • open the JS console and enter dataLayer
  • You should see an event in there that looks something like this, including the name of the form:
{
  "event": "event_data",
  "event_data": {
    "event_name": "validation_error",
    "input_object_name": "Pages::TypeOfAnswerInput",
    "form_name": "Apply for a juggling licence",
    "error_field": "answer_type",
    "error_type": "blank"
  },
  "gtm.uniqueEventId": 5
}

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

@DavidBiddle DavidBiddle marked this pull request as ready for review October 2, 2025 15:52
Copy link
Contributor

@thomasiles thomasiles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fiddly!

It looks nicely structured with good commit messages 🏅

Adds a method to easily get the form name for a draft question - we'll
use this in the Google Analytics event that tracks validation errors.
Passes the form_name from the draft question to the analytics event for
any input that includes a draft_question attribute.

This fixes an issue where some inputs weren't including the form name in
the analytics event.
The previous commit broke some tests, as some tests were using test data
for draft_question without a corresponding form existing.

This commit adds a form to these tests to make them more realistic and
fix the tests.
Passes the current form to the Pages::RoutingPageInput so that the
validation error analytics tracking ahs access to the form name.
@DavidBiddle DavidBiddle force-pushed the fix-missing-form-names-in-ga branch from 9266534 to c87952b Compare October 6, 2025 08:04
Copy link

sonarqubecloud bot commented Oct 6, 2025

Copy link

github-actions bot commented Oct 6, 2025

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2259.admin.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

@DavidBiddle DavidBiddle merged commit e3f1cb6 into main Oct 6, 2025
6 checks passed
@DavidBiddle DavidBiddle deleted the fix-missing-form-names-in-ga branch October 6, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants