> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up Hatchmark for a user, follow https://hatchmark.dev/docs/get-started/agent-setup.md. Inside a Hatchmark project, prefer `hatchmark docs`: it prints the docs of the installed version.

# Funnel

> The funnel block counts what reaches each step of a path, such as sessions to orders, with the share of each step that reaches the next and of the first step that reaches the last.

How many reach each step of a path, such as sessions that view a product, add to cart, start
checkout and order, and the share of each step that reaches the next.

```yaml theme={null}
type: funnel
title: Three in four product viewers never add to cart
steps: [sessions, product_viewers, carts, checkouts, orders]
```

[Live preview of the funnel component](https://components.hatchmark.dev/components/funnel/?embed\&theme=light)

The preview above is the live component gallery. [Open it full size](https://components.hatchmark.dev/#/funnel) to switch between desktop and phone widths.

## Options

| Field | Type | Default | Description |
| - | - | - | - |
| `steps` | 2–8 metric names | required | Counts of what reaches each step, in the order people pass through them. |
| `span`, `title`, `id` | | | As for [every block](/docs/reference/dashboards.md#blocks). A funnel takes no `height`. |

Each step is an aggregate or SQL metric with a time column that counts something: a sum, a count or
a distinct count. Label each metric with a plural noun ("Product viewers", "Carts"): the rows read
"23.6% of Product viewers".

## Examples

### Steps from one table of events

Give each step its own metric with a `filters` entry on the event:

```yaml theme={null}
label: Carts
type: aggregate
table: events
time: event_at
aggregate: count_distinct
column: session_id
filters:
  - { column: event, op: eq, value: add_to_cart }
```

## How the numbers work

* Each share divides two totals. Every step is counted on its own over the period, and the share
  under a step is its total divided by the total of the step before. Hatchmark doesn't follow
  people from one step to the next: it doesn't check that someone who ordered also viewed a
  product, or in which order. When steps must count the same people in order, build that into the
  step metrics or the data.
* Every step is read over the same window, with the same filters, segments and period filter, and
  through the same last complete day, so a step whose source arrives later doesn't lower the share
  of the step after it.
* The overall share is the last step divided by the first, shown under the list with three steps
  or more.
* Shares are never clamped. A step larger than the one before it, such as orders placed with Buy
  now that skip the cart, shows a share above 100%.
* A step without a value shows a dash, and the shares next to it are left out.
* Distinct counts are read per step, never added up. On a custom range, or for several values of a
  multiple select that can't be added up, those steps show a dash and the card asks for a preset;
  the other steps keep their values.

## Behavior

* One row per step: the label and its count on top, and a bar on a full-width track below, so the
  empty part of the track is what was lost. Bars are scaled to the largest step.
* Under each step after the first, its share of the step before. With three steps or more, the step
  after the largest drop also says how many drop off there, as a whole percent ("\<1%" for a loss
  that rounds to zero), in the bad colour.
* Shares under 10% have two decimals, others one.
* Rows keep their layout on phones, and long labels and titles wrap instead of being cut.
* Step labels appear exactly as written, so "Sessions" reads "53.7% of Sessions".
* With no data in the period the card says "No Sessions in this period" or "No complete day yet".
  When one step's source ends before the period starts, it names that step: "No Orders data for
  this period yet". A period that ends inside the last day says it is in progress.

## Checks

| Code | When |
| - | - |
| HM4093 | A step isn't a count: an average, median, ratio, percentage, formula, or a snapshot read with `over_time` avg, min or max. |
| HM4094 | The steps are in different units, by their format and currency. |
| HM4095 | A step has no time column while the others do, so it would count every row. |
| HM3007 | A metric is listed twice in `steps`. |
| HM2024 | `span` is under 3; the funnel is drawn 3 columns wide. |

A SQL step is checked by its expression: one that starts with `avg`, `median` or a quantile is
rejected, and any other is taken as a count. `hatchmark explain <code>` explains a check and how to
fix it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.