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

GA4: Fix ecommerce tracking of searches without query #4317

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

csutter
Copy link
Contributor

@csutter csutter commented Oct 18, 2024

What

The GA4 ecommerce tracking for search results doesn't currently work if the user is searching for an empty query, as the check for whether the ga4-search-query data attribute is present uses loose Javascript boolean logic (i.e. returning false for an empty string).

This amends it to strictly check for null instead (data attribute not present at all), and adds some tests for the search ecommerce data being properly set with the query present and absent.

Why

So we can actually track empty searches like all other searches.

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4317 October 18, 2024 15:26 Inactive
@AshGDS
Copy link
Contributor

AshGDS commented Oct 18, 2024

Needs a CHANGELOG entry probably 👍

The GA4 ecommerce tracking for search results doesn't currently work if
the user is searching for an empty query, as the check for whether the
`ga4-search-query` data attribute is present uses loose Javascript
boolean logic (i.e. returning false for an empty string).

This amends it to strictly check for `null` instead (data attribute not
present at all), and adds some tests for the search ecommerce data being
properly set with the query present and absent.
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4317 October 18, 2024 15:42 Inactive
@csutter csutter merged commit a4d6d40 into main Oct 18, 2024
12 checks passed
@csutter csutter deleted the fix-search-ecomm branch October 18, 2024 15:48
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