Skip to content

Segments

Reusable targeting rules across multiple flags.

What are segments?

A segment is a named collection of targeting rules that can be referenced across multiple flags. Instead of duplicating rules in each flag, define them once in a segment.

Creating segments

Create segments via the dashboard or API:

bash
curl -X POST https://api.gatepost.dev/v1/segments \
  -H "Authorization: Bearer gp_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "premium-users",
    "name": "Premium Users",
    "rules": [
      { "type": "attribute", "attribute": "plan", "operator": "equals", "value": "premium" }
    ]
  }'

Using segments in flags

Reference segments in your SDK calls:

typescript
const enabled = await client.getBooleanValue("premium-feature", false, {
  segments: ["premium-users"]
});

Common use cases

Internal users

json
{
  "key": "internal-users",
  "rules": [
    { "type": "attribute", "attribute": "email", "operator": "contains", "value": "@yourcompany.com" }
  ]
}

Beta testers

json
{
  "key": "beta-testers",
  "rules": [
    { "type": "attribute", "attribute": "beta", "operator": "equals", "value": "true" }
  ]
}

Geographic targeting

json
{
  "key": "us-users",
  "rules": [
    { "type": "attribute", "attribute": "country", "operator": "in", "value": ["US", "CA"] }
  ]
}

AI-generated segments

Gatepost can generate segments from natural language using AI. In the segments page, click the AI button and describe your target audience:

"Premium users in the US with an enterprise plan"

The AI will create the appropriate rules automatically. Available on Pro+ plans.

OpenFeature compatible feature flags