The store's funnel
Tell the store what shoppers do on your storefront, so its analytics show the funnel from visit to order. Anonymous, and nothing is sent without consent when you ask for it.
Track what happens
await shop.analytics.track({ kind: "page_view", path: "/products/oud-noir" });
await shop.analytics.track({ kind: "product_view", productId });
await shop.analytics.track({ kind: "add_to_cart", productId, variantId });page_viewA page seen.pathwithout its language prefix.product_viewA product looked at:productId, andvariantIdwhen one is chosen.article_viewA blog article read:articleIdandblogId.add_to_cartAn add that worked:productIdandvariantId.checkout_started, checkout_completedThe hosted checkout counts these itself. Send them only from a checkout of your own, withorderIdon the second.
Every event can carry occurredAt; it's when it was sent otherwise, and events over a day old are dropped. track takes one event or a list, oldest first, and sends them 50 at a time.
Visitors and visits
The client keeps an anonymous visitor ID in its storage, and a visit ID that renews after 30 minutes without activity. The first events of a visit carry where it began: in a browser, the page's address and referrer unless you pass landing: { url, referrer }.
The API leaves out bots, and shoppers who opted out with DNT or Sec-GPC.
Consent
With a consent banner, pass its answer:
await shop.analytics.track(events, { consent: shopperAgreed });consent: false sends nothing and keeps nothing, not even the visitor's ID.
In Next.js
The starter's components/funnel.tsx sends a page_view on every navigation, a product_view on product pages, and an add_to_cart when the cart action comes back to /cart?added=. It never breaks a page: a failed send is ignored.
Was this page helpful?
Updated 25 Nov 2026