> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Feature Flag Integration

> Include observed feature flag variants and align targeting context across SDKs.

## How Feature Flag Integration Works

The Recording SDK works with the Confidence JavaScript SDK and the Confidence
OpenFeature web provider. Recordings include feature flag variants that these SDKs
evaluate in the same browser.

You can find the observed flags and variants in recording details. You can also use
them to filter the Recordings list.

Server-side flag evaluations do not appear automatically because they occur outside
the recorded browser.

## Align Targeting Context

The Feature Flag SDK and Recording SDK receive context separately:

* Feature flag context controls flag targeting and assignment.
* Recording context controls recording rules and sampling.

One SDK does not copy context to the other. Pass the same identifiers and targeting
attributes to both SDKs when their rules must select the same users.

```typescript theme={null}
import { Confidence } from '@spotify-confidence/sdk';
import { initSessionRecorder } from '@spotify-confidence/session-recording';

const sharedContext = {
  user_id: 'user-123',
  plan: 'premium',
};

const confidence = Confidence.create({
  clientSecret: '<feature-flag-client-secret>',
  environment: 'client',
  timeout: 1000,
});

confidence.setContext(sharedContext);

const recorder = initSessionRecorder({
  clientSecret: '<recording-client-secret>',
  context: sharedContext,
});
```

Use the same field name and value for the targeting entity in both sets of rules. For
example, if the feature flag rule targets `user_id`, select `user_id` in the recording
rule and pass the same value to both SDKs.

## Keep Context Stable

The Recording SDK uses the context supplied during initialization. Later changes to
the feature flag context do not update the recording context.

Initialize both SDKs after you have the identifiers and attributes needed for
targeting. Keep personal data, access tokens, and secrets out of both contexts.

## What Context Alignment Changes

Context alignment makes recording and feature flag rules target users consistently.
It does not control whether observed feature flag variants appear in a recording.

For example, matching context lets both rule sets target premium users. If the values
differ, a user can match a feature flag rule but not the corresponding recording rule.

## Related Resources

<CardGroup cols={2}>
  <Card title="Recording rules" href="/docs/recordings/recording-rules">
    Control which users and sessions the SDK records.
  </Card>

  <Card title="Evaluation context" href="/docs/sdks/context">
    Learn how Confidence SDKs use context for feature flags.
  </Card>
</CardGroup>
