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

# Smart segments

> Define dynamic audiences that update as customer data and behaviour change.

A **segment** is a query that resolves to a set of users. Its membership reflects matching user data when the segment is evaluated. You do not maintain it by hand.

## What you can segment on

Spotzee rules operate over two groups:

* **User attributes**: any standard or custom field on a user, including nested `data.*` fields (`data.plan`, `data.lifetime_value`, etc.).
* **Events**: any tracked event, optionally combined with a frequency window.

Anything you want to segment on must be one of the two. Sync external state into `data.*` if you need it as a filter input.

## Operators by field type

Each rule node has a typed comparison. Operators are scoped to the rule type.

| Rule type | Operators |
| - | - |
| `string` | `=`, `!=`, `contains`, `not contain`, `starts with`, `not start with`, `is set`, `is not set`, `empty` |
| `number` | `=`, `!=`, `<`, `<=`, `>`, `>=`, `is set`, `is not set` |
| `date` | `=`, `!=`, `<`, `<=`, `>`, `>=`, `is same day`, `is set`, `is not set` |
| `boolean` | `=`, `!=` |
| `array` | `=`, `!=`, `contains`, `empty`, `is set`, `is not set` |
| `wrapper` (combinator) | `and`, `or` |

The API also recognises `shopify_purchase` rules for synced Shopify product or collection IDs. The segment builder does not currently expose that rule type.

## Event frequency

Event rules express "happened how often, when" via an optional `frequency` block:

* `count`: how many times the event occurred, with a comparison operator (`=`, `<`, `<=`, `>`, `>=`).
* `period`: the window the count applies to. Either a rolling window (`unit: hour | minute | day | week | month | year`, `value: N`) or a fixed range (`start_date`, optional `end_date`).

Use the rolling window for "in the last 30 days"-style rules. Use the fixed range for "between Black Friday and Cyber Monday"-style cohorts.

## Build a segment

**1. Pick a base**

Start from **all users** or from another segment.

**2. Add filters**

Combine conditions with **AND** / **OR**. Group conditions with parentheses for complex logic.

**3. Preview**

The segment editor shows live count and a sample of matched users.

**4. Save and use**

Reference the segment from any journey entrance, campaign audience, or send step.

## Common patterns

* **Engaged in last 30 days**: `email_opened` or `email_clicked` event with frequency `count >= 1`, rolling 30-day window.
* **At-risk**: `email_opened` last occurrence > 60 days ago AND `data.lifetime_value > 500`.
* **High-intent**: `page_viewed` with `data.path = "/pricing"`, frequency `count >= 1` over rolling 7 days, AND `data.is_customer = false`.

## Reference

Segments are exposed as **dynamic Lists** in the API:

* Create / list / update / delete: see [Main API → Lists](https://spotzee.com/docs/main-api/introduction.md)
* Programmatic walkthrough: see [Build a segment via the API](https://spotzee.com/docs/guides/build-segment-via-api.md)

## Next

> [card] [Build a journey](https://spotzee.com/docs/guides/journeys.md)
>
> Use a segment as the audience.

> [card] [Send events from your backend](https://spotzee.com/docs/guides/event-ingestion.md)
>
> Get behavioural data into Spotzee so segments can react to it.


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