# The store's funnel

Source: https://snizu.dev/docs/storefronts/analytics

## Track what happens [#track-what-happens]

```ts title="funnel.ts"
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 });
```

<Fields>
<Field name="page_view">
A page seen. `path` without its language prefix.
</Field>

<Field name="product_view">
A product looked at: `productId`, and `variantId` when one is chosen.
</Field>

<Field name="article_view">
A blog article read: `articleId` and `blogId`.
</Field>

<Field name="add_to_cart">
An add that worked: `productId` and `variantId`.
</Field>

<Field name="checkout_started, checkout_completed">
The hosted checkout counts these itself. Send them only from a checkout of your own, with `orderId` on the second.
</Field>
</Fields>

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 [#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 [#consent]

With a consent banner, pass its answer:

```ts title="funnel.ts"
await shop.analytics.track(events, { consent: shopperAgreed });
```

`consent: false` sends nothing and keeps nothing, not even the visitor's ID.

## In Next.js [#in-nextjs]

The [starter](/docs/storefronts/nextjs-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.