Prevent duplicate purchase events via localStorage deduplication - #43
Open
koenvdwetering wants to merge 1 commit into
Open
Prevent duplicate purchase events via localStorage deduplication#43koenvdwetering wants to merge 1 commit into
koenvdwetering wants to merge 1 commit into
Conversation
The purchase event is pushed to the dataLayer by two independent mechanisms on the success page (the server-rendered layout event via data-layer.phtml, and the customerData "gtm-checkout" section via generic.js). Their payloads differ, so the existing in-memory hash guard (window.Tagging_GTM_PAST_EVENTS) does not deduplicate them. In addition, the server-rendered event is built from checkoutSession->getLastRealOrder() and re-fires on every reload/back-navigation of the success page, while the hash guard resets on each page load. Add a persistent, transaction_id-based dedup guard to both the Luma (push.js) and Hyva (script-pusher.phtml) pushers. A trytagging_purchase is now pushed at most once per browser per order, surviving reloads and the dual push path, without removing either delivery path so a conversion is never lost. Non-purchase events are unaffected (they carry no ecommerce.transaction_id). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DQvtz7r6vxm64uRZ4YEKoi
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
This change adds persistent browser-level deduplication for purchase events to prevent the same transaction from being tracked multiple times. Purchase events can be emitted from multiple sources (server-rendered layout events and customerData sections) and re-rendered on every success page reload, causing duplicate GTM events. This fix uses localStorage to track transaction IDs across page loads.
Key Changes
Added localStorage-based deduplication in both
push.jsandscript-pusher.phtml:Tagging_GTM_PURCHASED_TRANSACTIONSlocalStorage keytrytagging_purchaseevents (which carry stableecommerce.transaction_id)Bounded storage management:
Version bump: Updated
composer.jsonfrom 1.6.0 to 1.6.1Implementation Details
The deduplication logic:
transaction_idfrom purchase eventsThe implementation is identical in both files to ensure consistency across different template contexts (standard and Hyva theme).
https://claude.ai/code/session_01DQvtz7r6vxm64uRZ4YEKoi