Analytics: queued events, once-per-order revenue, heatmap on product pages (#17)
build / build (push) Successful in 1m7s

Analytics: queued events, once-per-order revenue, heatmap on product pages (#17)
Co-authored-by: Michael Czechowski <mail@librete.ch>
This commit was merged in pull request #17.
This commit is contained in:
libretech authored and Michael Czechowski committed 2026-10-15 04:18:09 +02:00
1 parent 61a74e649b
commit d5dd109c63
4 files changed
+145 -14

No files matched your search

+17
View File
@@ -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) {