Docs/Concepts/

Contexts

Provide user and request information for flag evaluation and targeting

A context is the set of attributes you provide to the SDK that describes the current user or request. Flagpool uses the context to evaluate targeting rules and determine rollout bucketing.

Setting context

Context is provided when initializing the SDK and can be updated at any time:

const client = new FlagpoolClient({
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
  decryptionKey: 'your-decryption-key',
  context: {
    userId: 'user-123',
    email: 'jane@acme.com',
    plan: 'enterprise',
    country: 'US',
  },
})
<FlagpoolProvider
  projectId="your-project-id"
  apiKey="your-api-key"
  decryptionKey="your-decryption-key"
  context={{
    userId: 'user-123',
    email: 'jane@acme.com',
    plan: 'enterprise',
    country: 'US',
  }}
>
  <App />
</FlagpoolProvider>
client = FlagpoolClient(
    project_id="your-project-id",
    api_key="your-api-key",
    decryption_key="your-decryption-key",
    context={
        "userId": "user-123",
        "email": "jane@acme.com",
        "plan": "enterprise",
        "country": "US",
    },
)

Context attributes

A context is a flat key-value object. You can include any attributes that are relevant to your targeting rules.

Common attributes

AttributeTypePurpose
userIdstringUnique user identifier — required for deterministic rollouts
emailstringUser email — useful for contains rules (e.g., @company.com)
planstringSubscription tier — "free", "pro", "enterprise"
countrystringCountry code — "US", "DE", "JP"
organizationIdstringOrganization or team identifier

Custom attributes

You can add any business-relevant attributes:

{
  userId: 'user-123',
  plan: 'pro',
  role: 'admin',
  department: 'engineering',
  loginCount: 42,
  platform: 'ios',
  appVersion: '2.4.1',
  createdAt: '2024-01-15',
}

These attributes can all be referenced in targeting rules. For example, a rule like role eq "admin" will match any context where role is "admin".

The userId attribute

The userId attribute has special significance:

  • Rollout bucketing — percentage rollouts use hash(userId + flagKey) % 100 to assign users to buckets. Without a userId, rollouts are not deterministic.
  • Target lists — the inTargetList and notInTargetList operators typically match against userId (though they can match any attribute).

Always provide a userId if you use percentage rollouts or target lists. Without it, the same user may get different results across evaluations.

Updating context

Context can be updated after initialization — for example, after a user logs in:

// After login
client.updateContext({
  userId: user.id,
  email: user.email,
  plan: user.subscription.plan,
})
import { useFlagpool } from '@flagpool/react'

function AfterLogin() {
  const { setContext } = useFlagpool()
  const { user } = useAuth()

  useEffect(() => {
    if (user) {
      setContext({
        userId: user.id,
        email: user.email,
        plan: user.subscription.plan,
      })
    }
  }, [user, setContext])
}
# After login
client.update_context({
    "userId": user.id,
    "email": user.email,
    "plan": user.subscription.plan,
})

When context changes, all flags are re-evaluated automatically with the new values.

Privacy

Context attributes are never sent to Flagpool servers. All flag evaluation happens locally inside your application. The context exists only in memory within your SDK instance.

This is a core design principle of Flagpool — your user data stays in your application.

Next steps

Start Managing Feature Flags Today

Join teams who trust Flagpool to deliver features safely and efficiently.

No credit card required • Cancel anytime