Skip to content
caliper ui pro docs

Segment builder

Build an audience from conditions joined by all or any, in nested groups, and watch its size move as you go: the estimate counts to each new figure and its share of everyone fills a bar. Alt+Enter adds a condition below the one you are in; Alt+Backspace removes it.

Pro

Estimated audience

10,524visitors

21.8% of 48.2k

Filter visitors

Showing visitors where Device is any of Mobile, and Visits ≥ 3.

Conditions
Match
of these

In a condition, Option Enter adds one below and Option Backspace removes it.

Estimated from 1,200 recent visitors.

When to use

  • Audience and cohort definitions in analytics, messaging or experiment targeting.
  • Any filter whose result size decides whether it is worth saving.

When not to use

  • Filtering a table in place; use the query builder on its own.
  • Estimates that take seconds to compute on every keystroke; pass `estimating` and debounce on the host.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/segment-builder

Adds its 42 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.

API reference

SegmentBuilder

11 props
PropTypeDefaultDescription
fields *readonly QueryField[]—
value *QueryGroup—
onChange *(query: QueryGroup) => void—
estimate *(query: QueryGroup) => number—How many match the query. Kept cheap: it runs on every change.
total *number—Everyone the audience is drawn from.
nounstring"people"Plural, e.g. "visitors".
segmentsreadonly QuerySegment[]—
onSegmentsChange((segments: QuerySegment[]) => void)—
estimatingboolean—The host is recounting; the last figure stays, marked as updating.
errorstring—The estimate failed; the rules still edit.
classNamestring—

addRuleAfter

4 props
PropTypeDefault
kind *"group"—
id *string—
combinator *"and" | "or"—
children *readonly (QueryGroup | QueryRule)[]—

removeRule

4 props
PropTypeDefault
kind *"group"—
id *string—
combinator *"and" | "or"—
children *readonly (QueryGroup | QueryRule)[]—

flattenRules

4 props
PropTypeDefault
kind *"group"—
id *string—
combinator *"and" | "or"—
children *readonly (QueryGroup | QueryRule)[]—

Keyboard

Enter
Activates the focused control.

Accessibility

It exposes alert semantics, with aria-labelledby, aria-busy and aria-hidden kept in step with state. Changes that matter are announced through a live region.

Notes for AI

Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.

/docs/components/segment-builder.md

The index of every part is at /llms.txt.

More in Metrics