-
Notifications
You must be signed in to change notification settings - Fork 826
WooCommerce Analytics: Fix duplicate product purchase events #44973
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
Conversation
…ooks and improve capture_event_in_session_data method to accept event properties. This enhances the accuracy of event data captured during checkout and cart actions.
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
add_action( 'woocommerce_thankyou', array( $this, 'order_process' ), 10, 1 ); | ||
// order processed. | ||
add_action( 'woocommerce_checkout_order_processed', array( $this, 'order_process' ), 10, 1 ); | ||
add_action( 'woocommerce_store_api_checkout_order_processed', array( $this, 'order_process' ), 10, 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as described 👍
Proposed changes:
Problem:
The
woocommerceanalytics_product_purchase
event is currently triggered every time a user refreshes the order confirmation page, due to its reliance on thewoocommerce_thankyou
hook. This causes duplicate events, which is problematic, especially when users open the order confirmation page in another device/browser since we use this event to track completed checkouts and calculate conversion rates accurately.Solution:
This update resolves the issue by switching from the
woocommerce_thankyou
hook to thewoocommerce_checkout_order_processed
andwoocommerce_store_api_checkout_order_processed
hooks. These order processed hooks are triggered only once when the order is completed, ensuring the event is not duplicated on page refreshes.Additionally, I have modified the
capture_event_in_session_data
method to accept event properties and to standardize the order of its parameters.Other information:
Does this pull request change what data or activity we track or use?
No, this PR does not change what data we track. It only fixes the timing and frequency of when the existing
woocommerceanalytics_product_purchase
events are triggered to prevent duplicates.Testing instructions:
woocommerceanalytics_product_purchase
event is recorded in the Network tabwoocommerceanalytics_product_purchase
events are not recorded when refreshing the pageNote: You can also check the ClickHouse table to verify that the event is not recorded more than once.