From 7d1a9eab1ed03642534c5f84c06a5a1ace57cc09 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 26 Dec 2023 19:11:48 +0800 Subject: [PATCH 1/2] Fix the incompatible data structure that causes JS exceptions when sending checkout event tracking for issue #341. --- assets/js/src/tracking.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assets/js/src/tracking.js b/assets/js/src/tracking.js index 63329121..767698ac 100644 --- a/assets/js/src/tracking.js +++ b/assets/js/src/tracking.js @@ -104,6 +104,15 @@ export const trackCheckoutStep = return; } + // compatibility-code "WC >= 8.1" -- The data structure of `storeCart` was (accidentally) changed. + if ( ! storeCart.hasOwnProperty( 'cartTotals' ) ) { + storeCart = { + cartCoupons: storeCart.coupons, + cartItems: storeCart.items, + cartTotals: storeCart.totals, + }; + } + trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', { items: storeCart.cartItems.map( getProductFieldObject ), coupon: storeCart.cartCoupons[ 0 ]?.code || '', From d11c90839b65dfa210989f7f5cd23a3568957ccf Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 26 Dec 2023 19:13:22 +0800 Subject: [PATCH 2/2] Fix the incorrect `quantity` value when sending checkout event tracking for issue #342. --- assets/js/src/tracking.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/js/src/tracking.js b/assets/js/src/tracking.js index 767698ac..56e0a7ec 100644 --- a/assets/js/src/tracking.js +++ b/assets/js/src/tracking.js @@ -114,7 +114,9 @@ export const trackCheckoutStep = } trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', { - items: storeCart.cartItems.map( getProductFieldObject ), + items: storeCart.cartItems.map( ( item ) => + getProductFieldObject( item, item.quantity ) + ), coupon: storeCart.cartCoupons[ 0 ]?.code || '', currency: storeCart.cartTotals.currency_code, value: formatPrice(