fix: Track order completion BEFORE clearing checkout

The checkout was being cleared before tracking, causing getTotal()
to return 0. Fixed by reordering operations:
1. Track order completion (while checkout data exists)
2. Then clear the checkout

Added console log to verify total is captured correctly.
This commit is contained in:
Unchained
2026-03-30 05:02:34 +02:00
parent 05b0a64c84
commit 6ae7b045a7

View File

@@ -307,12 +307,10 @@ export default function CheckoutPage() {
setOrderNumber(result.order.number);
setOrderComplete(true);
// Clear the checkout/cart from the store
clearCheckout();
// Track order completion
// Track order completion BEFORE clearing checkout
const lines = getLines();
const total = getTotal();
console.log("[Checkout] Order total before tracking:", total, "RSD");
trackOrderCompleted({
order_id: checkout.id,
order_number: result.order.number,
@@ -323,6 +321,9 @@ export default function CheckoutPage() {
customer_email: shippingAddress.email,
});
// Clear the checkout/cart from the store
clearCheckout();
// Identify the user
identifyUser({
profileId: shippingAddress.email,