export const grossRevenueDaily: MetricDefinition = {
id: "gross_revenue_daily",
label: "Gross revenue",
calcVersion: 1,
unit: "cents",
description: "Sum of order line items before discounts, excl. shipping/tax, order-dated.",
compute: (date, data) => ordersOn(date, data).reduce((s, o) => s + o.grossCents, 0),
};
export const netRevenueDaily: MetricDefinition = {
id: "net_revenue_daily",
label: "Net revenue",
calcVersion: 1,
unit: "cents",
description: "Gross minus discounts (order-dated) minus refunds issued that day (refund-dated).",
compute: (date, data) =>
ordersOn(date, data).reduce((s, o) => s + o.grossCents - o.discountCents, 0) -
refundsOn(date, data).reduce((s, r) => s + r.amountCents, 0),
};
export const ordersDaily: MetricDefinition = {
id: "orders_daily",
label: "Orders",
calcVersion: 1,
unit: "count",
description: "Number of orders placed, order-dated.",
compute: (date, data) => ordersOn(date, data).length,
};
export const aovDaily: MetricDefinition = {
id: "aov_daily",
label: "Average order value",
calcVersion: 1,
unit: "cents",
description: "Average order value: (gross - discounts) / orders, rounded to the cent. 0 when no orders.",
compute: (date, data) => {
const orders = ordersOn(date, data);
if (orders.length === 0) return 0;
const net = orders.reduce((s, o) => s + o.grossCents - o.discountCents, 0);
return Math.round(net / orders.length);
},
};Metric definitions

