Conversation
…tialization
Cart analytics events (product_added_to_cart, cart_updated) were silently
dropped due to a race condition between consent initialization and cart
resolution introduced in the new cookie system (2025.7.1).
Three interacting bugs caused the issue:
1. The `publish` function in AnalyticsProvider was set to a no-op
`() => {}` when `canTrack()` returned false during useMemo
evaluation (before the Customer Privacy SDK loaded).
2. CartAnalytics deduplication (`lastEventId.current`) marked events
as "sent" even when they went to the no-op, preventing re-emission
when the real publish function became available.
3. The waitForReadyQueue used a Map keyed by event name, silently
overwriting duplicate event types (e.g., two cart_updated events
would lose the first).
The fix:
- Always pass the real `publish` function (consent is enforced at 3
downstream layers: register/ready queue timing, subscriber-level
analyticsProcessingAllowed() check, and sendShopifyAnalytics
hasUserConsent gate)
- Change queue from Map to bounded Array (MAX=100) preserving all
events in FIFO order with overflow protection
- Add reentrancy-safe drain loop
- Remove dead analyticsLoaded state
Closes #3467
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
Patch bump for @Shopify/hydrogen to include the cart analytics event fix in the next release.
Contributor
Author
|
/snapit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes cart analytics events (
product_added_to_cart,cart_updated) being silently dropped since Hydrogen 2025.7.1. This affected every Hydrogen merchant using analytics — approximately 3 months of lost conversion data.Root Cause
Three interacting bugs created a deterministic race condition:
No-op publish gate —
publish: canTrack() ? publish : () => {}inAnalyticsProviderevaluatedcanTrack()atuseMemotime. Before the Customer Privacy SDK loaded,canTrack()returnedfalse, makingpublisha no-op.CartAnalytics deduplication — Cart events fired into the no-op were marked as "sent" via
lastEventId.current. Whenpublishlater became the real function, the dedup guard prevented re-emission.Map key collision —
waitForReadyQueueused aMapkeyed by event name, silently overwriting duplicate event types.Fix
publishfunction (consent is enforced at 3 downstream layers: register/ready queue timing, subscriber-levelanalyticsProcessingAllowed()check, andsendShopifyAnalyticshasUserConsentgate)Mapto boundedArray(MAX=100) preserving all events in FIFO orderanalyticsLoadedstateWhy page views were NOT affected
AnalyticsViewhas no deduplication guard — whenpublishchanged from no-op to real function, page view events re-fired successfully. Cart events had thelastEventIdref that prevented this.Closes #3467
Test plan
main, pass with fix)product_added_to_cartevents after adding to cart