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