> For the complete documentation index, see [llms.txt](https://docs.reflag.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reflag.com/supported-languages/browser-sdk/globals.md). Agents can also search and read this documentation through its [MCP server](https://docs.reflag.com/~gitbook/mcp).

# Reference

This page covers SDK v2.

## Classes <a href="#classes" id="classes"></a>

### ReflagClient <a href="#reflagclient" id="reflagclient"></a>

ReflagClient lets you interact with the Reflag API.

#### Constructors <a href="#constructors" id="constructors"></a>

### new ReflagClient() <a href="#new-reflagclient" id="new-reflagclient"></a>

```ts
new ReflagClient(opts: InitOptions): ReflagClient
```

Create a new ReflagClient instance.

**Parameters**

| Parameter | Type                          |
| --------- | ----------------------------- |
| `opts`    | [`InitOptions`](#initoptions) |

**Returns**

[`ReflagClient`](#reflagclient)

#### Properties <a href="#properties" id="properties"></a>

| Property | Modifier   | Type                |
| -------- | ---------- | ------------------- |
| `logger` | `readonly` | [`Logger`](#logger) |

#### Methods <a href="#methods" id="methods"></a>

### applyBootstrappedState() <a href="#applybootstrappedstate" id="applybootstrappedstate"></a>

```ts
applyBootstrappedState(bootstrappedState: BootstrappedState, triggerEvent: boolean): void
```

**Parameters**

| Parameter           | Type                                      | Default value |
| ------------------- | ----------------------------------------- | ------------- |
| `bootstrappedState` | [`BootstrappedState`](#bootstrappedstate) | `undefined`   |
| `triggerEvent`      | `boolean`                                 | `true`        |

**Returns**

`void`

### feedback() <a href="#feedback-1" id="feedback-1"></a>

```ts
feedback(payload: Feedback): Promise<
  | undefined
| Response>
```

Submit user feedback to Reflag. Must include either `score` or `comment`, or both.

**Parameters**

| Parameter | Type                    | Description                     |
| --------- | ----------------------- | ------------------------------- |
| `payload` | [`Feedback`](#feedback) | The feedback details to submit. |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< | `undefined` | [`Response`](https://developer.mozilla.org/docs/Web/API/Response)>

The server response.

### getConfig() <a href="#getconfig" id="getconfig"></a>

```ts
getConfig(): Config
```

Get the current configuration.

**Returns**

[`Config`](#config)

### getContext() <a href="#getcontext" id="getcontext"></a>

```ts
getContext(): ReflagContext
```

Get the current context.

**Returns**

[`ReflagContext`](#reflagcontext)

### getFlag() <a href="#getflag" id="getflag"></a>

**Call Signature**

```ts
getFlag(key: string, defaultValue?: undefined): boolean
```

Boolean-first reads; positional defaults select other top-level JSON categories.

**Parameters**

| Parameter       | Type        |
| --------------- | ----------- |
| `key`           | `string`    |
| `defaultValue`? | `undefined` |

**Returns**

`boolean`

**Call Signature**

```ts
getFlag<Default>(key: string, defaultValue: Default): FlagValueFromDefault<Default>
```

Boolean-first reads; positional defaults select other top-level JSON categories.

**Type Parameters**

| Type Parameter                                                          |
| ----------------------------------------------------------------------- |
| `Default` *extends* `object` \| [`FlagDefaultValue`](#flagdefaultvalue) |

**Parameters**

| Parameter      | Type      |
| -------------- | --------- |
| `key`          | `string`  |
| `defaultValue` | `Default` |

**Returns**

[`FlagValueFromDefault`](#flagvaluefromdefaultt)<`Default`>

### getFlagOverride() <a href="#getflagoverride" id="getflagoverride"></a>

```ts
getFlagOverride(key: string): undefined | FlagValue
```

**Parameters**

| Parameter | Type     |
| --------- | -------- |
| `key`     | `string` |

**Returns**

`undefined` | [`FlagValue`](#flagvalue)

### getFlagResults() <a href="#getflagresults" id="getflagresults"></a>

```ts
getFlagResults(): RawFlags
```

Owned evaluated diagnostics; inspecting these is not an application read.

**Returns**

[`RawFlags`](#rawflags)

### getFlags() <a href="#getflags" id="getflags"></a>

```ts
getFlags(): Record<string, undefined | FlagValue>
```

Return direct values and register checks for these returned roots. Use getFlagResults() for diagnostic/serialization access without checks.

**Returns**

[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `undefined` | [`FlagValue`](#flagvalue)>

### getFlagsForBootstrap() <a href="#getflagsforbootstrap" id="getflagsforbootstrap"></a>

```ts
getFlagsForBootstrap(): BootstrappedState
```

**Returns**

[`BootstrappedState`](#bootstrappedstate)

### getIsLoadingOptInFlags() <a href="#getisloadingoptinflags" id="getisloadingoptinflags"></a>

```ts
getIsLoadingOptInFlags(): boolean
```

Returns whether opt-in flags are loading for the current context.

Calling this method requests opt-in metadata if it is not already available.

**Returns**

`boolean`

### getOptInFlags() <a href="#getoptinflags" id="getoptinflags"></a>

```ts
getOptInFlags(): OptInFlag[]
```

Returns opt-in-enabled flags for the current context.

**Returns**

[`OptInFlag`](#optinflag)\[]

### getState() <a href="#getstate" id="getstate"></a>

```ts
getState(): State
```

**Returns**

[`State`](#state)

### initialize() <a href="#initialize" id="initialize"></a>

```ts
initialize(): Promise<void>
```

Initialize the Reflag SDK.

Must be called before calling other SDK methods.

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

### off() <a href="#off" id="off"></a>

```ts
off<THookType>(type: THookType, handler: (args0: HookArgs[THookType]) => void): void
```

Remove an event listener

**Type Parameters**

| Type Parameter                                      |
| --------------------------------------------------- |
| `THookType` *extends* keyof [`HookArgs`](#hookargs) |

**Parameters**

| Parameter | Type                                                       | Description                                |
| --------- | ---------------------------------------------------------- | ------------------------------------------ |
| `type`    | `THookType`                                                | Type of event to remove.                   |
| `handler` | (`args0`: [`HookArgs`](#hookargs)\[`THookType`]) => `void` | The same function that was passed to `on`. |

**Returns**

`void`

A function to remove the hook.

### on() <a href="#on" id="on"></a>

```ts
on<THookType>(type: THookType, handler: (args0: HookArgs[THookType]) => void): () => void
```

Add an event listener

**Type Parameters**

| Type Parameter                                      |
| --------------------------------------------------- |
| `THookType` *extends* keyof [`HookArgs`](#hookargs) |

**Parameters**

| Parameter | Type                                                       | Description                                       |
| --------- | ---------------------------------------------------------- | ------------------------------------------------- |
| `type`    | `THookType`                                                | Type of events to listen for                      |
| `handler` | (`args0`: [`HookArgs`](#hookargs)\[`THookType`]) => `void` | The function to call when the event is triggered. |

**Returns**

`Function`

A function to remove the hook.

**Returns**

`void`

### refresh() <a href="#refresh" id="refresh"></a>

```ts
refresh(): Promise<undefined | RawFlags>
```

Force refresh flags from the API, bypassing cache.

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`undefined` | [`RawFlags`](#rawflags)>

### requestFeedback() <a href="#requestfeedback" id="requestfeedback"></a>

```ts
requestFeedback(options: RequestFeedbackData): void
```

Display the Reflag feedback form UI programmatically.

This can be used to collect feedback from users in Reflag in cases where Automated Feedback Surveys isn't appropriate.

**Parameters**

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `options` | [`RequestFeedbackData`](#requestfeedbackdata) |

**Returns**

`void`

### setContext() <a href="#setcontext" id="setcontext"></a>

```ts
setContext(context: ReflagDeprecatedContext): Promise<void>
```

Update the context. Replaces the existing context with a new context.

**Parameters**

| Parameter | Type                                                  | Description            |
| --------- | ----------------------------------------------------- | ---------------------- |
| `context` | [`ReflagDeprecatedContext`](#reflagdeprecatedcontext) | The context to update. |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

### setFlagOverride() <a href="#setflagoverride" id="setflagoverride"></a>

```ts
setFlagOverride(key: string, value: undefined | FlagValue): void
```

Overrides are applied after server evaluation and never invent selections.

**Parameters**

| Parameter | Type                                     |
| --------- | ---------------------------------------- |
| `key`     | `string`                                 |
| `value`   | `undefined` \| [`FlagValue`](#flagvalue) |

**Returns**

`void`

### setOptIn() <a href="#setoptin" id="setoptin"></a>

```ts
setOptIn(flagKey: string, options: SetOptInOptions): Promise<
  | undefined
| Response>
```

Set whether the current user or company has opted into a flag.

A successful Response is returned after the refreshed flag state confirms the membership change. HTTP failures return a readable non-OK Response without refreshing flags. Offline mode, invalid arguments, or missing scoped context return undefined. Network and confirmation failures reject; a confirmation failure may occur after membership changed remotely.

**Parameters**

| Parameter | Type                                  |
| --------- | ------------------------------------- |
| `flagKey` | `string`                              |
| `options` | [`SetOptInOptions`](#setoptinoptions) |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< | `undefined` | [`Response`](https://developer.mozilla.org/docs/Web/API/Response)>

### showToolbarToggle() <a href="#showtoolbartoggle" id="showtoolbartoggle"></a>

```ts
showToolbarToggle(position?: ToolbarPosition): void
```

**Parameters**

| Parameter   | Type                                  |
| ----------- | ------------------------------------- |
| `position`? | [`ToolbarPosition`](#toolbarposition) |

**Returns**

`void`

### stop() <a href="#stop" id="stop"></a>

```ts
stop(): Promise<void>
```

Stop the SDK. This will stop any automated feedback surveys.

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

### track() <a href="#track" id="track"></a>

```ts
track(eventName: string, attributes?:
  | null
  | Record<string, any>): Promise<
  | undefined
| Response>
```

Track an event in Reflag.

**Parameters**

| Parameter     | Type                                                                                                                      | Description                                     |
| ------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| `eventName`   | `string`                                                                                                                  | The name of the event.                          |
| `attributes`? | \| `null` \| [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `any`> | Any attributes you want to attach to the event. |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< | `undefined` | [`Response`](https://developer.mozilla.org/docs/Web/API/Response)>

### updateCompany() <a href="#updatecompany" id="updatecompany"></a>

```ts
updateCompany(company: {}): Promise<void>
```

Update the company context. Performs a shallow merge with the existing company context. It will not update the context if nothing has changed.

**Parameters**

| Parameter | Type | Description          |
| --------- | ---- | -------------------- |
| `company` | {}   | The company details. |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

### updateFlags() <a href="#updateflags" id="updateflags"></a>

```ts
updateFlags(
   flags: RawFlags,
   triggerEvent: boolean,
   flagStateVersion?: number): void
```

Update the flags.

**Parameters**

| Parameter           | Type                    | Default value | Description                                  |
| ------------------- | ----------------------- | ------------- | -------------------------------------------- |
| `flags`             | [`RawFlags`](#rawflags) | `undefined`   | The flags to update.                         |
| `triggerEvent`      | `boolean`               | `true`        | Whether to trigger the `flagsUpdated` event. |
| `flagStateVersion`? | `number`                | `undefined`   | ‐                                            |

**Returns**

`void`

### updateOtherContext() <a href="#updateothercontext" id="updateothercontext"></a>

```ts
updateOtherContext(otherContext: {}): Promise<void>
```

Update the company context. Performs a shallow merge with the existing company context. It will not update the context if nothing has changed.

**Parameters**

| Parameter      | Type | Description         |
| -------------- | ---- | ------------------- |
| `otherContext` | {}   | Additional context. |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

### updateUser() <a href="#updateuser" id="updateuser"></a>

```ts
updateUser(user: {}): Promise<void>
```

Update the user context. Performs a shallow merge with the existing user context. It will not update the context if nothing has changed.

**Parameters**

| Parameter | Type |
| --------- | ---- |
| `user`    | {}   |

**Returns**

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>

## Interfaces <a href="#interfaces" id="interfaces"></a>

### CheckEvent <a href="#checkevent" id="checkevent"></a>

A root read records selection identity, never its JSON payload.

#### Properties <a href="#properties-1" id="properties-1"></a>

| Property             | Type                                     |
| -------------------- | ---------------------------------------- |
| `action`             | `"check"`                                |
| `evalContext?`       | [`ReflagContext`](#reflagcontext)        |
| `evalErrors?`        | [`EvaluationError`](#evaluationerror)\[] |
| `evalMissingFields?` | `string`\[]                              |
| `evalResult?`        | `string`                                 |
| `evalRuleResults?`   | `boolean`\[]                             |
| `flagStateVersion?`  | `number`                                 |
| `key`                | `string`                                 |
| `sourceVersionId?`   | `string`                                 |

***

### CompanyContext <a href="#companycontext" id="companycontext"></a>

Context is a set of key-value pairs. This is used to determine if feature targeting matches and to track events. Id should always be present so that it can be referenced to an existing company.

#### Indexable <a href="#indexable" id="indexable"></a>

```ts
[key: string]: ContextValue
```

#### Properties <a href="#properties-2" id="properties-2"></a>

| Property | Type                                | Description  |
| -------- | ----------------------------------- | ------------ |
| `id`     | `undefined` \| `string` \| `number` | Company id   |
| `name?`  | `string`                            | Company name |

***

### Config <a href="#config" id="config"></a>

ReflagClient configuration.

#### Properties <a href="#properties-3" id="properties-3"></a>

| Property         | Type      | Description                                                         |
| ---------------- | --------- | ------------------------------------------------------------------- |
| `apiBaseUrl`     | `string`  | Base URL of Reflag servers.                                         |
| `appBaseUrl`     | `string`  | Base URL of the Reflag web app.                                     |
| `bootstrapped`   | `boolean` | Whether the client is bootstrapped.                                 |
| `enableTracking` | `boolean` | Whether to enable tracking.                                         |
| `offline`        | `boolean` | Whether to enable offline mode.                                     |
| `sseBaseUrl`     | `string`  | Base URL used for pubsub SSE connections. Defaults to `apiBaseUrl`. |

***

### FeedbackScoreSubmission <a href="#feedbackscoresubmission" id="feedbackscoresubmission"></a>

#### Properties <a href="#properties-4" id="properties-4"></a>

| Property      | Type     |
| ------------- | -------- |
| `feedbackId?` | `string` |
| `question`    | `string` |
| `score`       | `number` |

***

### FeedbackSubmission <a href="#feedbacksubmission" id="feedbacksubmission"></a>

#### Properties <a href="#properties-5" id="properties-5"></a>

| Property      | Type     |
| ------------- | -------- |
| `comment`     | `string` |
| `feedbackId?` | `string` |
| `question`    | `string` |
| `score`       | `number` |

***

### HookArgs <a href="#hookargs" id="hookargs"></a>

#### Properties <a href="#properties-6" id="properties-6"></a>

| Property                   | Type                                | Description                                                                     |
| -------------------------- | ----------------------------------- | ------------------------------------------------------------------------------- |
| `check`                    | [`CheckEvent`](#checkevent)         | ‐                                                                               |
| `company`                  | [`CompanyContext`](#companycontext) | ‐                                                                               |
| ~~`featuresUpdated`~~      | [`RawFlags`](#rawflags)             | <p><strong>Deprecated</strong></p><p>Use <code>flagsUpdated</code> instead.</p> |
| `flagsUpdated`             | [`RawFlags`](#rawflags)             | ‐                                                                               |
| `optInFlagsLoadingUpdated` | `boolean`                           | ‐                                                                               |
| `stateUpdated`             | [`State`](#state)                   | ‐                                                                               |
| `track`                    | [`TrackEvent`](#trackevent)         | ‐                                                                               |
| `user`                     | [`UserContext`](#usercontext)       | ‐                                                                               |

***

### Logger <a href="#logger" id="logger"></a>

#### Methods <a href="#methods-1" id="methods-1"></a>

### debug() <a href="#debug" id="debug"></a>

```ts
debug(message: string, ...args: any[]): void
```

**Parameters**

| Parameter | Type     |
| --------- | -------- |
| `message` | `string` |
| ...`args` | `any`\[] |

**Returns**

`void`

### error() <a href="#error" id="error"></a>

```ts
error(message: string, ...args: any[]): void
```

**Parameters**

| Parameter | Type     |
| --------- | -------- |
| `message` | `string` |
| ...`args` | `any`\[] |

**Returns**

`void`

### info() <a href="#info" id="info"></a>

```ts
info(message: string, ...args: any[]): void
```

**Parameters**

| Parameter | Type     |
| --------- | -------- |
| `message` | `string` |
| ...`args` | `any`\[] |

**Returns**

`void`

### warn() <a href="#warn" id="warn"></a>

```ts
warn(message: string, ...args: any[]): void
```

**Parameters**

| Parameter | Type     |
| --------- | -------- |
| `message` | `string` |
| ...`args` | `any`\[] |

**Returns**

`void`

***

### OnScoreSubmitResult <a href="#onscoresubmitresult" id="onscoresubmitresult"></a>

#### Properties <a href="#properties-7" id="properties-7"></a>

| Property     | Type     |
| ------------ | -------- |
| `feedbackId` | `string` |

***

### OpenFeedbackFormOptions <a href="#openfeedbackformoptions" id="openfeedbackformoptions"></a>

#### Properties <a href="#properties-8" id="properties-8"></a>

| Property                  | Type                                                                                                                                                                                                              | Description                                                                                                       |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `key`                     | `string`                                                                                                                                                                                                          | ‐                                                                                                                 |
| `onClose?`                | () => `void`                                                                                                                                                                                                      | ‐                                                                                                                 |
| `onDismiss?`              | () => `void`                                                                                                                                                                                                      | ‐                                                                                                                 |
| `onScoreSubmit?`          | (`data`: [`FeedbackScoreSubmission`](#feedbackscoresubmission)) => [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`OnScoreSubmitResult`](#onscoresubmitresult)> | ‐                                                                                                                 |
| `onSubmit`                | (`data`: [`FeedbackSubmission`](#feedbacksubmission)) => \| `void` \| [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>                                     | ‐                                                                                                                 |
| `openWithCommentVisible?` | `boolean`                                                                                                                                                                                                         | Open the form with both the score and comment fields visible. Defaults to `false`                                 |
| `position?`               | [`Position`](#position)                                                                                                                                                                                           | Control the placement and behavior of the feedback form.                                                          |
| `title?`                  | `string`                                                                                                                                                                                                          | ‐                                                                                                                 |
| `translations?`           | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`FeedbackTranslations`](#feedbacktranslations)>                                                                         | Add your own custom translations for the feedback form. Undefined translation keys fall back to english defaults. |

***

### ReflagContext <a href="#reflagcontext" id="reflagcontext"></a>

Context is a set of key-value pairs. This is used to determine if feature targeting matches and to track events.

#### Extended by <a href="#extended-by" id="extended-by"></a>

* [`ReflagDeprecatedContext`](#reflagdeprecatedcontext)

#### Properties <a href="#properties-9" id="properties-9"></a>

| Property   | Type                                                                                                                                   | Description                                                                                                                       |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `company?` | [`CompanyContext`](#companycontext)                                                                                                    | Company related context. If you provide `id` Reflag will enrich the evaluation context with company attributes on Reflag servers. |
| `other?`   | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, [`ContextValue`](#contextvalue)> | Context which is not related to a user or a company.                                                                              |
| `user?`    | [`UserContext`](#usercontext)                                                                                                          | User related context. If you provide `id` Reflag will enrich the evaluation context with user attributes on Reflag servers.       |

***

### ~~ReflagDeprecatedContext~~ <a href="#reflagdeprecatedcontext" id="reflagdeprecatedcontext"></a>

**`Internal`**

#### Deprecated <a href="#deprecated" id="deprecated"></a>

Use `ReflagContext` instead, this interface will be removed in the next major version

#### Extends <a href="#extends" id="extends"></a>

* [`ReflagContext`](#reflagcontext)

#### Properties <a href="#properties-10" id="properties-10"></a>

| Property            | Type                                                                                                                                   | Description                                                                                                                                                                                 |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ~~`company?`~~      | [`CompanyContext`](#companycontext)                                                                                                    | Company related context. If you provide `id` Reflag will enrich the evaluation context with company attributes on Reflag servers.                                                           |
| ~~`other?`~~        | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, [`ContextValue`](#contextvalue)> | Context which is not related to a user or a company.                                                                                                                                        |
| ~~`otherContext?`~~ | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, [`ContextValue`](#contextvalue)> | <p>Context which is not related to a user or a company.</p><p><strong>Deprecated</strong></p><p>Use <code>other</code> instead, this property will be removed in the next major version</p> |
| ~~`user?`~~         | [`UserContext`](#usercontext)                                                                                                          | User related context. If you provide `id` Reflag will enrich the evaluation context with user attributes on Reflag servers.                                                                 |

***

### ToolbarPosition <a href="#toolbarposition" id="toolbarposition"></a>

#### Properties <a href="#properties-11" id="properties-11"></a>

| Property    | Type                                  |
| ----------- | ------------------------------------- |
| `offset?`   | [`Offset`](#offset)                   |
| `placement` | [`DialogPlacement`](#dialogplacement) |

***

### UserContext <a href="#usercontext" id="usercontext"></a>

Context is a set of key-value pairs. This is used to determine if feature targeting matches and to track events. Id should always be present so that it can be referenced to an existing user.

#### Indexable <a href="#indexable-1" id="indexable-1"></a>

```ts
[key: string]: ContextValue
```

#### Properties <a href="#properties-12" id="properties-12"></a>

| Property | Type                                | Description |
| -------- | ----------------------------------- | ----------- |
| `email?` | `string`                            | User email  |
| `id`     | `undefined` \| `string` \| `number` | User id     |
| `name?`  | `string`                            | User name   |

## Type Aliases <a href="#type-aliases" id="type-aliases"></a>

### BootstrappedState <a href="#bootstrappedstate" id="bootstrappedstate"></a>

```ts
type BootstrappedState = {
  context: ReflagContext;
  flags: RawFlags;
  flagStateVersion: number;
  protocolVersion: 2;
};
```

Pre-fetched evaluated state used to bootstrap the client.

#### Type declaration <a href="#type-declaration" id="type-declaration"></a>

| Name                | Type                              |
| ------------------- | --------------------------------- |
| `context`           | [`ReflagContext`](#reflagcontext) |
| `flags`             | [`RawFlags`](#rawflags)           |
| `flagStateVersion`? | `number`                          |
| `protocolVersion`   | `2`                               |

***

### ContextValue <a href="#contextvalue" id="contextvalue"></a>

```ts
type ContextValue = DefinedContextValue | undefined;
```

A context value. Object properties set to `undefined` are omitted.

***

### DefinedContextValue <a href="#definedcontextvalue" id="definedcontextvalue"></a>

```ts
type DefinedContextValue =
  | string
  | number
  | boolean
  | null
  | DefinedContextValue[]
| {};
```

A JSON-compatible context value that is not `undefined`.

***

### DialogPlacement <a href="#dialogplacement" id="dialogplacement"></a>

```ts
type DialogPlacement = "bottom-right" | "bottom-left" | "top-right" | "top-left";
```

***

### EvaluationError <a href="#evaluationerror" id="evaluationerror"></a>

```ts
type EvaluationError = {
  code: string;
  field: string;
  message: string;
  operator: string;
  source: {
     key: string;
     type: "flag" | "segment";
    };
};
```

#### Type declaration <a href="#type-declaration-1" id="type-declaration-1"></a>

| Name          | Type                                                  |
| ------------- | ----------------------------------------------------- |
| `code`        | `string`                                              |
| `field`?      | `string`                                              |
| `message`     | `string`                                              |
| `operator`?   | `string`                                              |
| `source`?     | { `key`: `string`; `type`: `"flag"` \| `"segment"`; } |
| `source.key`  | `string`                                              |
| `source.type` | `"flag"` \| `"segment"`                               |

***

### EventSourceFactory() <a href="#eventsourcefactory" id="eventsourcefactory"></a>

```ts
type EventSourceFactory = (url: string) => EventSourceLike;
```

#### Parameters <a href="#parameters-22" id="parameters-22"></a>

| Parameter | Type     |
| --------- | -------- |
| `url`     | `string` |

#### Returns <a href="#returns-34" id="returns-34"></a>

[`EventSourceLike`](#eventsourcelike)

***

### EventSourceLike <a href="#eventsourcelike" id="eventsourcelike"></a>

```ts
type EventSourceLike = {
  addEventListener: (type: string, cb: (event: any) => void) => void;
  close: () => void;
};
```

#### Type declaration <a href="#type-declaration-2" id="type-declaration-2"></a>

| Name               | Type                                                           |
| ------------------ | -------------------------------------------------------------- |
| `addEventListener` | (`type`: `string`, `cb`: (`event`: `any`) => `void`) => `void` |
| `close`            | () => `void`                                                   |

***

### Feedback <a href="#feedback" id="feedback"></a>

```ts
type Feedback = UnassignedFeedback & {
  companyId: string;
  userId: string;
};
```

#### Type declaration <a href="#type-declaration-3" id="type-declaration-3"></a>

| Name         | Type     | Description                           |
| ------------ | -------- | ------------------------------------- |
| `companyId`? | `string` | Company ID from your own application. |
| `userId`?    | `string` | User ID from your own application.    |

***

### FeedbackOptions <a href="#feedbackoptions" id="feedbackoptions"></a>

```ts
type FeedbackOptions = {
  autoFeedbackHandler: FeedbackPromptHandler;
  enableAutoFeedback: boolean;
  ui: {
     position: Position;
     translations: Partial<FeedbackTranslations>;
    };
};
```

#### Type declaration <a href="#type-declaration-4" id="type-declaration-4"></a>

| Name                   | Type                                                                                                                                                                                                | Description                                                                                                       |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `autoFeedbackHandler`? | [`FeedbackPromptHandler`](#feedbackprompthandler)                                                                                                                                                   | ‐                                                                                                                 |
| `enableAutoFeedback`?  | `boolean`                                                                                                                                                                                           | Enables automatic feedback prompting if it's set up in Reflag                                                     |
| `ui`?                  | { `position`: [`Position`](#position); `translations`: [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`FeedbackTranslations`](#feedbacktranslations)>; } | With these options you can override the look of the feedback prompt                                               |
| `ui.position`?         | [`Position`](#position)                                                                                                                                                                             | Control the placement and behavior of the feedback form.                                                          |
| `ui.translations`?     | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`FeedbackTranslations`](#feedbacktranslations)>                                                           | Add your own custom translations for the feedback form. Undefined translation keys fall back to english defaults. |

***

### FeedbackPrompt <a href="#feedbackprompt" id="feedbackprompt"></a>

```ts
type FeedbackPrompt = {
  featureId: string;
  promptId: string;
  question: string;
  showAfter: Date;
  showBefore: Date;
};
```

#### Type declaration <a href="#type-declaration-5" id="type-declaration-5"></a>

| Name         | Type                                                                                      | Description                                        |
| ------------ | ----------------------------------------------------------------------------------------- | -------------------------------------------------- |
| `featureId`  | `string`                                                                                  | Feature ID from Reflag                             |
| `promptId`   | `string`                                                                                  | Id of the prompt                                   |
| `question`   | `string`                                                                                  | Specific question user was asked                   |
| `showAfter`  | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | Feedback prompt should appear only after this time |
| `showBefore` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | Feedback prompt will not be shown after this time  |

***

### FeedbackPromptHandler() <a href="#feedbackprompthandler" id="feedbackprompthandler"></a>

```ts
type FeedbackPromptHandler = (prompt: FeedbackPrompt, handlers: FeedbackPromptHandlerCallbacks) => void;
```

#### Parameters <a href="#parameters-23" id="parameters-23"></a>

| Parameter  | Type                                                                |
| ---------- | ------------------------------------------------------------------- |
| `prompt`   | [`FeedbackPrompt`](#feedbackprompt)                                 |
| `handlers` | [`FeedbackPromptHandlerCallbacks`](#feedbackprompthandlercallbacks) |

#### Returns <a href="#returns-35" id="returns-35"></a>

`void`

***

### FeedbackPromptHandlerCallbacks <a href="#feedbackprompthandlercallbacks" id="feedbackprompthandlercallbacks"></a>

```ts
type FeedbackPromptHandlerCallbacks = {
  openFeedbackForm: (options: FeedbackPromptHandlerOpenFeedbackFormOptions) => void;
  reply: FeedbackPromptReplyHandler;
};
```

#### Type declaration <a href="#type-declaration-6" id="type-declaration-6"></a>

| Name               | Type                                                                                                                   |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `openFeedbackForm` | (`options`: [`FeedbackPromptHandlerOpenFeedbackFormOptions`](#feedbackprompthandleropenfeedbackformoptions)) => `void` |
| `reply`            | [`FeedbackPromptReplyHandler`](#feedbackpromptreplyhandler)                                                            |

***

### FeedbackPromptHandlerOpenFeedbackFormOptions <a href="#feedbackprompthandleropenfeedbackformoptions" id="feedbackprompthandleropenfeedbackformoptions"></a>

```ts
type FeedbackPromptHandlerOpenFeedbackFormOptions = Omit<RequestFeedbackOptions,
  | "featureId"
  | "flagKey"
  | "userId"
  | "companyId"
  | "onClose"
| "onDismiss">;
```

***

### FeedbackPromptReply <a href="#feedbackpromptreply" id="feedbackpromptreply"></a>

```ts
type FeedbackPromptReply = {
  comment: string;
  companyId: string;
  question: string;
  score: number;
};
```

#### Type declaration <a href="#type-declaration-7" id="type-declaration-7"></a>

| Name         | Type     |
| ------------ | -------- |
| `comment`?   | `string` |
| `companyId`? | `string` |
| `question`   | `string` |
| `score`?     | `number` |

***

### FeedbackPromptReplyHandler() <a href="#feedbackpromptreplyhandler" id="feedbackpromptreplyhandler"></a>

```ts
type FeedbackPromptReplyHandler = <T>(reply: T) => T extends null ? Promise<void> : Promise<{
  feedbackId: string;
}>;
```

#### Type Parameters <a href="#type-parameters-3" id="type-parameters-3"></a>

| Type Parameter                                                        |
| --------------------------------------------------------------------- |
| `T` *extends* [`FeedbackPromptReply`](#feedbackpromptreply) \| `null` |

#### Parameters <a href="#parameters-24" id="parameters-24"></a>

| Parameter | Type |
| --------- | ---- |
| `reply`   | `T`  |

#### Returns <a href="#returns-36" id="returns-36"></a>

`T` *extends* `null` ? [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> : [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `feedbackId`: `string`; }>

***

### FeedbackTranslations <a href="#feedbacktranslations" id="feedbacktranslations"></a>

```ts
type FeedbackTranslations = {
  DefaultQuestionLabel: string;
  QuestionPlaceholder: string;
  ScoreDissatisfiedLabel: string;
  ScoreNeutralLabel: string;
  ScoreSatisfiedLabel: string;
  ScoreStatusDescription: string;
  ScoreStatusLoading: string;
  ScoreStatusReceived: string;
  ScoreVeryDissatisfiedLabel: string;
  ScoreVerySatisfiedLabel: string;
  SendButton: string;
  SuccessMessage: string;
};
```

You can use this to override text values in the feedback form with desired language translation

#### Type declaration <a href="#type-declaration-8" id="type-declaration-8"></a>

| Name                         | Type     |
| ---------------------------- | -------- |
| `DefaultQuestionLabel`       | `string` |
| `QuestionPlaceholder`        | `string` |
| `ScoreDissatisfiedLabel`     | `string` |
| `ScoreNeutralLabel`          | `string` |
| `ScoreSatisfiedLabel`        | `string` |
| `ScoreStatusDescription`     | `string` |
| `ScoreStatusLoading`         | `string` |
| `ScoreStatusReceived`        | `string` |
| `ScoreVeryDissatisfiedLabel` | `string` |
| `ScoreVerySatisfiedLabel`    | `string` |
| `SendButton`                 | `string` |
| `SuccessMessage`             | `string` |

***

### FlagDefaultFor\<Registry, Key> <a href="#flagdefaultforregistry-key" id="flagdefaultforregistry-key"></a>

```ts
type FlagDefaultFor<Registry, Key> = keyof Registry extends never ? FlagDefaultValue | object : Key extends keyof Registry ? ReadonlyFlagValue<Registry[Key]> | null : never;
```

Registered defaults match the value schema; null explicitly requests arbitrary JSON.

#### Type Parameters <a href="#type-parameters-4" id="type-parameters-4"></a>

| Type Parameter                |
| ----------------------------- |
| `Registry`                    |
| `Key` *extends* `PropertyKey` |

***

### FlagDefaultValue <a href="#flagdefaultvalue" id="flagdefaultvalue"></a>

```ts
type FlagDefaultValue =
  | null
  | boolean
  | number
  | string
  | readonly FlagDefaultValue[]
| {};
```

***

### FlagOverrides <a href="#flagoverrides" id="flagoverrides"></a>

```ts
type FlagOverrides = Record<string, FlagValue | undefined>;
```

***

### FlagValue <a href="#flagvalue" id="flagvalue"></a>

```ts
type FlagValue =
  | null
  | boolean
  | number
  | string
  | FlagValue[]
| {};
```

***

### FlagValueFromDefault\<T> <a href="#flagvaluefromdefaultt" id="flagvaluefromdefaultt"></a>

```ts
type FlagValueFromDefault<T> = T extends null ? FlagValue : T extends boolean ? boolean : T extends number ? number : T extends string ? string : T extends readonly infer Element[] ? [Element] extends [never] ? FlagValue[] : FlagValueFromDefault<Element>[] : T extends object ? { -readonly [Key in keyof T]: FlagValueFromDefault<T[Key]> } : never;
```

Widen literals and return mutable copies. Null requests arbitrary JSON.

#### Type Parameters <a href="#type-parameters-5" id="type-parameters-5"></a>

| Type Parameter |
| -------------- |
| `T`            |

***

### FlagValues <a href="#flagvalues" id="flagvalues"></a>

```ts
type FlagValues = Record<string, FlagValue | undefined>;
```

***

### InitOptions <a href="#initoptions" id="initoptions"></a>

```ts
type InitOptions = ReflagDeprecatedContext & {
  apiBaseUrl: string;
  appBaseUrl: string;
  bootstrappedState: BootstrappedState;
  credentials: "include" | "same-origin" | "omit";
  enableLiveFlagUpdates: boolean;
  enableTracking: boolean;
  eventSourceFactory: EventSourceFactory;
  expireTimeMs: number;
  feedback: FeedbackOptions;
  logger: Logger;
  offline: boolean;
  publishableKey: string;
  sdkVersion: string;
  sseBaseUrl: string;
  staleTimeMs: number;
  staleWhileRevalidate: boolean;
  storage: StorageAdapter;
  timeoutMs: number;
  toolbar: ToolbarOptions;
  trackingQueue: {
     flushDelayMs: number;
     maxSize: number;
     retryBaseDelayMs: number;
     retryMaxDelayMs: number;
    };
};
```

ReflagClient initialization options.

#### Type declaration <a href="#type-declaration-9" id="type-declaration-9"></a>

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>apiBaseUrl</code>?</td><td><code>string</code></td><td>Base URL of Reflag servers. You can override this to use your mocked server.</td></tr><tr><td><code>appBaseUrl</code>?</td><td><code>string</code></td><td>Base URL of the Reflag web app. Links open ín this app by default.</td></tr><tr><td><code>bootstrappedState</code>?</td><td><a href="#bootstrappedstate"><code>BootstrappedState</code></a></td><td>Pre-fetched evaluated state used for the initial flag state. The client fetches opt-in metadata on demand when opt-in flags are requested.</td></tr><tr><td><code>credentials</code>?</td><td><code>"include"</code> | <code>"same-origin"</code> | <code>"omit"</code></td><td>When proxying requests, you may want to include credentials like cookies so you can authorize the request in the proxy. This option controls the <code>credentials</code> option of the fetch API.</td></tr><tr><td><code>enableLiveFlagUpdates</code>?</td><td><code>boolean</code></td><td><p>Whether to enable live flag updates.</p><p>When enabled, the SDK opens a Server-Sent Events (SSE) connection and refreshes flag definitions automatically whenever they change on the server, without relying on context changes or manual refreshes.</p><p>Defaults to <code>false</code> in the browser SDK.</p></td></tr><tr><td><code>enableTracking</code>?</td><td><code>boolean</code></td><td>Whether to enable tracking. Defaults to <code>true</code>.</td></tr><tr><td><code>eventSourceFactory</code>?</td><td><a href="#eventsourcefactory"><code>EventSourceFactory</code></a></td><td><p>Optional factory used to create SSE connections.</p><p>By default the SDK uses the global <code>EventSource</code> implementation available in browsers. This option is intended for alternative runtimes where you need to provide an EventSource-compatible transport manually. The React Native wrapper already injects a transport automatically.</p></td></tr><tr><td><code>expireTimeMs</code>?</td><td><code>number</code></td><td>If set, flags will be cached between page loads for this duration</td></tr><tr><td><code>feedback</code>?</td><td><a href="#feedbackoptions"><code>FeedbackOptions</code></a></td><td>AutoFeedback specific configuration</td></tr><tr><td><code>logger</code>?</td><td><a href="#logger"><code>Logger</code></a></td><td><p>You can provide a logger to see the logs of the network calls. This is undefined by default. For debugging purposes you can just set the browser console to this property:</p><pre class="language-javascript"><code class="lang-javascript">options.logger = window.console;
</code></pre></td></tr><tr><td><code>offline</code>?</td><td><code>boolean</code></td><td>Whether to enable offline mode. Defaults to <code>false</code>.</td></tr><tr><td><code>publishableKey</code></td><td><code>string</code></td><td>Publishable key for authentication</td></tr><tr><td><code>sdkVersion</code>?</td><td><code>string</code></td><td>Version of the SDK</td></tr><tr><td><code>sseBaseUrl</code>?</td><td><code>string</code></td><td><p><strong>Deprecated</strong></p><p>SSE now uses the same origin as <code>apiBaseUrl</code> by default. Override only if you need a separate pubsub host temporarily.</p></td></tr><tr><td><code>staleTimeMs</code>?</td><td><code>number</code></td><td>Stale flags will be returned if staleWhileRevalidate is true if no new flags can be fetched</td></tr><tr><td><code>staleWhileRevalidate</code>?</td><td><code>boolean</code></td><td>If set to true stale flags will be returned while refetching flags</td></tr><tr><td><code>storage</code>?</td><td><a href="#storageadapter"><code>StorageAdapter</code></a></td><td>Optional storage adapter used for caching flags and overrides. Useful for React Native (AsyncStorage).</td></tr><tr><td><code>timeoutMs</code>?</td><td><code>number</code></td><td>Timeout in milliseconds when fetching flags</td></tr><tr><td><code>toolbar</code>?</td><td><a href="#toolbaroptions"><code>ToolbarOptions</code></a></td><td>Toolbar configuration</td></tr><tr><td><code>trackingQueue</code>?</td><td>{ <code>flushDelayMs</code>: <code>number</code>; <code>maxSize</code>: <code>number</code>; <code>retryBaseDelayMs</code>: <code>number</code>; <code>retryMaxDelayMs</code>: <code>number</code>; }</td><td>Queue settings for tracking updates sent to <code>/bulk</code>. Applies to user/company updates, check events, and prompt events. Events are buffered in memory and flushed in the background.</td></tr><tr><td><code>trackingQueue.flushDelayMs</code>?</td><td><code>number</code></td><td>Delay in milliseconds before flushing queued events. Lower values send sooner; slightly higher values batch better. Defaults to 200ms.</td></tr><tr><td><code>trackingQueue.maxSize</code>?</td><td><code>number</code></td><td>Maximum number of queued events retained locally. Oldest events are dropped when the cap is exceeded. Defaults to 100.</td></tr><tr><td><code>trackingQueue.retryBaseDelayMs</code>?</td><td><code>number</code></td><td>Deprecated: retries are no longer performed for bulk delivery.</td></tr><tr><td><code>trackingQueue.retryMaxDelayMs</code>?</td><td><code>number</code></td><td>Deprecated: retries are no longer performed for bulk delivery.</td></tr></tbody></table>

***

### Offset <a href="#offset" id="offset"></a>

```ts
type Offset = {
  x: string | number;
  y: string | number;
};
```

#### Type declaration <a href="#type-declaration-10" id="type-declaration-10"></a>

| Name | Type                 | Description                                                                |
| ---- | -------------------- | -------------------------------------------------------------------------- |
| `x`? | `string` \| `number` | Offset from the nearest horizontal screen edge after placement is resolved |
| `y`? | `string` \| `number` | Offset from the nearest vertical screen edge after placement is resolved   |

***

### OptInFlag <a href="#optinflag" id="optinflag"></a>

```ts
type OptInFlag = RawFlagOptIn & {
  key: string;
  value: boolean;
};
```

#### Type declaration <a href="#type-declaration-11" id="type-declaration-11"></a>

| Name    | Type      | Description                                                                      |
| ------- | --------- | -------------------------------------------------------------------------------- |
| `key`   | `string`  | Flag key.                                                                        |
| `value` | `boolean` | Whether the flag is on for the current context. Opt-in flags are always Boolean. |

***

### PopoverPlacement <a href="#popoverplacement" id="popoverplacement"></a>

```ts
type PopoverPlacement = Placement;
```

***

### Position <a href="#position" id="position"></a>

```ts
type Position =
  | {
  type: "MODAL";
 }
  | {
  offset: Offset;
  placement: DialogPlacement;
  type: "DIALOG";
 }
  | {
  anchor: any | null;
  placement: PopoverPlacement;
  type: "POPOVER";
};
```

***

### RawFlag <a href="#rawflag" id="rawflag"></a>

```ts
type RawFlag = {
  allocationIndex: number;
  errors: EvaluationError[];
  matchedRuleId: string;
  optIn: RawFlagOptIn | null;
  optInEnabled: boolean;
  resolved: boolean;
  ruleResults: RuleEvaluationResult[];
  sourceVersionId: string;
  value: FlagValue | undefined;
  variantKey: string;
};
```

Evaluated diagnostics for v2 transport/bootstrap, not a flag wrapper.

#### Type declaration <a href="#type-declaration-12" id="type-declaration-12"></a>

| Name               | Type                                               | Description                                                             |
| ------------------ | -------------------------------------------------- | ----------------------------------------------------------------------- |
| `allocationIndex`? | `number`                                           | ‐                                                                       |
| `errors`           | [`EvaluationError`](#evaluationerror)\[]           | ‐                                                                       |
| `matchedRuleId`?   | `string`                                           | ‐                                                                       |
| `optIn`?           | [`RawFlagOptIn`](#rawflagoptin) \| `null`          | ‐                                                                       |
| `optInEnabled`?    | `boolean`                                          | Absent in Node bootstrap/older snapshots; null optIn means unavailable. |
| `resolved`         | `boolean`                                          | ‐                                                                       |
| `ruleResults`      | [`RuleEvaluationResult`](#ruleevaluationresult)\[] | ‐                                                                       |
| `sourceVersionId`? | `string`                                           | ‐                                                                       |
| `value`            | [`FlagValue`](#flagvalue) \| `undefined`           | ‐                                                                       |
| `variantKey`?      | `string`                                           | ‐                                                                       |

***

### RawFlagOptIn <a href="#rawflagoptin" id="rawflagoptin"></a>

```ts
type RawFlagOptIn = {
  companyOptedIn: boolean;
  description: string | null;
  isOptedIn: boolean;
  name: string;
  userOptedIn: boolean;
};
```

#### Type declaration <a href="#type-declaration-13" id="type-declaration-13"></a>

| Name             | Type               | Description                                                         |
| ---------------- | ------------------ | ------------------------------------------------------------------- |
| `companyOptedIn` | `boolean`          | Whether the current company has opted into the flag.                |
| `description`    | `string` \| `null` | SDK-facing opt-in description.                                      |
| `isOptedIn`      | `boolean`          | Whether either the current user or company has opted into the flag. |
| `name`           | `string`           | Display name of the opt-in flag.                                    |
| `userOptedIn`    | `boolean`          | Whether the current user has opted into the flag.                   |

***

### RawFlags <a href="#rawflags" id="rawflags"></a>

```ts
type RawFlags = Record<string, RawFlag>;
```

***

### RequestFeedbackData <a href="#requestfeedbackdata" id="requestfeedbackdata"></a>

```ts
type RequestFeedbackData = Omit<OpenFeedbackFormOptions, "key" | "onSubmit"> & {
  companyId: string;
  flagKey: string;
  onAfterSubmit: (data: FeedbackSubmission) => void;
};
```

#### Type declaration <a href="#type-declaration-14" id="type-declaration-14"></a>

| Name             | Type                                                            | Description                                                                                                                                                                           |
| ---------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `companyId`?     | `string`                                                        | Company ID from your own application.                                                                                                                                                 |
| `flagKey`        | `string`                                                        | Flag key.                                                                                                                                                                             |
| `onAfterSubmit`? | (`data`: [`FeedbackSubmission`](#feedbacksubmission)) => `void` | <p>Allows you to handle a copy of the already submitted feedback.</p><p>This can be used for side effects, such as storing a copy of the feedback in your own application or CRM.</p> |

***

### RequestFeedbackOptions <a href="#requestfeedbackoptions" id="requestfeedbackoptions"></a>

```ts
type RequestFeedbackOptions = RequestFeedbackData & {
  userId: string;
};
```

#### Type declaration <a href="#type-declaration-15" id="type-declaration-15"></a>

| Name     | Type     | Description                        |
| -------- | -------- | ---------------------------------- |
| `userId` | `string` | User ID from your own application. |

***

### RuleEvaluationResult <a href="#ruleevaluationresult" id="ruleevaluationresult"></a>

```ts
type RuleEvaluationResult = {
  allocationIndex: number;
  destination:   | {
     type: "nextRule";
    }
     | {
     type: "variant";
     variantKey: string;
    };
  matched: boolean;
  ruleId: string;
};
```

#### Type declaration <a href="#type-declaration-16" id="type-declaration-16"></a>

| Name               | Type                                                                             |
| ------------------ | -------------------------------------------------------------------------------- |
| `allocationIndex`? | `number`                                                                         |
| `destination`?     | \| { `type`: `"nextRule"`; } \| { `type`: `"variant"`; `variantKey`: `string`; } |
| `matched`          | `boolean`                                                                        |
| `ruleId`           | `string`                                                                         |

***

### SetOptInOptions <a href="#setoptinoptions" id="setoptinoptions"></a>

```ts
type SetOptInOptions = {
  optedIn: boolean;
  scope?: "user" | "company";
};
```

Options for changing the current user or company's opt-in membership.

#### Type declaration <a href="#type-declaration-17" id="type-declaration-17"></a>

| Name      | Type                    | Description                                                                |
| --------- | ----------------------- | -------------------------------------------------------------------------- |
| `optedIn` | `boolean`               | Whether the scoped subject has opted in.                                   |
| `scope`?  | `"user"` \| `"company"` | Whether to update the current user or current company. Defaults to `user`. |

***

### State <a href="#state" id="state"></a>

```ts
type State = "idle" | "initializing" | "initialized" | "stopped";
```

State of the client.

***

### StorageAdapter <a href="#storageadapter" id="storageadapter"></a>

```ts
type StorageAdapter = {
  getItem: Promise<null | string>;
  removeItem: Promise<void>;
  setItem: Promise<void>;
};
```

#### Type declaration <a href="#type-declaration-18" id="type-declaration-18"></a>

| Name            | Type                                                                                                                |
| --------------- | ------------------------------------------------------------------------------------------------------------------- |
| `getItem()`     | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`null` \| `string`> |
| `removeItem()`? | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>             |
| `setItem()`     | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>             |

***

### ToolbarOptions <a href="#toolbaroptions" id="toolbaroptions"></a>

```ts
type ToolbarOptions =
  | boolean
  | {
  position: ToolbarPosition;
  show: boolean;
};
```

Toolbar options.

***

### TrackEvent <a href="#trackevent" id="trackevent"></a>

```ts
type TrackEvent = {
  attributes:   | Record<string, any>
     | null;
  company: CompanyContext;
  eventName: string;
  user: UserContext;
};
```

#### Type declaration <a href="#type-declaration-19" id="type-declaration-19"></a>

| Name          | Type                                                                                                                      |
| ------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `attributes`? | \| [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `any`> \| `null` |
| `company`?    | [`CompanyContext`](#companycontext)                                                                                       |
| `eventName`   | `string`                                                                                                                  |
| `user`        | [`UserContext`](#usercontext)                                                                                             |

***

### UnassignedFeedback <a href="#unassignedfeedback" id="unassignedfeedback"></a>

```ts
type UnassignedFeedback = {
  comment: string;
  feedbackId: string;
  flagKey: string;
  promptedQuestion: string;
  promptId: string;
  question: string;
  score: number;
  source: "prompt" | "sdk" | "widget";
};
```

#### Type declaration <a href="#type-declaration-20" id="type-declaration-20"></a>

| Name                | Type                                | Description                                                                                                                                                                                                                                                                                                                              |
| ------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `comment`?          | `string`                            | User supplied comment about your flag.                                                                                                                                                                                                                                                                                                   |
| `feedbackId`?       | `string`                            | Reflag feedback ID                                                                                                                                                                                                                                                                                                                       |
| `flagKey`           | `string`                            | Flag key.                                                                                                                                                                                                                                                                                                                                |
| `promptedQuestion`? | `string`                            | The original question. This only needs to be populated if the feedback was submitted through the automated feedback surveys channel.                                                                                                                                                                                                     |
| `promptId`?         | `string`                            | <p>Reflag feedback prompt ID.</p><p>This only exists if the feedback was submitted as part of an automated prompt from Reflag.</p><p>Used for internal state management of automated feedback.</p>                                                                                                                                       |
| `question`?         | `string`                            | The question that was presented to the user.                                                                                                                                                                                                                                                                                             |
| `score`?            | `number`                            | Customer satisfaction score.                                                                                                                                                                                                                                                                                                             |
| `source`?           | `"prompt"` \| `"sdk"` \| `"widget"` | <p>Source of the feedback, depending on how the user was asked</p><ul><li><code>prompt</code> - Feedback submitted by way of an automated feedback survey (prompted)</li><li><code>widget</code> - Feedback submitted via <code>requestFeedback</code></li><li><code>sdk</code> - Feedback submitted via <code>feedback</code></li></ul> |

## Variables <a href="#variables" id="variables"></a>

### DEFAULT\_TRANSLATIONS <a href="#default_translations" id="default_translations"></a>

```ts
const DEFAULT_TRANSLATIONS: FeedbackTranslations;
```

```tsx
import { FeedbackTranslations } from "../types";
/**
 * {@includeCode ./defaultTranslations.tsx}
 */
export const DEFAULT_TRANSLATIONS: FeedbackTranslations = {
  DefaultQuestionLabel: "How satisfied are you with this feature?",
  QuestionPlaceholder: "Write a comment",
  ScoreStatusDescription: "Pick a score and leave a comment",
  ScoreStatusLoading: "Saving score, please wait...",
  ScoreStatusReceived: "Score has been received!",
  ScoreVeryDissatisfiedLabel: "Very dissatisfied (1/5)",
  ScoreDissatisfiedLabel: "Dissatisfied (2/5)",
  ScoreNeutralLabel: "Neutral (3/5)",
  ScoreSatisfiedLabel: "Satisfied (4/5)",
  ScoreVerySatisfiedLabel: "Very satisfied (5/5)",
  SuccessMessage: "Feedback received, thank you!",
  SendButton: "Send feedback",
};
```

***

### feedbackContainerId <a href="#feedbackcontainerid" id="feedbackcontainerid"></a>

```ts
const feedbackContainerId: "reflag-feedback-dialog-container" = "reflag-feedback-dialog-container";
```

ID of HTML DIV element which contains the feedback dialog

***

### propagatedEvents <a href="#propagatedevents" id="propagatedevents"></a>

```ts
const propagatedEvents: string[];
```

These events will be propagated to the feedback dialog

#### See <a href="#see" id="see"></a>

<https://developer.mozilla.org/en-US/docs/Web/API/Element#events>

Using v1? [Legacy docs](https://docs.reflag.com/legacy-sdks/v1/browser-sdk/globals.md) · [Upgrade guide](https://docs.reflag.com/supported-languages/migrating-from-v1.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.reflag.com/supported-languages/browser-sdk/globals.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
