Traits & Segments
Traits
Traits are key-value string pairs that describe the current user or context. Examples include plan: "enterprise", region: "us-east", or role: "admin". The SDK uses traits during flag evaluation to determine which segment a user belongs to.
Setting global traits
Call setTraits() once, typically at application startup or after authentication, to set traits that apply to every subsequent flag evaluation.
import { setTraits, flag } from "@deployramp/sdk";
setTraits({ plan: "enterprise", region: "us-east" });
// This evaluation uses the global traits
flag("new-dashboard");Per-evaluation overrides
You can pass traits directly to a flag() call to override or supplement the global traits for a single evaluation. This is useful when evaluating a flag on behalf of a different user or role.
// Override traits for a single evaluation
flag("admin-feature", { role: "admin" });Segments
Segments define conditions that match against traits. They let you target specific groups of users with independent rollout percentages. For example, you could roll out to 100% of enterprise users while keeping free-plan users at 10%.
Each segment has its own rollout percentage, so a flag can be at different stages for different audiences simultaneously.
Segment conditions
Conditions are configured in the DeployRamp dashboard. Three types of conditions are supported:
- Match: a single trait comparison.
plan == "enterprise" - And: all conditions must be true.
plan == "enterprise" AND region == "us-east" - Or: at least one condition must be true.
region == "us-east" OR region == "eu-west"
When a user matches multiple segments, the most specific segment takes priority. This gives you fine-grained control over who sees what, at every stage of a rollout.