Compare commits
2
Commits
eb9a798d40
...
4a63098e3e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a63098e3e | ||
|
|
2e6668ff0d |
@@ -163,28 +163,29 @@ async function handleOrderConfirmed(order: Order, eventType: string) {
|
|||||||
// Send customer email only for ORDER_CONFIRMED (not ORDER_CREATED)
|
// Send customer email only for ORDER_CONFIRMED (not ORDER_CREATED)
|
||||||
if (eventType === "ORDER_CONFIRMED") {
|
if (eventType === "ORDER_CONFIRMED") {
|
||||||
await orderNotificationService.sendOrderConfirmation(order);
|
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
|
// Send admin notification for both events
|
||||||
await orderNotificationService.sendOrderConfirmationToAdmin(order);
|
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) {
|
async function handleOrderFulfilled(order: Order) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class AnalyticsService {
|
|||||||
|
|
||||||
async trackRevenue(data: RevenueData): Promise<void> {
|
async trackRevenue(data: RevenueData): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
console.log(`Tracking revenue: ${data.amount} ${data.currency} for order ${data.orderNumber}`);
|
||||||
await op.revenue(data.amount, {
|
await op.revenue(data.amount, {
|
||||||
currency: data.currency,
|
currency: data.currency,
|
||||||
order_id: data.orderId,
|
order_id: data.orderId,
|
||||||
|
|||||||
Reference in New Issue
Block a user