Evaluation Context
How to pass user attributes for targeting and personalization
What Is Evaluation Context?
Evaluation context is a set of attributes you pass with every flag evaluation. It tells Versia who the user is and what they’re doing, so your flags can return the right variant.
Passing Context
Every OpenFeature SDK takes a context object as the last parameter.
Go
evalContext := openfeature.NewEvaluationContext(
"user-123", // targeting key (user ID)
map[string]interface{}{
"plan": "enterprise",
"country": "us",
"device": "mobile",
"age": 28,
},
)
variant, _ := client.StringValue(ctx, "banner-cta", "sign-up-free", evalContext)
Node.js
const context = {
targetingKey: 'user-123',
plan: 'enterprise',
country: 'us',
device: 'mobile',
age: 28,
};
const variant = await client.getStringValue('banner-cta', 'sign-up-free', context);
Python
context = EvaluationContext(
targeting_key="user-123",
attributes={
"plan": "enterprise",
"country": "us",
"device": "mobile",
"age": 28,
},
)
variant = client.get_string_value("banner-cta", "sign-up-free", context)
The Targeting Key
Every context must include a targeting key, a unique identifier for the user. This is how Versia ensures consistent behavior: the same user sees the same variant across evaluations.
Use whatever stable user ID you have: database ID, auth token subject, session ID for anonymous users.
Common Attributes
You can pass any attributes you want. Here are some common ones:
| Attribute | Example | Use case |
|---|---|---|
plan |
"free", "pro", "enterprise" |
Show different experiences by plan tier |
country |
"us", "de", "jp" |
Localized variants |
device |
"mobile", "desktop", "tablet" |
Device-specific layouts |
browser |
"chrome", "safari", "firefox" |
Browser-specific behavior |
role |
"admin", "member", "viewer" |
Permission-based features |
age |
28 |
Numeric comparisons |
beta |
true |
Boolean attributes |
How Context Is Used
Exclusion Rules
When you create an exclusion rule in the dashboard, the condition (e.g., plan eq "enterprise") is matched against the context attributes you pass. If a user’s context matches, they get the specified variation instead of the default rule.
For example, if you pass { plan: "enterprise" } and have an exclusion rule with condition plan eq "enterprise", that user will always receive the variation you’ve configured for that rule.
Reward-Driven Flags
For reward-driven flags, context attributes are used to learn per-segment preferences. If mobile users prefer one variant while desktop users prefer another, Versia will learn this automatically from the context you pass. No rules to configure.
The more relevant context you pass, the better Versia can personalize. But don’t overthink it: start with a few attributes and add more as needed.
Condition Operators
When writing exclusion rule conditions in the dashboard, these operators are available:
| Operator | Meaning | Example |
|---|---|---|
eq |
Equals | plan eq "enterprise" |
ne |
Not equals | plan ne "free" |
co |
Contains | email co "@acme.com" |
sw |
Starts with | name sw "test-" |
ew |
Ends with | email ew ".edu" |
gt |
Greater than | age gt 18 |
ge |
Greater than or equal | age ge 21 |
lt |
Less than | score lt 50 |
le |
Less than or equal | score le 100 |
Conditions match against the attributes you pass in the evaluation context. The attribute name in the condition (left side) must match the key name you use in your context object.
The special attribute key refers to the targeting key itself: key eq "premium-user".
Compound Conditions
You can combine multiple conditions with AND or OR:
- AND:
plan eq "enterprise" and country eq "us"(both must match) - OR:
plan eq "enterprise" or plan eq "business"(either can match)
Tips
- Be consistent. Pass the same attribute keys every time. If you use
planin one place andsubscriptionin another, your rules won’t match. - Keep values simple. Lowercase strings work best. Avoid spaces or special characters in attribute values.
- The targeting key matters. It’s the primary identifier for consistent variant assignment. Use a stable user ID, not a session token that changes.
- Start small. You don’t need to pass everything. Start with 2-3 attributes that matter for your use case.