Segments
Segments are named subsets of profiles defined by an executable rule. Use them in campaigns, lookups, and the Studio.
Two ways to define
Natural languagein the Studio chat: "trial users who haven't logged in for 7 days". The chat compiles to JSON, shows the SQL preview, and you save once it looks right.
JSON directly via the API — useful for code-managed segments.
Rule shape
{
"all": [
{ "trait": "plan", "op": "eq", "value": "trial" },
{ "lastEventBefore": { "type": "session.started", "since": "7d" } }
]
}Supported predicates
trait— equality / comparison onprofiles.traitsJSONBhasEvent— profile fired this event type within a windowlastEventBefore— last event of this type was before N days agoinSegment— composition: include profiles in another segmentall/any— boolean combinators
Performance
Segments compile to a single SQL query against profiles + events. The events table is indexed by (workspace_id, profile_id, type, timestamp) — large workspaces stay fast because we only scan within the workspace partition.
Materialization
Segments are evaluated at use (no caching, no nightly rebuild). If you need a frozen audience for a campaign, snapshot to a tag on profiles. Materialized segments are coming in Phase 9 when ClickHouse lands for analytical workloads.