E-Commerce Tracking
Track the full purchase funnel from product discovery to checkout. This guide walks through instrumentation, identity, and dashboard setup for an online store.
Tracking plan
Define your events before writing code:
| Event | Trigger | Key properties |
|---|---|---|
product_viewed | Product detail page load | product_id, product_name, price, category |
add_to_cart | Item added to cart | product_id, quantity, price |
remove_from_cart | Item removed from cart | product_id, quantity |
checkout_started | Checkout page load | cart_value, item_count |
purchase | Order confirmed | revenue, currency, order_id, item_count |
All commerce events are well-known events with typed schemas.
SDK instrumentation
Product views
track('product_viewed', {
product_id: 'sku-123',
product_name: 'Running Shoes',
price: 89.99,
category: 'Footwear'
})Cart events
function addToCart(product: Product) {
track('add_to_cart', {
product_id: product.id,
quantity: 1,
price: product.price
})
}Purchase — use immediate flush
async function onOrderConfirmed(order: Order) {
identify(order.userId, { email: order.email })
track('purchase', {
revenue: order.total,
currency: 'USD',
order_id: order.id,
item_count: order.items.length
}, { immediate: true })
}Identify at the right moment
Call identify() when you have a stable user ID — at account creation or checkout:
if (currentUser) {
identify(currentUser.id, { email: currentUser.email, plan: currentUser.plan })
}Dashboard setup
- Events — confirm all commerce events appear with
revenueas a number - Insights — build funnel:
product_viewed → add_to_cart → checkout_started → purchase - Dashboards — pin revenue KPI and purchase funnel tiles
Revenue analysis
- Use Sum aggregation on
revenuefor total revenue - Use Unique users on
purchasefor unique buyers - Breakdown by
$geo.countryfor regional revenue
Common mistakes
| Mistake | Fix |
|---|---|
revenue as string | Pass as number: 29.99 not '29.99' |
| Purchase on checkout page | Fire on order confirmation only |
Missing immediate: true | Purchase lost on redirect |
Further reading
Last updated on