Skip to content

Targeting and rollouts

Targeting is configured per environment with a management key (vsk_live_…) against the REST base https://statskit.ai/api/v1. The server applies these rules and returns only resolved values to browser clients, the rules themselves never cross the wire to public keys.

For a given context, an environment resolves a flag in this order:

  1. Off? If the flag is disabled in this environment, serve its offVariation.

  2. A rule matches? Serve that rule’s variation (or its weighted rollout).

  3. Fallthrough. Serve the environment’s default variation (or its rollout).

Set the on/off state, the off variation, and the fallthrough for one environment:

PUT /v1/flags/:key/environments/:env
{
"enabled": true,
"offVariation": 1,
"fallthrough": { "variation": 0 }
}

A weighted rollout splits traffic across variations by weight. Bucketing is deterministic on the context key, so a given user stays in the same bucket as you dial the weights up.

Rules serve a specific variation (or rollout) to contexts that match a set of clauses. A clause is either attribute op values or a segment match, and rules combine clauses with and/or.

PUT /v1/flags/:key/environments/:env/rules
{
"rules": [
{
"clauses": [
{ "attribute": "plan", "op": "in", "values": ["pro", "enterprise"] },
{ "attribute": "country", "op": "in", "values": ["US", "CA"] }
],
"serve": { "variation": 0 }
},
{
"clauses": [
{ "segment": "beta-testers", "op": "segmentMatch" }
],
"serve": { "rollout": [ { "idx": 0, "weight": 50 }, { "idx": 1, "weight": 50 } ] }
}
]
}

Rules are evaluated top to bottom; the first match wins. A context that matches no rule falls through.

A segment is a reusable targeting group, define who’s in it once and reference it from any flag’s clauses with segmentMatch. Update the segment and every flag that references it changes at the next publish. See the segments API.

Flip a flag off (or back on) in one environment without touching its config:

POST /v1/flags/:key/environments/:env/toggle

When off, the flag serves its offVariation to everyone, bypassing all rules. This is the fast path to disable a feature in production.

Before you target it, a flag must exist. Create one with:

POST /v1/flags
{
"key": "new-checkout",
"name": "New checkout",
"description": "Redesigned checkout flow",
"type": "boolean",
"variations": [
{ "idx": 0, "value": true, "name": "on" },
{ "idx": 1, "value": false, "name": "off" }
],
"temporary": true,
"bucketBy": "key",
"tags": ["checkout"]
}

See the full flags API reference for every field and endpoint.