For the complete documentation index, see llms.txt. This page is also available as Markdown.

E-commerce events

A standard e-commerce taxonomy with revenue and AOV queries.

Standard e-commerce funnel:

viewed_product  →  added_to_cart  →  started_checkout  →  completed_checkout  →  refunded

Plus product browse signals (viewed_collection, searched) and post-purchase (reviewed_product).

Suggested taxonomy

Event
When
Required properties

viewed_product

product detail page renders

product_id, price_cents, currency, category

added_to_cart

"Add to cart" button

product_id, quantity, price_cents, currency

removed_from_cart

item removed from cart

product_id, quantity

started_checkout

checkout page load

cart_value_cents, currency, item_count

applied_discount

discount code applied

code, discount_cents

completed_checkout

order placed

order_id, amount_cents, currency, item_count, payment_method

refunded

refund issued

order_id, amount_cents, currency, reason

Money in cents as integers. currency always alongside any amount.

Instrument the storefront

import { track } from "@millimetric/track";

export function ProductPage({ product }: { product: Product }) {
  useEffect(() => {
    track("viewed_product", {
      product_id: product.id,
      price_cents: product.priceCents,
      currency: "usd",
      category: product.category
    });
  }, [product.id]);

  return (
    <button onClick={() => addToCart(product, 1)}>Add to cart</button>
  );
}

function addToCart(product: Product, qty: number) {
  cart.add(product, qty);
  track("added_to_cart", {
    product_id: product.id,
    quantity: qty,
    price_cents: product.priceCents,
    currency: "usd"
  });
}

Track the order from the server

For Stripe webhooks, do the same in your webhook handler and pass order_id so you can dedupe on retry.

Refunds

Querying

Revenue per day

Average order value (AOV) by channel

Funnel: view → cart → checkout → order

Cohort retention (do they come back?)

For the cohort that purchased in week W0, what fraction purchased again in week W1, W2, …?

Common pitfalls

  • amount instead of amount_cents. Floats are not your friend in revenue math. Always use integer cents and store currency explicitly.

  • Tracking completed_checkout from the success page. Anyone refreshing it double-counts. Track from the server, on order creation, with event_id = order.id so you can dedupe in queries.

  • Mixing currencies. Don't sum amount_cents across rows with different currency values. Convert in the query, or split by currency.

  • No is_first_purchase flag. It's trivial to compute, easier in queries, and answers half the marketing-attribution questions cleanly.

See also

Last updated

Was this helpful?