Docs

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.

typescript
await FeatureFlags.refresh({
  userId: 'user-123',
  plan: 'pro',
  country: 'US',
  betaTester: true,
});

Context Properties

PropertyTypeDescription
userIdstringYour user’s ID. Used for percentage rollouts and user targeting.
visitorIdstringSessionSight visitor ID. Enables segment-based targeting.
Custom propertiesstring \| number \| booleanAny 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:

typescript
// 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
});

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:

typescript
// 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

OperatorDescription
equalsExact match
not_equalsDoes not match
containsString contains
not_containsString does not contain
starts_withString starts with
ends_withString ends with
inValue is in list
not_inValue is not in list
greater_thanNumeric comparison
less_thanNumeric comparison
existsProperty is present
not_existsProperty is not present