Tracking ecommerce events: add to cart, purchase, and more

Capture the full ecommerce funnel — product views, cart adds, checkouts, purchases — to measure what experiments actually move revenue.

The standard tracker captures pageviews and clicks automatically. For ecommerce, you want richer signals: which products were viewed, what got added to cart, what was purchased and at what value. The tracker exposes a small ecommerce API for exactly this.

The API

Once the tracker is loaded, window.netaj.ecommerce exposes these methods:

// Product page view
netaj.ecommerce.productView({ id: "sku-1234", name: "T-Shirt", price: 199 });

// Add to cart
netaj.ecommerce.addToCart({ id: "sku-1234", name: "T-Shirt", price: 199, quantity: 1 });

// Begin checkout
netaj.ecommerce.checkout({ total: 597, items: 3 });

// Purchase complete
netaj.ecommerce.purchase({ orderId: "ORD-9876", total: 597, items: 3, currency: "SAR" });

// Search
netaj.ecommerce.search("white t-shirt");

// Wishlist
netaj.ecommerce.wishlist({ id: "sku-1234", name: "T-Shirt" });

// Coupon
netaj.ecommerce.coupon("SUMMER25", true);

Auto-detection

For Salla and Shopify stores, we auto-detect cart-count changes via the storefront badge — so add_to_cart fires without you adding code. purchase usually requires explicit instrumentation because order pages vary too much across themes.

Where to call them

  • productView — on the product detail page, after the page loads.
  • addToCart — on the click handler of your add-to-cart button (or rely on auto-detection).
  • checkout — when the user starts the checkout flow (cart → checkout button).
  • purchase — on the order-complete / thank-you page.

Use them as goals

Once an event has fired at least once, it shows up in the goal picker. Set __ecom_purchase__ as the goal of an experiment and you'll measure how variants affect actual revenue, not just clicks. More on goals here.

Privacy and PII

Don't include emails, names, or phone numbers in the event payload. Order IDs are fine — they're internal references. Product names and SKUs are fine. Customer-identifying data should never go through the tracker; that's what your CRM is for.

Was this article helpful?