Skip to content

Commit

Permalink
Merge pull request #343 from woocommerce/fix/341-342-checkout-event-t…
Browse files Browse the repository at this point in the history
…racking

Fix the JS exceptions and incorrect `quantity` value for checkout event tracking
  • Loading branch information
eason9487 authored Dec 28, 2023
2 parents 64e7dda + d11c908 commit c05be3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion assets/js/src/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ 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 ),
items: storeCart.cartItems.map( ( item ) =>
getProductFieldObject( item, item.quantity )
),
coupon: storeCart.cartCoupons[ 0 ]?.code || '',
currency: storeCart.cartTotals.currency_code,
value: formatPrice(
Expand Down

0 comments on commit c05be3b

Please sign in to comment.