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 GA4 to form validation errors #9148

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

lauraghiorghisor-tw
Copy link
Contributor

@lauraghiorghisor-tw lauraghiorghisor-tw commented Jun 13, 2024

We want to be able to track validation errors on the page. This is in the context of the visual editor tool, albeit validation errors are not very relevant in that case.

We are looking to also migrate UA to GA4 so these changes also remove UA tracking for the ErrorSummary component.

Trello card

@lauraghiorghisor-tw lauraghiorghisor-tw force-pushed the add-ga4-for-form-validation branch 5 times, most recently from 9f00e04 to 454952d Compare June 14, 2024 22:51
@@ -1,13 +1,4 @@
<% if flash["alert"].present? %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@minhngocd Not super sure what the logic here was meant to achieve.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is to track flash alerts back in the days i guess - if you check the commit message it says

Ensure flash-danger Google Analytics event is retained

We've moved away from using flash[:alert] in favour of the error summary component when there are errors on an object.

However, we want to retain the GA event that is triggered by the flash. To get around this I've ensured a flash["alert"] is only rendered on the page when the error summary block is empty.

This will ensure we only ever get 1 banner on the page. To ensure we still get the GA event i've wrapped the error summary component in a div which tracks the flash["alert"].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dug it up too. I just find it a bit confusing/convoluted. We're still firing
data_attributes: track_analytics_data("form-error", analytics_action, error.full_message) from within the error_summary_component.rb so it feels a bit duplicated.

I can leave it in and we can make this call when we implement whatever schema we want for flash, as part of the migration to GA4.

Copy link
Contributor

Choose a reason for hiding this comment

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

update on conversations - we've discussed with Carmen, and believe if the user doesn't see the flash as a separate thing, then we should not need to see it as a separate event. we can remove this logic to reduce the duplication

@@ -69,7 +69,7 @@ class Admin::StatisticsAnnouncementPublicationsControllerTest < ActionController

assert_response :success
has_search_results_table
assert_select "ul.govuk-error-summary__list a[data-track-action='statistics announcement-error'][data-track-label=\"Publication type does not match: must be statistics\"]", text: "Publication type does not match: must be statistics"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@minhngocd not sure why this was ever needed

Copy link
Contributor

Choose a reason for hiding this comment

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

probably to test that we are sending that tracking data by setting those attributes

Copy link
Contributor Author

@lauraghiorghisor-tw lauraghiorghisor-tw Jun 17, 2024

Choose a reason for hiding this comment

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

It is tested elsewhere, the test is not about tracking, the test does not require tracking selector to pass. 🤷🏻‍♀️

@lauraghiorghisor-tw lauraghiorghisor-tw force-pushed the add-ga4-for-form-validation branch 2 times, most recently from d4805a3 to c8beb7f Compare June 18, 2024 10:43
@lauraghiorghisor-tw lauraghiorghisor-tw marked this pull request as ready for review June 18, 2024 12:36
def ga4_title
return object.class.name.humanize if [ActiveModel::Errors, Array].include?(object.class)

"#{object.try(:new_record?) ? 'New' : 'Editing'} #{object.model_name.human.downcase.titleize}"
Copy link
Contributor

Choose a reason for hiding this comment

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

we do this so many times you it warrants a helper method 👀 but also happy to refactor as a separate piece of work

@lauraghiorghisor-tw lauraghiorghisor-tw merged commit 32e6091 into main Jun 18, 2024
19 checks passed
@lauraghiorghisor-tw lauraghiorghisor-tw deleted the add-ga4-for-form-validation branch June 18, 2024 14:28
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