Targeting & Context
Control who sees what with evaluation context
Last updated:
Evaluation Context
When you call init() or refresh(), you can pass a context object that determines which flag values the user gets. Targeting rules in the dashboard match against these context properties.
await FeatureFlags.refresh({
userId: 'user-123',
plan: 'pro',
country: 'US',
betaTester: true,
});Context Properties
| Property | Type | Description |
|---|---|---|
userId | string | Your user’s ID. Used for percentage rollouts and user targeting. |
visitorId | string | SessionSight visitor ID. Enables segment-based targeting. |
| Custom properties | string \| number \| boolean | Any additional properties for targeting rules. |
Never send PII (emails, phone numbers, addresses, etc.) as context properties. Use opaque identifiers like user IDs instead.
Segment-Based Targeting
If you pass a visitorId in the context, flags can target users based on SessionSight segments. This lets you create rules like “show this feature to users in the ‘power-users’ segment.”
The visitorId is generated by the Insights SDK on the frontend. There are two ways to get it to your backend:
Option A: getVisitorId()
Call SessionSight.getVisitorId() on the frontend and send it to your backend:
// Option A: Your frontend sends the visitorId to your backend
const visitorId = SessionSight.getVisitorId();
// On your server:
await FeatureFlags.refresh({
userId: 'user-123',
visitorId, // from the frontend
});Option B: Read the ss_vid Cookie
The Insights SDK automatically sets a first-party cookie (ss_vid) on your domain. Your backend can read it directly from the request, no frontend changes needed:
// Option B: Read the ss_vid cookie directly (Node/Express)
const visitorId = req.cookies['ss_vid'];
await FeatureFlags.refresh({
userId: 'user-123',
visitorId,
});Targeting Rules
Targeting rules are configured in the SessionSight dashboard under Feature Flags → Flag Config. Each rule has:
- Conditions: Match against context properties (e.g.,
plan equals "pro") - Value: The flag value to return when conditions match
- Priority: Rules are evaluated top to bottom; first match wins
Condition Operators
| Operator | Description |
|---|---|
equals | Exact match |
not_equals | Does not match |
contains | String contains |
not_contains | String does not contain |
starts_with | String starts with |
ends_with | String ends with |
in | Value is in list |
not_in | Value is not in list |
greater_than | Numeric comparison |
less_than | Numeric comparison |
exists | Property is present |
not_exists | Property is not present |