From 6ae7b045a77d2953e2e0320d1be53c3c13546b54 Mon Sep 17 00:00:00 2001 From: Unchained Date: Mon, 30 Mar 2026 05:02:34 +0200 Subject: [PATCH] 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. --- src/app/[locale]/checkout/page.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/[locale]/checkout/page.tsx b/src/app/[locale]/checkout/page.tsx index 67ffd86..c85e866 100644 --- a/src/app/[locale]/checkout/page.tsx +++ b/src/app/[locale]/checkout/page.tsx @@ -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,