Segments
Segments let you group users based on behavior, attributes, and rules. Use segments to target content variants and understand your audience.
Segments are now context dimensions with
sourceType: 'segment'. Membership is a rule (evaluationRules) evaluated fresh on every request intosegment.<key>— there is no precomputed membership table or evaluation mode. Author them in the console Context Dimensions editor or as code withcontextDimensions:.
Overview
A segment is a named group of users defined by rules. Users automatically enter or leave segments as their attributes and behavior change.
VIP Users
Rule: Total spend > 500 AND Order count > 5
→ segment.vip-users = true, for the user making this requestThere is no count of “how many users match”. Membership is not a set the platform holds; it is a rule answered for one user at a time, at the moment they ask for content.
Key Concepts
- Rules define who belongs using conditions on user attributes and behaviour
- Evaluated per request, always — there is no batch mode and no stored membership
- Nested segments allow rules that reference other segments
In the console
Creating a Segment
- Go to Settings > Context Dimensions
- Click Create
- Configure:
- Name: “VIP Users”
- Key:
vip-users - Source type:
segment - Description: optional explanation
- Rules: the conditions that make it true
- Click Save, then Publish to promote the draft
Building Rules
Segment rules use the same expression system as targeting rules. Combine conditions with AND/OR logic.
What a rule can read
A segment rule reads the request’s context, as context operands:
user.<field>: a field of the signed-in user’s record in the project’s user-context model (total spend, order count, tags, whatever that model declares). An installed app can write that record, which is how data it syncs reaches a rule- the request’s own context dimensions, by key
segment.<key>: whether the user is in another segment
A rule does not see the record being resolved, so a field operand never matches in a segment rule.
Example Rules
High-Value Users:
user.totalSpend > 500 AND user.orderCount > 5Using Segments
For Variant Targeting
Segments are commonly used in targeting rules to show different content to different user groups:
Priority 20: Segment is "vip-users" -> VIP variant
Priority 10: Device is mobile -> Mobile variant
Priority 0: Default -> Standard variantSegment membership is evaluated on every content resolution, so users automatically enter and exit segment-targeted variants as their membership changes (e.g. when they cross a spending threshold). Anonymous visitors never match segment rules — segments are user-bound, so the visitor must be signed in. Use context-based targeting (device, locale) to differentiate anonymous traffic.
Nested Segments
A segment’s rule can reference another segment by its segment.<key> path — “in
VIP and not in Lapsed”. The resolver topologically sorts the project’s
segments so a dimension that references another is evaluated after it.
A cycle is not rejected on save. Two segments that reference each other fall
back to their declared order, and the one evaluated first reads the other as
absent, which the expression evaluator treats as false. So a cycle does not
error and does not hang — it silently makes one of the two segments false. Read
_segments with a targeting:debug key if a nested rule is not behaving.
Via the CLI
A segment is a context dimension with sourceType: 'segment', so it is
managed through foir context-dimensions (aliased foir context-dims) — there
is no foir segments command group.
# List the project's context dimensions
foir context-dimensions list
# Get one by id or key
foir context-dims get vip-users
# Create a segment dimension
foir context-dims create --data '{
"key": "vip-users",
"name": "VIP Users",
"sourceType": "segment",
"evaluationRules": {
"type": "group",
"logicalOperator": "AND",
"conditions": [
{
"type": "condition",
"left": { "type": "context", "path": "user.totalSpend" },
"operator": "greater_than",
"right": { "type": "literal", "value": 500 }
}
]
}
}'
# Update it, then release the draft
foir context-dims update <id> --data '{"name": "Premium Users"}'
foir release publish context_dimension:vip-users
# Remove it
foir context-dims delete <id>--file <path> takes the same JSON from disk, which is easier to review than a
quoted rule tree on the command line.
The declarative route is better still: put the dimension in foir.config.ts
and let foir push create, update and prune it. See
Defining Context Dimensions.
There is no CLI command to preview which users match a rule, or to test one
user against one segment. Membership is not stored — the rule is evaluated
fresh on every request inside record resolution — so there is no set to list.
Read segment.<key> off a resolved record to see the answer for the user
making that request.
Segments and the public API
Segments are defined and managed through the console and CLI — there is no public GraphQL query for creating or editing them.
segmentMemberships was removed
Earlier versions of this page described a root query segmentMemberships(userId: String!): [String!]!. It no longer exists, and a call naming it is pruned from your document before execution:
{
"data": null,
"errors": [{ "message": "nothing in this query exists in the schema, so there was nothing left to run: \"segmentMemberships\" is not a field of Query. Every removal is listed in extensions.pruned." }],
"extensions": {
"pruned": {
"selections": [
{ "path": "query.segmentMemberships", "reason": "unknown_field", "type": "Query" }
]
}
}
}What happened, so anyone who built against it can tell whether their code was ever working:
- The field was already a stub before it was removed. Its resolver returned an empty list unconditionally, and its own source said why — membership stopped being a stored table and became a rule evaluated fresh per request inside record resolution.
- It was then deleted outright on 2026-07-18, in the same change that added the replacement below. It was not renamed, so the old name resolves to nothing at all rather than to something with different behaviour.
So an integration that read it saw [] for some time, and then began failing. Neither result was ever a real membership answer.
What replaced it: _segments
Membership is no longer a query about a user. It is resolution metadata on the record you read, reporting the segment vector of the user whose credential made the request:
query GetPage {
page(naturalKey: "homepage") {
_id
_variant
_resolvedBy
_segments
}
}const page = await foir.page.findUnique({ naturalKey: 'homepage' });
// page._segments — JSON, `{ "vip-users": true, "uk-market": false }` or null_segments is on every record-bearing model type and comes back with the record, so the data client returns it with no extra call — the selection model is complete-by-default and foir types emits it as FoirJsonValue | null.
Three differences from the field it replaced, all of them load-bearing:
segmentMemberships | _segments | |
|---|---|---|
| Subject | any user, by their id | the resolving user only |
| Shape | list of keys they belong to | full vector, key → bool, including the false entries |
| Scope | none | targeting:debug |
The first row is the one that will bite a back-office tool. There is no way to ask “which segments is user X in”, not on the public API and not on the CLI. The replacement answers only “which segments is the caller in”, and that is not an omission to work around: membership stopped being a stored table and became a rule evaluated fresh inside the resolving user’s own request, so there is no set to query. To answer it for another user you would have to resolve a record as them.
_segments and _resolvedBy are omitted entirely for a key without targeting:debug, and also when there is nothing to report — an anonymous caller has no evaluated segments, and a non-variant record has no _resolvedBy — so an empty value never masquerades as data. _variant is ungated: the selected variant’s key alone carries no targeting logic.
Segments feed into targeting rules: when content is resolved, segment membership is evaluated as part of the targeting context, and the matching variant is returned. See Targeting & Context for how context values are passed and resolved.
Best Practices
- Start simple — begin with a few key segments before building complex rules.
- Use meaningful keys —
vip-usersis clearer thanseg-001. - Check the rule against a real resolution — read
_segmentsoff a record resolved with atargeting:debugkey to see the whole evaluated vector, including thefalseentries, rather than guessing which condition failed. - Document your segments — add descriptions so your team understands each segment’s purpose.
- Combine with targeting — segments are most powerful when used in variant targeting and experiments.