Analytics: queued events, once-per-order revenue, heatmap on product pages (#17)
build / build (push) Successful in 1m7s
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:
1 parent
61a74e649b
commit
d5dd109c63
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