Analytics: queued events, once-per-order revenue, heatmap on product pages
build / build (pull_request) Successful in 1m10s
build / build (pull_request) Successful in 1m10s
trackEvent queues events until the deferred Umami script exists (they were dropped when fired in onMounted) and drops them silently after 10 s. The result page sends purchase-completed with revenue/currency once per order (localStorage guard, set only after sending). The plugin honours Do Not Track and loads recorder.js only on /details/* for Umami heatmaps. bun test utils/trackEvent.test.ts: 4 pass. Netcup #115.
This commit is contained in:
4 files changed
+145
-14
No files matched your search
@@ -151,6 +151,23 @@ onMounted(async () => {
|
||||
orderTotal: order.value.total,
|
||||
itemCount: order.value.cart?.length ?? 0
|
||||
});
|
||||
|
||||
// Revenue for Umami's revenue report: exactly once per order, even if the
|
||||
// customer reloads this page or opens it again from the confirmation mail.
|
||||
const purchaseKey = `mp-purchase-tracked-${order.value.uuid}`;
|
||||
if (!localStorage.getItem(purchaseKey)) {
|
||||
const products = (order.value.cart ?? []).map((item) => item.product?.slug).filter(Boolean);
|
||||
trackEvent(
|
||||
"purchase-completed",
|
||||
{
|
||||
revenue: order.value.total,
|
||||
currency: "EUR",
|
||||
itemCount: (order.value.cart ?? []).reduce((sum, item) => sum + (item.count ?? 1), 0),
|
||||
products: products.join(",").slice(0, 400)
|
||||
},
|
||||
() => localStorage.setItem(purchaseKey, new Date().toISOString())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.value?.invoice?.url) {
|
||||
|
||||
Reference in new issue
Block a user