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

Track select interactions in Whitehall #10069

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gtvj
Copy link
Contributor

@gtvj gtvj commented Mar 17, 2025

What

Send data to GA4 in response to change events that occur on those <select> elements which are not part of a select_with_search component. Further information is provided in the Trello card

  • Introduce new analytics module with tests (See ec861fe)
  • Decorate native <select> elements within the codebase (See 000a6c1)
  • Understand how we might decorate <select> elements coming from the components Gem with data_attributes
  • Add the data attributes to all ~29 instances of govuk_publishing_components/components/select in Whitehall

How

Introduces a new analytics GA4SelectSetup module that sends data to GA4 in response to change events on only those select elements that are not part of a select_with_search component (See #9983 for details of how the select_with_search components are tracked using custom events provided by choices.js).

The select_with_search components have been excluded through the selector used to build the nodeList:

"select:not([data-module~='select-with-search'] select)"

This queries for all select elements that do not have an ancestor with the select-with-search data-module. This approach is necessary to avoid multiple submissions in response to a single change in select_with_search.

Following the implementation of other analytics modules, a new module is added to the HTML (ga4-select-setup) to allow for control of when this tracking is enabled.

Performance analyst review

[To be done]

Related PRs

gtvj added 3 commits March 26, 2025 10:29
Introduces a new analytics GA4SelectSetup module that sends data to GA4
in response to `change` events on only those select elements that are
not part of a `select_with_search` component (See #9983 for details of
how the `select_with_search` components are tracked using custom events
provided by choices.js).

The `select_with_search` components have been excluded through the selector
used to build the nodeList:

"select:not([data-module~='select-with-search'] select)"

This instructs the DOM to return all select elements that do not have
an ancestor decorated with the 'select-with-search' data-module. This
approach is necessary to avoid multiple submissions in response to a
single change in `select_with_search`.

Following the implementation of other analytics modules, a new module is added
to the HTML (`ga4-select-setup`) to allow for control of when this
tracking is enabled.
Introduces the necessary data-attributes to allow for data to be passed to GA4 on the
one instance of a `<select>` element within the codebase. There are many other select
elements, but these use the GOV.UK Publishing Components select component.
This is an interim commit to save and share my work. It'll be
overwritten before I ask for a PR review.
@ChrisBAshton ChrisBAshton force-pushed the track_select_interactions_in_whitehall branch from c25cd9d to 6703628 Compare March 26, 2025 10:29
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.

1 participant