diff --git a/src/app/api/webhooks/saleor/route.ts b/src/app/api/webhooks/saleor/route.ts index 0e6fd7a..f49c978 100644 --- a/src/app/api/webhooks/saleor/route.ts +++ b/src/app/api/webhooks/saleor/route.ts @@ -163,28 +163,29 @@ async function handleOrderConfirmed(order: Order, eventType: string) { // Send customer email only for ORDER_CONFIRMED (not ORDER_CREATED) if (eventType === "ORDER_CONFIRMED") { await orderNotificationService.sendOrderConfirmation(order); + + // Track revenue and order analytics only on ORDER_CONFIRMED (not ORDER_CREATED) + // This prevents duplicate tracking when both events fire for the same order + analyticsService.trackOrderReceived({ + orderId: order.id, + orderNumber: order.number, + total: order.total.gross.amount, + currency: order.total.gross.currency, + itemCount, + customerEmail: order.userEmail, + eventType, + }); + + analyticsService.trackRevenue({ + amount: order.total.gross.amount, + currency: order.total.gross.currency, + orderId: order.id, + orderNumber: order.number, + }); } // Send admin notification for both events await orderNotificationService.sendOrderConfirmationToAdmin(order); - - // Track analytics (fire and forget - don't await) - analyticsService.trackOrderReceived({ - orderId: order.id, - orderNumber: order.number, - total: order.total.gross.amount, - currency: order.total.gross.currency, - itemCount, - customerEmail: order.userEmail, - eventType, - }); - - analyticsService.trackRevenue({ - amount: order.total.gross.amount, - currency: order.total.gross.currency, - orderId: order.id, - orderNumber: order.number, - }); } async function handleOrderFulfilled(order: Order) {