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

Improve GA4 search tracking #4582

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Improve GA4 search tracking #4582

merged 1 commit into from
Jan 23, 2025

Conversation

csutter
Copy link
Contributor

@csutter csutter commented Jan 22, 2025

What

This change updates the behaviour of the Ga4SearchTracker module as follows:

  • update the tracking to always fire a search event when the form is submitted
  • make the action of the search event dynamic
  • update the logic to establish whether the user is searching vs filtering by checking which fields the user has interacted with (instead of checking if the keyword has changed), and set the event's action property accordingly

Why

Now that we have collected a decent amount of tracking data on search across GOV.UK, we've come across a couple of trip hazards with the existing tracking. In particular:

  • suppressing the event if the keyword hasn't changed is a bit brittle (and subtly buggy as we've forgotten to normalise the initial keyword in the JS component state)
  • Relying on separate tracking in Finder Frontend for filter application has led to duplication and unreliable behaviour (for example, as we only track clicks of the filter button, we do not get events when a user submits the form through other means such as the Enter key or the main search field's submit button)

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4582 January 22, 2025 10:23 Inactive
Copy link
Contributor

@AshGDS AshGDS left a comment

Choose a reason for hiding this comment

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

Looks good to me, just had a couple questions first.

Now that we have collected a decent amount of tracking data on search
across GOV.UK, we've come across a couple of trip hazards with the
existing tracking. In particular:
- suppressing the event if the keyword hasn't changed is a bit brittle
  (and subtly buggy as we've forgotten to normalise the initial keyword
  in the JS component state)
- Relying on separate tracking in Finder Frontend for filter application
  has led to duplication and unreliable behaviour (for example, as we
  only track clicks of the filter button, we do not get events when a
  user submits the form through other means such as the Enter key or the
  main search field's submit button)

This change updates the behaviour of the `Ga4SearchTracker` module as
follows:
- update the tracking to _always_ fire a `search` event when the form is
  submitted
- make the action of the `search` event dynamic
- update the logic to establish whether the user is searching vs
  filtering by checking which fields the user has interacted with
  (instead of checking if the keyword has changed), and set the event's
  action property accordingly
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4582 January 23, 2025 12:35 Inactive
Copy link
Contributor

@AshGDS AshGDS left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@csutter csutter merged commit e13539c into main Jan 23, 2025
12 checks passed
@csutter csutter deleted the ga4-search-new branch January 23, 2025 15:04
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.

3 participants