Skip to Content
DocsGuidesE-Commerce Tracking

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:

EventTriggerKey properties
product_viewedProduct detail page loadproduct_id, product_name, price, category
add_to_cartItem added to cartproduct_id, quantity, price
remove_from_cartItem removed from cartproduct_id, quantity
checkout_startedCheckout page loadcart_value, item_count
purchaseOrder confirmedrevenue, 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

  1. Events — confirm all commerce events appear with revenue as a number
  2. Insights — build funnel: product_viewed → add_to_cart → checkout_started → purchase
  3. Dashboards — pin revenue KPI and purchase funnel tiles

Revenue analysis

  • Use Sum aggregation on revenue for total revenue
  • Use Unique users on purchase for unique buyers
  • Breakdown by $geo.country for regional revenue

Common mistakes

MistakeFix
revenue as stringPass as number: 29.99 not '29.99'
Purchase on checkout pageFire on order confirmation only
Missing immediate: truePurchase lost on redirect

Further reading

Last updated on