---
title: "Quickstart"
description: "Welcome to ConfigDirector docs! This is a quickstart guide to get you up and running."
canonical_url: "https://docs.configdirector.com/getting-started/quickstart"
---
# Quickstart

> Welcome to ConfigDirector docs! This is a quickstart guide to get you up and running.

Welcome to **ConfigDirector**, a cloud service to manage remote configuration and feature flags.

In this section we'll walk you through:

1. Creating your first config
2. Installing and configuring an SDK
3. Retrieving the config in your app via the SDK
4. Configuring contexts and targeting rules

<collapsed-topic title="What are feature flags and remote configuration?">

Feature flags and remote configuration values allow you to change the behavior of your application without releasing new code. Your application can utilize one of the many ConfigDirector SDKs to retrieve the configuration values or feature flag states to decide if and how a certain feature should be presented to a given user.

</collapsed-topic>

## 1. Create your first config

1. [Sign in](https://app.configdirector.com/) to the ConfigDirector dashboard. <span className="text-muted">

You'll be prompted to create a free account if you don't have one. Don't worry, it's free to start and does not require a payment method. You can start pay as you go later if you need more than the free allowance.

</span>
2. Click on the `Create` button next to the `Configs` navigation to create a new config.
3. Enter a key (the key is both the name and how you'll reference it in code) for the config, adjust other selections, and save it.

## 2. Install and configure an SDK for your language and framework

<note>

Client and server SDK keys belong to an environment within your project. Use environment variables to
provide them at runtime to match the given environment.

</note>

1. Retrieve your client and server SDK keys by going to `SDK keys` in the dashboard's navigation panel.
2. Select each environment to access its client and server SDK keys.
3. Install and configure an SDK for your application stack:

<warning>

Server SDK keys are secret values. Do not commit them to your source code repository. Provide them at runtime via environment variables instead.

</warning>

<sdk-tabs>
<template v-slot:javascript="">
<code-group>

```bash [npm]
npm install --save @configdirector/client-sdk
```

```bash [yarn]
yarn add @configdirector/client-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/client-sdk
```

```bash [bun]
bun add @configdirector/client-sdk
```

</code-group>

```ts [config-director-setup.ts (Initialize the client)]
import { createClient } from "@configdirector/client-sdk";

export const client = createClient("YOUR-CLIENT-SDK-KEY");
await client.initialize();
```

</template>

<template v-slot:react-web="">
<code-group>

```bash [npm]
npm install --save @configdirector/react-web-sdk
```

```bash [yarn]
yarn add @configdirector/react-web-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/react-web-sdk
```

```bash [bun]
bun add @configdirector/react-web-sdk
```

</code-group>

```tsx [main.tsx]
import { createRoot } from "react-dom/client"
import App from "./App"
import { ConfigDirectorProvider } from "@configdirector/react-web-sdk";

createRoot(document.getElementById("root")!).render(
  <ConfigDirectorProvider sdkKey="YOUR-CLIENT-SDK-KEY">
    <App />
  </ConfigDirectorProvider>
);
```

</template>

<template v-slot:vue="">
<code-group>

```bash [npm]
npm install --save @configdirector/vue-sdk
```

```bash [yarn]
yarn add @configdirector/vue-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/vue-sdk
```

```bash [bun]
bun add @configdirector/vue-sdk
```

</code-group>

```ts [main.ts]
import { createApp } from "vue";
import App from "./App.vue";
import { ConfigDirectorPlugin } from "@configdirector/vue-sdk";

const app = createApp(App);

app.use(ConfigDirectorPlugin, { sdkKey: "YOUR-CLIENT-SDK-KEY" });

app.mount("#app");
```

</template>

<template v-slot:openfeature-web="">
<code-group>

```bash [npm]
npm install --save @openfeature/web-sdk @configdirector/openfeature-web-provider
```

```bash [yarn]
yarn add @openfeature/web-sdk @openfeature/core @configdirector/openfeature-web-provider
```

```bash [pnpm]Javascript
pnpm add @openfeature/web-sdk @openfeature/core @configdirector/openfeature-web-provider
```

```bash [bun]
bun add @openfeature/web-sdk @openfeature/core @configdirector/openfeature-web-provider
```

</code-group>

```ts
import { OpenFeature } from "@openfeature/web-sdk";
import { ConfigDirectorProvider } from "@configdirector/openfeature-web-provider";

const provider = new ConfigDirectorProvider("YOUR-CLIENT-SDK-KEY");
try {
  await OpenFeature.setProviderAndWait(provider, {
    targetingKey: "12345", // In OpenFeature, the `targetingKey` represents the context's identifier
    name: "Example User",
    traits: {
      region: "North America", // Any arbitrary traits which can be referenced in targeting rules
    },
  });
} catch (error) {
  console.warn("Continuing until ConfigDirector sends config:", error);
}
const client = OpenFeature.getClient();
```

The provider connects with the context it has when it is registered. Pass the context you already know to `setProviderAndWait`, or set it with `OpenFeature.setContext` before registering the provider, so the first connection carries it.

</template>

<template v-slot:react-native="">
<code-group>

```bash [npm]
npm install --save @configdirector/react-native-sdk
```

```bash [yarn]
yarn add @configdirector/react-native-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/react-native-sdk
```

```bash [bun]
bun add @configdirector/react-native-sdk
```

</code-group>

Also install `@react-native-async-storage/async-storage`, which works in Expo Go. Without it, the SDK cannot tell one app start from a new install: every start counts as one more [monthly active user](https://docs.configdirector.com/getting-started/pricing-and-billing#billing-metrics), nothing is [kept on the device](https://docs.configdirector.com/sdks/mobile/react-native#values-kept-on-the-device) for the next start, and the SDK logs a warning.

<code-group>

```bash [npm]
npm install --save @react-native-async-storage/async-storage
```

```bash [yarn]
yarn add @react-native-async-storage/async-storage
```

```bash [pnpm]
pnpm add @react-native-async-storage/async-storage
```

```bash [bun]
bun add @react-native-async-storage/async-storage
```

```bash [expo]
npx expo install @react-native-async-storage/async-storage
```

</code-group>

```tsx [main.tsx]
import { View } from "react-native";
import AwesomeApp from "./AwesomeApp";
import { ConfigDirectorProvider } from "@configdirector/react-native-sdk";

export default function App() {
  return (
    <ConfigDirectorProvider
      sdkKey={"YOUR-CLIENT-SDK-KEY"}
      appName="MyAwesomeApp"
      appVersion="1.0.0">
      <View>
        <AwesomeApp />
      </View>
    </ConfigDirectorProvider>
  );
};
```

</template>

<template v-slot:flutter="">
<code-group>

```bash [flutter]
flutter pub add configdirector_flutter_client_sdk
```

```yaml [pubspec.yaml]
dependencies:
  configdirector_flutter_client_sdk: ^1.8.0
```

</code-group>

```dart [config_director_setup.dart (Initialize the client)]
import 'package:configdirector_flutter_client_sdk/configdirector_flutter_client_sdk.dart';

final client = ConfigDirectorClient(clientSdkKey: 'YOUR-CLIENT-SDK-KEY');

await client.initialize();
```

</template>

<template v-slot:swift="">

In Xcode, go to **File → Add Package Dependencies…** and enter the package URL:

```txt
https://github.com/ConfigDirector/configdirector-swift-sdk
```

To add it to a Swift package instead, declare it in `Package.swift`:

```swift [Package.swift]
dependencies: [
    .package(url: "https://github.com/ConfigDirector/configdirector-swift-sdk", from: "1.11.0"),
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [.product(name: "ConfigDirector", package: "configdirector-swift-sdk")]
    ),
]
```

```swift [ConfigDirectorSetup.swift]
import ConfigDirector

// Creating the client makes no network calls. It throws only for a programming
// error, such as a blank SDK key or a custom base URL that is invalid.
let client = try ConfigDirectorClient(clientSDKKey: "YOUR-CLIENT-SDK-KEY")

// Connects and waits until config values are received, or until it times out.
// After a timeout the client keeps trying to connect in the background.
await client.initialize()
```

The client is thread safe. Create one and share it for the lifetime of the app.

</template>

<template v-slot:android="">

The SDK is published to the [ConfigDirector Maven repository](https://docs.configdirector.com/sdks/maven-repository). Add the repository to `settings.gradle.kts` or `settings.gradle`, next to `google()` and `mavenCentral()`:

<code-group>

```kotlin [settings.gradle.kts]
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        exclusiveContent {
            forRepository {
                maven {
                    name = "ConfigDirector"
                    url = uri("https://maven.configdirector.com")
                }
            }
            filter {
                includeGroup("com.configdirector")
            }
        }
    }
}
```

```groovy [settings.gradle]
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        exclusiveContent {
            forRepository {
                maven {
                    name = 'ConfigDirector'
                    url = 'https://maven.configdirector.com'
                }
            }
            filter {
                includeGroup 'com.configdirector'
            }
        }
    }
}
```

</code-group>

Then add the dependencies to your app module:

<code-group>

```kotlin [build.gradle.kts]
dependencies {
    implementation("com.configdirector:android-sdk:1.10.0")

    // Optional, for Jetpack Compose applications
    implementation("com.configdirector:android-sdk-compose:1.10.0")
}
```

```groovy [build.gradle]
dependencies {
    implementation 'com.configdirector:android-sdk:1.10.0'

    // Optional, for Jetpack Compose applications
    implementation 'com.configdirector:android-sdk-compose:1.10.0'
}
```

```toml [libs.versions.toml]
[versions]
configdirector = "1.10.0"

[libraries]
configdirector-android-sdk = { module = "com.configdirector:android-sdk", version.ref = "configdirector" }
# Optional, for Jetpack Compose applications
configdirector-android-sdk-compose = { module = "com.configdirector:android-sdk-compose", version.ref = "configdirector" }
```

</code-group>

The SDK declares the `INTERNET` permission, which is merged into your application's manifest, so there is nothing to add there.

<code-group>

```kotlin [ConfigDirectorSetup.kt]
import com.configdirector.ConfigDirectorClient

// Creating the client makes no network calls. It throws only when the SDK key is
// blank or an option holds an unusable value.
val client = ConfigDirectorClient(applicationContext, "YOUR-CLIENT-SDK-KEY")

// Connects and waits until config values are received, or until it times out.
// After a timeout the client keeps trying to connect in the background.
client.initialize()
```

```java [ConfigDirectorSetup.java]
import com.configdirector.ConfigDirectorClient;

// Creating the client makes no network calls. It throws only when the SDK key is
// blank or an option holds an unusable value.
ConfigDirectorClient client = new ConfigDirectorClient(getApplicationContext(), "YOUR-CLIENT-SDK-KEY");

// Connects, and calls back on the main thread once config values are received or
// the attempt times out. After a timeout the client keeps trying in the background.
client.initialize(null, () -> Log.i("MyApp", "ConfigDirector ready: " + client.isReady()));
```

</code-group>

The client is thread safe. Create one and share it for the lifetime of the app.

`initialize` is a `suspend` function in Kotlin, so it is called from a coroutine. The overload taking a `CompletionCallback` is the one to use from Java, and from anywhere in Kotlin that has no coroutine to run in.

</template>

<template v-slot:node="">
<code-group>

```bash [npm]
npm install --save @configdirector/server-sdk
```

```bash [yarn]
yarn add @configdirector/server-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/server-sdk
```

```bash [bun]
bun add @configdirector/server-sdk
```

</code-group>

```ts [config-director-setup.ts (Initialize the client)]
import { createClient } from "@configdirector/server-sdk";

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
export const client = createClient("YOUR-SERVER-SDK-KEY");
await client.initialize();
```

</template>

<template v-slot:openfeature-node="">
<code-group>

```bash [npm]
npm install --save @openfeature/server-sdk @configdirector/openfeature-server-provider
```

```bash [yarn]
yarn add @openfeature/server-sdk @openfeature/core @configdirector/openfeature-server-provider
```

```bash [pnpm]Javascript
pnpm add @openfeature/server-sdk @openfeature/core @configdirector/openfeature-server-provider
```

```bash [bun]
bun add @openfeature/server-sdk @openfeature/core @configdirector/openfeature-server-provider
```

</code-group>

```ts
import { OpenFeature } from "@openfeature/server-sdk";
import { ConfigDirectorProvider } from "@configdirector/openfeature-server-provider";

const provider = new ConfigDirectorProvider("YOUR-SERVER-SDK-KEY");
try {
  await OpenFeature.setProviderAndWait(provider);
} catch (error) {
  console.warn("Starting on in-code default values until ConfigDirector sends config:", error);
}
const client = OpenFeature.getClient();
```

</template>

<template v-slot:openfeature-java="">

The provider is published to the [ConfigDirector Maven repository](https://docs.configdirector.com/sdks/maven-repository). Add the repository and the dependency to your build. If your Gradle build declares its repositories in `settings.gradle.kts` or `settings.gradle`, under `dependencyResolutionManagement`, the repository block goes there instead.

<code-group>

```kotlin [build.gradle.kts]
repositories {
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                name = "ConfigDirector"
                url = uri("https://maven.configdirector.com")
            }
        }
        filter {
            includeGroup("com.configdirector")
        }
    }
}

dependencies {
    implementation("com.configdirector:openfeature-server-provider:1.9.0")
}
```

```groovy [build.gradle]
repositories {
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                name = 'ConfigDirector'
                url = 'https://maven.configdirector.com'
            }
        }
        filter {
            includeGroup 'com.configdirector'
        }
    }
}

dependencies {
    implementation 'com.configdirector:openfeature-server-provider:1.9.0'
}
```

```xml [pom.xml]
<repositories>
  <repository>
    <id>configdirector</id>
    <url>https://maven.configdirector.com</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>false</enabled></snapshots>
  </repository>
</repositories>

<dependency>
  <groupId>com.configdirector</groupId>
  <artifactId>openfeature-server-provider</artifactId>
  <version>1.9.0</version>
</dependency>
```

</code-group>

```java [ConfigDirectorSetup.java]
import com.configdirector.openfeature.ConfigDirectorProvider;
import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;

OpenFeatureAPI api = OpenFeatureAPI.getInstance();
try {
    api.setProviderAndWait(new ConfigDirectorProvider("YOUR-SERVER-SDK-KEY"));
} catch (ProviderNotReadyError error) {
    System.err.println("Starting on in-code default values until ConfigDirector sends config: " + error.getMessage());
}
Client client = api.getClient();
```

</template>

<template v-slot:openfeature-python="">
<code-group>

```bash [pip]
pip install configdirector-openfeature-server-provider
```

</code-group>

```python [config_director_setup.py]
import logging

from configdirector_openfeature import ConfigDirectorProvider
from openfeature import api
from openfeature.exception import ProviderNotReadyError

try:
    api.set_provider_and_wait(ConfigDirectorProvider("YOUR-SERVER-SDK-KEY"))
except ProviderNotReadyError as error:
    logging.warning("Starting on in-code default values until ConfigDirector sends config: %s", error)
client = api.get_client()
```

</template>

<template v-slot:openfeature-dotnet="">
<code-group>

```bash [.NET CLI]
dotnet add package ConfigDirector.OpenFeature.ServerProvider --version 1.8.0
```

```xml [.csproj]
<ItemGroup>
  <PackageReference Include="ConfigDirector.OpenFeature.ServerProvider" Version="1.8.0" />
</ItemGroup>
```

</code-group>

```csharp [ConfigDirectorSetup.cs]
using ConfigDirector.OpenFeature;
using OpenFeature;

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Waits until the provider is initialized or it times out.
// If initialization times out, the provider will continue attempting to
// initialize in the background.
await Api.Instance.SetProviderAsync(new ConfigDirectorProvider("YOUR-SERVER-SDK-KEY"));
var client = Api.Instance.GetClient();
```

</template>

<template v-slot:openfeature-go="">
<code-group>

```bash [go get]
go get github.com/ConfigDirector/go-sdks/configdirector-openfeature@latest
```

</code-group>

```go [main.go]
import (
    "log"
    "log/slog"

    "github.com/ConfigDirector/go-sdks/configdirector"
    configdirectoropenfeature "github.com/ConfigDirector/go-sdks/configdirector-openfeature"
    "github.com/open-feature/go-sdk/openfeature"
)

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
provider, err := configdirectoropenfeature.NewProvider(configdirector.Options{SDKKey: "YOUR-SERVER-SDK-KEY"})
if err != nil {
    log.Fatal(err)
}

if err := openfeature.SetProviderAndWait(provider); err != nil {
    slog.Warn("Starting on in-code default values until ConfigDirector sends config", slog.Any("cause", err))
}
defer openfeature.Shutdown()

client := openfeature.NewClient("my-app")
```

</template>

<template v-slot:openfeature-php="">
<code-group>

```bash [composer]
composer require configdirector/openfeature-server-provider
```

</code-group>

```php [index.php]
use ConfigDirector\OpenFeature\ConfigDirectorProvider;
use OpenFeature\OpenFeatureAPI;

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Creating the provider reads the values kept on this host. Only when there are none yet,
// as on the first request of a new host or container, does it ask ConfigDirector and wait
// up to the connection timeout.
$api = OpenFeatureAPI::getInstance();
$api->setProvider(new ConfigDirectorProvider(serverSdkKey: 'YOUR-SERVER-SDK-KEY'));

$client = $api->getClient('my-app', '1.0.0');
```

</template>

<template v-slot:openfeature-ruby="">
<code-group>

```bash [bundler]
bundle add configdirector-openfeature-server-provider
```

</code-group>

```ruby [lib/open_feature_client_per_process.rb]
require "configdirector/openfeature"

# Registers the provider the first time a process reads a flag, and returns the same client afterwards.
module OpenFeatureClientPerProcess
  @lock = Mutex.new
  @client = nil

  def self.client
    @lock.synchronize { @client ||= client_after_registering_the_provider }
  end

  def self.client_after_registering_the_provider
    # IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
    provider = ConfigDirector::OpenFeature::ConfigDirectorProvider.new(ENV.fetch("CONFIGDIRECTOR_SERVER_KEY"))
    begin
      OpenFeature::SDK.set_provider_and_wait(provider)
    rescue OpenFeature::SDK::ProviderInitializationError => e
      warn("Starting on in-code default values until ConfigDirector sends config: #{e.message}")
    end
    at_exit { OpenFeature::SDK.shutdown }
    OpenFeature::SDK.build_client
  end

  private_class_method :client_after_registering_the_provider
end
```

</template>

<template v-slot:openfeature-swift="">
<code-group>

```bash [Xcode]
# In Xcode, go to File -> Add Package Dependencies... and enter the package URL:
https://github.com/ConfigDirector/configdirector-swift-openfeature-provider
```

```swift [Package.swift]
dependencies: [
    .package(url: "https://github.com/ConfigDirector/configdirector-swift-openfeature-provider", from: "1.6.0"),
    .package(url: "https://github.com/open-feature/swift-sdk", from: "0.6.0"),
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "ConfigDirectorOpenFeatureProvider", package: "configdirector-swift-openfeature-provider"),
            .product(name: "OpenFeature", package: "swift-sdk"),
        ]
    ),
]
```

</code-group>

```swift [ConfigDirectorSetup.swift]
import ConfigDirectorOpenFeatureProvider
import OpenFeature

let provider = try ConfigDirectorProvider(clientSDKKey: "YOUR-CLIENT-SDK-KEY")
await OpenFeatureAPI.shared.setProviderAndWait(
    provider: provider,
    initialContext: ImmutableContext(targetingKey: "user-123")
)
let client = OpenFeatureAPI.shared.getClient()
```

</template>

<template v-slot:openfeature-android="">

The provider is published to the [ConfigDirector Maven repository](https://docs.configdirector.com/sdks/maven-repository). Add the repository to `settings.gradle.kts` or `settings.gradle`, next to `google()` and `mavenCentral()`:

<code-group>

```kotlin [settings.gradle.kts]
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        exclusiveContent {
            forRepository {
                maven {
                    name = "ConfigDirector"
                    url = uri("https://maven.configdirector.com")
                }
            }
            filter {
                includeGroup("com.configdirector")
            }
        }
    }
}
```

```groovy [settings.gradle]
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        exclusiveContent {
            forRepository {
                maven {
                    name = 'ConfigDirector'
                    url = 'https://maven.configdirector.com'
                }
            }
            filter {
                includeGroup 'com.configdirector'
            }
        }
    }
}
```

</code-group>

Then add the dependency to your app module:

<code-group>

```kotlin [build.gradle.kts]
dependencies {
    implementation("com.configdirector:openfeature-android-provider:1.7.0")
}
```

```groovy [build.gradle]
dependencies {
    implementation 'com.configdirector:openfeature-android-provider:1.7.0'
}
```

```toml [libs.versions.toml]
[versions]
configdirector-openfeature = "1.7.0"

[libraries]
openfeature-provider = { module = "com.configdirector:openfeature-android-provider", version.ref = "configdirector-openfeature" }
```

</code-group>

```kotlin [ConfigDirectorSetup.kt]
import com.configdirector.openfeature.ConfigDirectorProvider
import dev.openfeature.kotlin.sdk.ImmutableContext
import dev.openfeature.kotlin.sdk.OpenFeatureAPI

// Creating the provider makes no network calls. It throws only when the SDK key is
// blank or an option holds an unusable value.
val provider = ConfigDirectorProvider(applicationContext, "YOUR-CLIENT-SDK-KEY")

// Connects and waits until config values are received, or until it times out.
// After a timeout the provider keeps trying to connect in the background.
OpenFeatureAPI.setProviderAndWait(provider, ImmutableContext(targetingKey = "user-123"))

val client = OpenFeatureAPI.getClient()
```

</template>

<template v-slot:openfeature-flutter="">
<code-group>

```bash [flutter]
flutter pub add configdirector_openfeature_flutter_provider:^0.1.0-beta.8 openfeature_dart_client_sdk:^0.0.1-beta.1
```

```yaml [pubspec.yaml]
dependencies:
  configdirector_openfeature_flutter_provider: ^0.1.0-beta.8
  openfeature_dart_client_sdk: ^0.0.1-beta.1
```

</code-group>

```dart [config_director_setup.dart (Register the provider)]
import 'package:configdirector_openfeature_flutter_provider/configdirector_openfeature_flutter_provider.dart';
import 'package:openfeature_dart_client_sdk/openfeature_dart_client_sdk.dart';

// Creating the provider makes no network calls. It throws only when the SDK key is
// blank or an option holds an unusable value.
final provider = ConfigDirectorProvider(clientSdkKey: 'YOUR-CLIENT-SDK-KEY');

// The context the provider connects with. Set it before the provider.
await OpenFeatureAPI.instance.setEvaluationContextAndWait(
  EvaluationContext(targetingKey: 'user-123'),
);

// Connects and waits until config values are received. It throws an
// OpenFeatureException on a timeout, after which the provider keeps trying to
// connect in the background.
await OpenFeatureAPI.instance.setProviderAndWait(provider);

final client = OpenFeatureAPI.instance.getClient();
```

</template>

<template v-slot:python="">
<code-group>

```bash [pip]
pip install configdirector-server-sdk
```

</code-group>

```python [config_director_setup.py]
from configdirector import create_client

client = create_client("YOUR-SERVER-SDK-KEY")

# Blocks until the client is initialized or it times out.
# If initialization times out, the client will continue attempting to
# initialize in the background.
client.initialize()
```

</template>

<template v-slot:java="">

The SDK is published to the [ConfigDirector Maven repository](https://docs.configdirector.com/sdks/maven-repository). Add the repository and the dependency to your build. If your Gradle build declares its repositories in `settings.gradle.kts` or `settings.gradle`, under `dependencyResolutionManagement`, the repository block goes there instead.

<code-group>

```kotlin [build.gradle.kts]
repositories {
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                name = "ConfigDirector"
                url = uri("https://maven.configdirector.com")
            }
        }
        filter {
            includeGroup("com.configdirector")
        }
    }
}

dependencies {
    implementation("com.configdirector:server-sdk:1.11.0")
}
```

```groovy [build.gradle]
repositories {
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                name = 'ConfigDirector'
                url = 'https://maven.configdirector.com'
            }
        }
        filter {
            includeGroup 'com.configdirector'
        }
    }
}

dependencies {
    implementation 'com.configdirector:server-sdk:1.11.0'
}
```

```xml [pom.xml]
<repositories>
  <repository>
    <id>configdirector</id>
    <url>https://maven.configdirector.com</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>false</enabled></snapshots>
  </repository>
</repositories>

<dependency>
  <groupId>com.configdirector</groupId>
  <artifactId>server-sdk</artifactId>
  <version>1.11.0</version>
</dependency>
```

</code-group>

```java [ConfigDirectorSetup.java]
import com.configdirector.ConfigDirector;
import com.configdirector.ConfigDirectorClient;

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Building the client makes no network calls.
ConfigDirectorClient client = ConfigDirector.client("YOUR-SERVER-SDK-KEY");

// Blocks until the client is initialized or it times out.
// If initialization times out, the client will continue attempting to
// initialize in the background.
client.initialize();
```

The client is thread safe. Create one at startup, share it for the lifetime of the process, and call `close` on shutdown.

</template>

<template v-slot:dotnet="">
<code-group>

```bash [.NET CLI]
dotnet add package ConfigDirector.ServerSdk --version 1.10.0
```

```xml [.csproj]
<ItemGroup>
  <PackageReference Include="ConfigDirector.ServerSdk" Version="1.10.0" />
</ItemGroup>
```

</code-group>

```csharp [ConfigDirectorSetup.cs]
using ConfigDirector;

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Building the client makes no network calls.
await using var client = new ConfigDirectorClient("YOUR-SERVER-SDK-KEY");

// Waits until the client is initialized or it times out.
// If initialization times out, the client will continue attempting to
// initialize in the background.
await client.InitializeAsync();
```

The client is thread safe. Create one at startup, share it for the lifetime of the process, and dispose it on shutdown.

</template>

<template v-slot:go="">
<code-group>

```bash [go get]
go get github.com/ConfigDirector/go-sdks/configdirector@latest
```

</code-group>

```go [main.go]
import (
    "context"
    "log"

    "github.com/ConfigDirector/go-sdks/configdirector"
)

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Creating the client starts its connection in the background.
client, err := configdirector.NewClient(configdirector.Options{SDKKey: "YOUR-SERVER-SDK-KEY"})
if err != nil {
    log.Fatal(err)
}
defer client.Close()

// Blocks until the first config state arrives or the connection timeout elapses.
// If the wait times out, the client keeps connecting in the background and
// reads return their in-code default value until config state arrives.
if err := client.WaitForReady(context.Background()); err != nil {
    log.Printf("ConfigDirector is not ready yet: %v", err)
}
```

The client is safe to share between goroutines. Create one at startup, share it for the lifetime of the process, and call `Close` on shutdown.

</template>

<template v-slot:php="">
<code-group>

```bash [composer]
composer require configdirector/server-sdk
```

</code-group>

```php [index.php]
use ConfigDirector\ConfigDirector;

// IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
// Creating the client makes no network call.
$client = ConfigDirector::createClient(serverSdkKey: 'YOUR-SERVER-SDK-KEY');

// Reads the values kept on this host. Only when there are none yet, as on the first
// request of a new host or container, does it ask ConfigDirector and wait up to the
// connection timeout. Without values, reads return their in-code default value.
$client->initialize();
```

Create one client per request, for example in your framework's container, and read through it as often as you need. The SDK disposes of the client when the request ends.

</template>

<template v-slot:ruby="">
<code-group>

```bash [bundler]
bundle add configdirector-server-sdk
```

</code-group>

```ruby [lib/config_director_client_per_process.rb]
require "configdirector"

# Creates the client the first time a process reads a config, and returns that client afterwards.
module ConfigDirectorClientPerProcess
  @lock = Mutex.new
  @client = nil

  def self.client
    @lock.synchronize { @client ||= created_and_initialized_client }
  end

  def self.created_and_initialized_client
    # IMPORTANT: Do not commit the server SDK key to your source code, it is a secret value.
    # Creating the client makes no network call.
    client = ConfigDirector.create_client(ENV.fetch("CONFIGDIRECTOR_SERVER_KEY"))

    # Waits for the first values, up to the connection timeout. If none arrive in time, the client
    # keeps connecting in the background and reads return their in-code default value until they do.
    client.init

    # Reports what the process evaluated since the last report, and closes the connection.
    at_exit { client.close }
    client
  end

  private_class_method :created_and_initialized_client
end
```

Read through `ConfigDirectorClientPerProcess.client` wherever your application reads a config. The client is safe to share between threads, and each process creates its own, as [Servers that fork their workers](https://docs.configdirector.com/sdks/server/ruby#servers-that-fork-their-workers) explains.

</template>

<template v-slot:nextjs="">
<code-group>

```bash [npm]
npm install --save @configdirector/nextjs-sdk
```

```bash [yarn]
yarn add @configdirector/nextjs-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/nextjs-sdk
```

```bash [bun]
bun add @configdirector/nextjs-sdk
```

</code-group>

```ts [instrumentation.ts]
export async function register() {
  const { register } = await import("@configdirector/nextjs-sdk/server");
  await register({
    // The server SDK key is a secret value, do not commit it to your source code repository.
    // In this example, we are assuming the environment variable CONFIGDIRECTOR_SERVER_SDK_KEY
    // will be populated at runtime with your server SDK key in the server environment
    serverSdkKey: process.env["CONFIGDIRECTOR_SERVER_SDK_KEY"]!,
  });
}
```

```tsx [app/layout.tsx]
import { ConfigDirectorProvider } from "@configdirector/nextjs-sdk/server";
import type { ReactNode } from "react";

export const dynamic = "force-dynamic";

export default async function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <ConfigDirectorProvider sdkKey={process.env["CONFIGDIRECTOR_CLIENT_SDK_KEY"]!}>
          <main>{children}</main>
        </ConfigDirectorProvider>
      </body>
    </html>
  );
}
```

</template>

<template v-slot:nuxt="">
<code-group>

```bash [npm]
npm install --save @configdirector/nuxt-sdk
```

```bash [yarn]
yarn add @configdirector/nuxt-sdk
```

```bash [pnpm]Javascript
pnpm add @configdirector/nuxt-sdk
```

```bash [bun]
bun add @configdirector/nuxt-sdk
```

</code-group>

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  //...
  modules: ["@configdirector/nuxt-sdk"],
  runtimeConfig: {
    public: {
      configdirector: {
        // You can also provide the key at runtime to match the given environment
        // via the NUXT_PUBLIC_CONFIGDIRECTOR_CLIENT_SDK_KEY environment variable
        clientSdkKey: "YOUR-CLIENT-SDK-KEY",
      },
    },
    configdirector: {
      // IMPORTANT: This is a secret, do not commit to your source repository
      // You can provide the server key at runtime via the
      // NUXT_CONFIGDIRECTOR_SERVER_SDK_KEY environment variable
      serverSdkKey: "YOUR-SERVER-SDK-KEY",
    },
  },
});
```

</template>
</sdk-tabs>

## 3. Retrieve config values

<sdk-tabs>
<template v-slot:javascript="">

```ts [main.ts (Use the client)]
import { client } from "./config-director-setup"

// Retrieve the current value
const value = client.getValue("my-config-key", false);

// Subscribe to value updates
const unwatchMyKey = client.watch(
  "my-config-key",
  false,
  (newValue) => {
    console.log("Value updated:", newValue)
  },
);

unwatchMyKey(); // Call the unwatch function returned to remove the listener

client.unwatch("my-config-key"); // Removes all listeners for that key
```

</template>

<template v-slot:react-web="">

```tsx [YourComponent.tsx]
import { useConfigValue } from "@configdirector/react-web-sdk";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);

  return (<p>my-config-key: {value}</p>);
}

export default YourComponent;
```

</template>

<template v-slot:vue="">

```vue [YourComponent.vue]
<script setup lang="ts">
import { useConfigValue } from "@configdirector/vue-sdk";

const { value } = useConfigValue("my-config-key", false);
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
</template>
```

</template>

<template v-slot:openfeature-web="">

```ts
const booleanValue = client.getBooleanValue("my-config-key", false);

const stringValue = client.getStringValue("my-string-config-key", "Default");
```

</template>

<template v-slot:react-native="">

```tsx [YourComponent.tsx]
import { Text } from "react-native";
import { useConfigValue } from "@configdirector/react-native-sdk";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);

  return <Text>my-config-key: {String(value)}</Text>;
}

export default YourComponent;
```

</template>

<template v-slot:flutter="">

```dart [main.dart (Use the client)]
import 'config_director_setup.dart';

// Retrieve the current value
final value = client.getValue('my-config-key', false);

// Subscribe to value updates
final subscription = client.watch('my-config-key', false).listen((newValue) {
  debugPrint('Value updated: $newValue');
});

await subscription.cancel(); // Cancel the subscription to remove the listener

client.unwatch('my-config-key'); // Closes every stream watching that key
```

</template>

<template v-slot:swift="">

```swift [ContentView.swift]
// Retrieve the current value. The default value decides the type the config
// is read as, and is returned until the client is ready.
let darkMode = client.value(for: "my-config-key", default: false)

// Subscribe to value updates. The stream yields the current value right away
// and then every time the evaluated value changes.
for await darkMode in client.values(for: "my-config-key", default: false) {
    print("Value updated: \(darkMode)")
}
```

</template>

<template v-slot:android="">
<code-group>

```kotlin [MainActivity.kt]
import com.configdirector.value
import com.configdirector.values

// Retrieve the current value. The default value decides the type the config
// is read as, and is returned until the client is ready.
val darkMode = client.value("my-config-key", false)

// Subscribe to value updates. The flow emits the current value right away
// and then every time the evaluated value changes.
lifecycleScope.launch {
    client.values("my-config-key", false).collect { darkMode ->
        Log.i("MyApp", "Value updated: $darkMode")
    }
}
```

```java [MainActivity.java]
import com.configdirector.Subscription;

// Retrieve the current value. There is a getter per type a config can be read
// as, and each returns the default value until the client is ready.
boolean darkMode = client.getBoolean("my-config-key", false);

// Subscribe to value updates. The listener is called on the main thread with the
// current value, and then every time the evaluated value changes.
Subscription subscription = client.watchBoolean(
    "my-config-key",
    false,
    value -> Log.i("MyApp", "Value updated: " + value));

// Close the subscription to stop watching
subscription.close();
```

```kotlin [SampleScreen.kt (Compose)]
import com.configdirector.compose.configValue

@Composable
fun SampleScreen() {
    // Recomposes whenever the evaluated value changes.
    val darkMode = configValue("my-config-key", false)

    Text("my-config-key: $darkMode")
}
```

</code-group>
</template>

<template v-slot:node="">

Retrieving config values via `getValue`, and subscribe to updates via `watch`:

```ts [main.ts]
import { client } from "./config-director-setup"

// Retrieve the current value
client.getValue("my-config-key", false);

// Subscribe to value updates
const unwatchMyKey = client.watch("my-config-key", false, (newValue) => {
  console.log("Value updated:", newValue);
});

unwatchMyKey(); // Call the unwatch function returned to remove the listener

client.unwatch("my-config-key"); // Removes all listeners for that key
```

</template>

<template v-slot:openfeature-node="">

```ts
const booleanValue = await client.getBooleanValue("my-config-key", false);

const stringValue = await client.getStringValue("my-string-config-key", "Default");
```

</template>

<template v-slot:openfeature-java="">

```java [Main.java]
boolean booleanValue = client.getBooleanValue("my-config-key", false);

String stringValue = client.getStringValue("my-string-config-key", "Default");
```

</template>

<template v-slot:openfeature-python="">

```python [main.py]
boolean_value = client.get_boolean_value("my-config-key", False)

string_value = client.get_string_value("my-string-config-key", "Default")
```

</template>

<template v-slot:openfeature-dotnet="">

```csharp [Program.cs]
var booleanValue = await client.GetBooleanValueAsync("my-config-key", false);

var stringValue = await client.GetStringValueAsync("my-string-config-key", "Default");
```

</template>

<template v-slot:openfeature-go="">

Every getter takes a `context.Context` first, such as the request's context in an HTTP handler, and the evaluation context last:

```go [main.go]
booleanValue := client.Boolean(ctx, "my-config-key", false, openfeature.EvaluationContext{})

stringValue := client.String(ctx, "my-string-config-key", "Default", openfeature.EvaluationContext{})
```

</template>

<template v-slot:openfeature-php="">

Every getter takes the flag key, the in-code default value and, optionally, the evaluation context:

```php [index.php]
$booleanValue = $client->getBooleanValue('my-config-key', false);

$stringValue = $client->getStringValue('my-string-config-key', 'Default');
```

</template>

<template v-slot:openfeature-ruby="">

Every getter takes the flag key and the in-code default value and, optionally, the evaluation context, as keyword arguments:

```ruby [main.rb]
client = OpenFeatureClientPerProcess.client

boolean_value = client.fetch_boolean_value(flag_key: "my-config-key", default_value: false)

string_value = client.fetch_string_value(flag_key: "my-string-config-key", default_value: "Default")
```

</template>

<template v-slot:openfeature-swift="">

```swift [ContentView.swift]
let booleanValue = client.getBooleanValue(key: "my-config-key", defaultValue: false)

let stringValue = client.getStringValue(key: "my-string-config-key", defaultValue: "Default")
```

</template>

<template v-slot:openfeature-android="">

```kotlin [MainActivity.kt]
val booleanValue = client.getBooleanValue("my-config-key", false)

val stringValue = client.getStringValue("my-string-config-key", "Default")
```

</template>

<template v-slot:python="">

Retrieve config values via `get_value`, and subscribe to updates via `watch`. The first argument is the config key, the second is the default value. The type of the default value provided determines the type the config is parsed as. The default value is returned if the config is not available or cannot be parsed as the given type:

```python [main.py]
# Retrieve config values
retries = client.get_value("max-retries", 3)
theme = client.get_value("theme", "light")
limits = client.get_value("rate-limits", {"per_minute": 60}) # JSON config

# Watch for config updates
def on_change(value: bool) -> None:
    print(f"new-checkout is now {value}")

subscription = client.watch("new-checkout", False, on_change)

# Call close when the subscription is no longer needed
subscription.close()
```

</template>

<template v-slot:java="">

Retrieve config values via the typed getters, and subscribe to updates via the matching typed watches. The first argument is the config key and the second is the default value, which is returned if the config is not available or cannot be parsed as the given type:

```java [Main.java]
import com.configdirector.Subscription;
import java.util.Map;

// Retrieve config values
int retries = client.getInteger("max-retries", 3);
String theme = client.getString("theme", "light");
boolean newCheckout = client.getBoolean("new-checkout", false);
Map<String, Object> limits = client.getJsonObject("rate-limits", Map.of("per_minute", 60)); // JSON config

// Watch for config updates
Subscription subscription = client.watchBoolean(
    "new-checkout",
    false,
    value -> System.out.println("new-checkout is now " + value));

// Call close when the subscription is no longer needed
subscription.close();
```

</template>

<template v-slot:dotnet="">

Retrieve config values via the typed `GetValue` overloads, and subscribe to updates via `Watch`. The first argument is the config key and the second is the default value, which is returned if the config is not available or cannot be read as the given type. The type of the default value decides the type the config is read as:

```csharp [Program.cs]
using System.Text.Json;

// Retrieve config values
var retries = client.GetValue("max-retries", 3);
var theme = client.GetValue("theme", "light");
var newCheckout = client.GetValue("new-checkout", false);
var limits = client.GetValue("rate-limits", JsonDocument.Parse("{}").RootElement.Clone()); // JSON config

// Watch for config updates
var subscription = client.Watch(
    "new-checkout",
    false,
    value => Console.WriteLine($"new-checkout is now {value}"));

// Dispose the subscription when it is no longer needed
subscription.Dispose();
```

</template>

<template v-slot:go="">

Retrieve config values via the typed value methods, and subscribe to updates via the typed watches. The first argument is the config key, the second is the in-code default value, which is returned if the config is not available or cannot be read as the given type, and the third is the context targeting rules are evaluated for. The method decides the type the config is read as:

```go [main.go]
user := configdirector.UserContext{ID: "user-id"}

// Retrieve config values
retries := client.IntValue("max-retries", 3, user)
theme := client.StringValue("theme", "light", user)
newCheckout := client.BoolValue("new-checkout", false, user)

// A JSON config is decoded into a value of your own, which holds the in-code default value
limits := map[string]any{"per_minute": 60}
if err := client.JSONValue("rate-limits", &limits, user); err != nil {
    log.Fatal(err)
}

// Watch for config updates
unwatch := client.WatchBool("new-checkout", false, user, func(value bool) {
    log.Printf("new-checkout is now %t", value)
})

// Call unwatch when the watch is no longer needed
unwatch()
```

</template>

<template v-slot:php="">

Retrieve config values with `getValue`. The first argument is the config key, the second is the in-code default value, which is returned if the config is not available or cannot be read as its type, and the third is the context targeting rules are evaluated for. The type of the in-code default value decides the type the config is read as:

```php [index.php]
use ConfigDirector\Context;

$user = new Context(id: 'user-id');

// Retrieve config values
$retries = $client->getValue('max-retries', 3, $user);
$theme = $client->getValue('theme', 'light', $user);
$newCheckout = $client->getValue('new-checkout', false, $user);

// A JSON config is read as an array, and so is its in-code default value
$limits = $client->getValue('rate-limits', ['per_minute' => 60], $user);
```

</template>

<template v-slot:ruby="">

Retrieve config values with `get_value`, and subscribe to updates with `watch`. The first argument is the config key, the second is the in-code default value, which is returned if the config is not available or cannot be read as its class, and the third is the context targeting rules are evaluated for. The class of the in-code default value decides how the config is read:

```ruby [main.rb]
client = ConfigDirectorClientPerProcess.client
user = ConfigDirector::Context.new(id: "user-id")

# Retrieve config values
retries = client.get_value("max-retries", 3, user)
theme = client.get_value("theme", "light", user)
new_checkout = client.get_value("new-checkout", false, user)

# A JSON config is read as a Hash, and so is its in-code default value
limits = client.get_value("rate-limits", { "per_minute" => 60 }, user)

# Watch for config updates
subscription = client.watch("new-checkout", false, user) do |enabled|
  puts "new-checkout is now #{enabled}"
end

# Close the subscription when the watch is no longer needed
subscription.close
```

</template>

<template v-slot:nextjs="">

Retrieving config values in client components:

```tsx [YourComponent.tsx]
"use client";

import { useConfigValue } from "@configdirector/nextjs-sdk/client";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);

  return (<p>my-config-key: {value}</p>);
}

export default YourComponent;
```

Retrieving config values in server routes:

```ts [route.ts]
import { getConfigClient } from "@configdirector/nextjs-sdk/server";

export async function GET() {
  const client = getConfigClient();
  const value = client.getValue("my-config-key", false);
  return Response.json({ "my-config-key": value });
}
```

</template>

<template v-slot:nuxt="">

Retrieving config values in components:

```vue [YourComponent.vue]
<script setup lang="ts">
const { value } = useConfigDirectorValue("my-config-key", false);
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
</template>
```

Retrieving config values in server resource handlers:

```ts [server-resource.get.ts]
export default defineEventHandler(async (_event) => {
  const client = useConfigDirectorServerClient();
  return client.getValue("my-config-key", false);
});
```

</template>
</sdk-tabs>

## 4. Configure contexts and targeting rules

1. With any of our SDKs you can provide an optional context with attributes that can be leveraged in targeting rules. A context describes a user unless you give it another [context kind](https://docs.configdirector.com/getting-started/core-concepts#contexts), such as a device or a tenant. Choose your SDK for instructions on how to provide a context:

<sdk-tabs>
<template v-slot:javascript="">

A context can be provided when initializing the client:

```ts [config-director-setup.ts]
import { createClient } from "@configdirector/client-sdk";

export const client = createClient("YOUR-CLIENT-SDK-KEY");
await client.initialize({
  id: "12345",
  name: "Example User",
  traits: {
    region: "North America", // Any arbitrary traits which can be referenced in targeting rules
  }
});
```

The context can also be updated via `updateContext`:

```ts [main.ts]
import { client } from "./config-director-setup"

await client.updateContext({
  id: "654321",
  name: "Another User",
  traits: {
    region: "Australia",
  },
});

// Update it to `undefined` (anonymous user context) when a user signs out
await client.updateContext();
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```ts [main.ts]
await client.updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

</template>

<template v-slot:react-web="">

The browser connects with the context given to the provider's `context` prop. Give it there when you already know the context as the page loads, so the first connection carries it:

```tsx [main.tsx]
import { createRoot } from "react-dom/client"
import App from "./App"
import { ConfigDirectorProvider } from "@configdirector/react-web-sdk";

createRoot(document.getElementById("root")!).render(
  <ConfigDirectorProvider
    sdkKey="YOUR-CLIENT-SDK-KEY"
    context={{ id: "12345", name: "Example User", traits: { region: "North America" } }}>
    <App />
  </ConfigDirectorProvider>
);
```

To change the context afterwards, for example when a user signs in, call `updateContext` from the `useContext` hook where the change happens. Each `updateContext` call opens a new connection with the new context:

```tsx [YourComponent.tsx]
import { useConfigValue, useContext } from "@configdirector/react-web-sdk";

function YourComponent() {
  const { value: myConfigValue } = useConfigValue("my-config", "default value");
  const { updateContext } = useContext();

  const onUpdate = async () => {
    await updateContext({
      id: "654321",
      name: "Another User",
      traits: {
        region: "Australia",
      },
    });
  };

  return (
    <div>
      <p>My config value: {myConfigValue}</p>
      <button type="button" onClick={onUpdate}>
        Update context
      </button>
    </div>
  );
}

export default YourComponent;
```

Rendering the provider with a different `context` prop updates the context the same way.

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```tsx [YourComponent.tsx]
updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

</template>

<template v-slot:vue="">

A context can be provided when initializing the plugin:

```ts [main.ts]
import { createApp } from "vue";
import App from "./App.vue";
import { ConfigDirectorPlugin } from "@configdirector/vue-sdk";

const app = createApp(App);

app.use(ConfigDirectorPlugin, {
  sdkKey: "YOUR-CLIENT-SDK-KEY",
  context: {
    id: "12345",
    name: "Example User",
    traits: {
      region: "North America", // Any arbitrary traits which can be referenced in targeting rules
    },
  },
});

app.mount("#app");
```

The context can also be updated via the `useContext` composable:

```vue [YourComponent.vue]
<script setup lang="ts">
import { useConfigValue, useContext } from "@configdirector/vue-sdk";

const { updateContext } = useContext();
const { value } = useConfigValue("my-config-key", false);

const onUpdate = () => {
  updateContext({
    id: "654321",
    name: "Another User",
    traits: {
      region: "Australia",
    },
  });
};
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
  <button type="button" @click="onUpdate">Update Context</button>
</template>
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```ts
updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

</template>

<template v-slot:openfeature-web="">

The provider connects with the context it has when it is registered, as shown in [Configure and initialize the client](https://docs.configdirector.com/sdks/openfeature/web#configure-and-initialize-the-client). To change the context afterwards, for example when a user signs in, call `OpenFeature.setContext`. Each change opens a new connection with the new context:

```ts
await OpenFeature.setContext({
  targetingKey: "654321",
  name: "Another User",
  traits: {
    region: "Australia",
  },
});
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```ts
await OpenFeature.setContext({
  targetingKey: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 1.7.0 of the provider.

</template>

<template v-slot:react-native="">

The app connects with the context given to the provider's `context` prop. Give it there when you already know the context as the app starts, so the first connection carries it:

```tsx [main.tsx]
import { View } from "react-native";
import AwesomeApp from "./AwesomeApp";
import { ConfigDirectorProvider } from "@configdirector/react-native-sdk";

export default function App() {
  return (
    <ConfigDirectorProvider
      sdkKey={"YOUR-CLIENT-SDK-KEY"}
      appName="MyAwesomeApp"
      appVersion="1.0.0"
      context={{ id: "12345", name: "Example User", traits: { region: "North America" } }}>
      <View>
        <AwesomeApp />
      </View>
    </ConfigDirectorProvider>
  );
};
```

To change the context afterwards, for example when a user signs in, call `updateContext` from the `useContext` hook where the change happens. Each `updateContext` call opens a new connection with the new context:

```tsx [YourComponent.tsx]
import { Button, Text, View } from "react-native";
import { useConfigValue, useContext } from "@configdirector/react-native-sdk";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);
  const { updateContext } = useContext();

  const onUpdate = async () => {
    await updateContext({
      id: "654321",
      name: "Another User",
      traits: {
        region: "Australia",
      },
    });
  };

  return (
    <View>
      <Text>my-config-key: {String(value)}</Text>
      <Button title="Update context" onPress={onUpdate} />
    </View>
  );
}

export default YourComponent;
```

Rendering the provider with a different `context` prop updates the context the same way.

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```tsx [YourComponent.tsx]
updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

</template>

<template v-slot:flutter="">

A context can be provided when initializing the client:

```dart [config_director_setup.dart]
import 'package:configdirector_flutter_client_sdk/configdirector_flutter_client_sdk.dart';

final client = ConfigDirectorClient(clientSdkKey: 'YOUR-CLIENT-SDK-KEY');

await client.initialize(
  const ConfigDirectorContext(
    id: '12345',
    name: 'Example User',
    traits: {
      // Any arbitrary traits which can be referenced in targeting rules
      'region': 'North America',
    },
  ),
);
```

The context can also be updated via `updateContext`:

```dart [main.dart]
import 'package:configdirector_flutter_client_sdk/configdirector_flutter_client_sdk.dart';

import 'config_director_setup.dart';

await client.updateContext(
  const ConfigDirectorContext(
    id: '654321',
    name: 'Another User',
    traits: {'region': 'Australia'},
  ),
);

// Update it to a context with no `id` (anonymous user context) when a user
// signs out. ConfigDirector derives an identifier that lasts until the app is
// uninstalled, or on the web until the site's data is cleared.
await client.updateContext(const ConfigDirectorContext());
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```dart [main.dart]
await client.updateContext(
  const ConfigDirectorContext(
    id: 'acme',
    kind: 'tenant',
    name: 'Acme Inc.',
    traits: {'plan': 'enterprise'},
  ),
);
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.6.0 of the SDK.

</template>

<template v-slot:swift="">

A context can be provided when initializing the client:

```swift [ConfigDirectorSetup.swift]
import ConfigDirector

let client = try ConfigDirectorClient(clientSDKKey: "YOUR-CLIENT-SDK-KEY")

await client.initialize(
    context: ConfigDirectorContext(
        id: "12345",
        name: "Example User",
        traits: [
            // Any arbitrary traits which can be referenced in targeting rules
            "region": "North America",
        ]
    )
)
```

The context can also be updated via `updateContext`:

```swift [ContentView.swift]
await client.updateContext(
    ConfigDirectorContext(
        id: "654321",
        name: "Another User",
        traits: ["region": "Australia"]
    )
)

// Update it to an anonymous context when a user signs out. Leaving `id` unset
// makes ConfigDirector derive an identifier that lasts until the app is uninstalled.
await client.updateContext(ConfigDirectorContext(isAnonymous: true))
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```swift [ContentView.swift]
await client.updateContext(
    ConfigDirectorContext(
        id: "acme",
        kind: "tenant",
        name: "Acme Inc.",
        traits: ["plan": "enterprise"]
    )
)
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.8.0 of the SDK.

</template>

<template v-slot:android="">

A context can be provided when initializing the client:

<code-group>

```kotlin [ConfigDirectorSetup.kt]
import com.configdirector.ConfigDirectorClient
import com.configdirector.ConfigDirectorContext

val client = ConfigDirectorClient(applicationContext, "YOUR-CLIENT-SDK-KEY")

client.initialize(
    ConfigDirectorContext.build {
        id("12345")
        name("Example User")
        // Any arbitrary traits which can be referenced in targeting rules
        trait("region", "North America")
    },
)
```

```java [ConfigDirectorSetup.java]
import com.configdirector.ConfigDirectorClient;
import com.configdirector.ConfigDirectorContext;

ConfigDirectorClient client = new ConfigDirectorClient(getApplicationContext(), "YOUR-CLIENT-SDK-KEY");

ConfigDirectorContext context = ConfigDirectorContext.builder()
    .id("12345")
    .name("Example User")
    // Any arbitrary traits which can be referenced in targeting rules
    .trait("region", "North America")
    .build();

client.initialize(context, () -> Log.i("MyApp", "ConfigDirector ready: " + client.isReady()));
```

</code-group>

The context can also be updated via `updateContext`:

<code-group>

```kotlin [MainActivity.kt]
import com.configdirector.ConfigDirectorContext

client.updateContext(
    ConfigDirectorContext.build {
        id("654321")
        name("Another User")
        trait("region", "Australia")
    },
)

// Update it to an anonymous context when a user signs out. Leaving `id` unset
// makes ConfigDirector derive an identifier that lasts until the app is uninstalled.
client.updateContext(ConfigDirectorContext.build { anonymous(true) })
```

```java [MainActivity.java]
import com.configdirector.ConfigDirectorContext;

client.updateContext(
    ConfigDirectorContext.builder()
        .id("654321")
        .name("Another User")
        .trait("region", "Australia")
        .build(),
    () -> Log.i("MyApp", "Context updated"));

// Update it to an anonymous context when a user signs out. Leaving `id` unset
// makes ConfigDirector derive an identifier that lasts until the app is uninstalled.
client.updateContext(
    ConfigDirectorContext.builder().anonymous(true).build(),
    () -> Log.i("MyApp", "Signed out"));
```

</code-group>

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

<code-group>

```kotlin [MainActivity.kt]
client.updateContext(
    ConfigDirectorContext.build {
        id("acme")
        kind("tenant")
        name("Acme Inc.")
        trait("plan", "enterprise")
    },
)
```

```java [MainActivity.java]
client.updateContext(
    ConfigDirectorContext.builder()
        .id("acme")
        .kind("tenant")
        .name("Acme Inc.")
        .trait("plan", "enterprise")
        .build(),
    () -> Log.i("MyApp", "Context updated"));
```

</code-group>

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.8.0 of the SDK.

</template>

<template v-slot:node="">

The context can be provided as the third argument to `getValue`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```ts [main.ts]
import { client } from "./config-director-setup"

client.getValue("my-config-key", false, {
  id: "12345",
  name: "Example User",
  traits: {
    region: "North America", // Any arbitrary traits which can be referenced in targeting rules
  },
});
```

It can also be provided as the fourth argument to `watch`:

```ts [main.ts]
import { client } from "./config-director-setup"

const unwatchMyKey = client.watch(
  "my-config-key",
  false,
  (newValue) => console.log("Value updated:", newValue),
  {
    id: "12345",
    name: "Example User",
    traits: {
      region: "North America",
    },
  },
);
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```ts [main.ts]
client.getValue("my-config-key", false, {
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.10.0 of the SDK.

</template>

<template v-slot:openfeature-node="">

The context can be provided as the third argument to value getter functions of the OpenFeature client. The OpenFeature Node.js provider evaluates targeting rules locally without additional network calls for different contexts.

```ts
const booleanValue = await client.getBooleanValue("my-config-key", false, {
  targetingKey: "12345", // In OpenFeature, the `targetingKey` represents the context's identifier
  name: "Example User",
  traits: {
    region: "North America", // Any arbitrary traits which can be referenced in targeting rules
  },
});
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```ts
const booleanValue = await client.getBooleanValue("my-config-key", false, {
  targetingKey: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 1.10.0 of the provider.

</template>

<template v-slot:openfeature-java="">

The context can be provided as the third argument to value getter functions of the OpenFeature client. The OpenFeature Java provider evaluates targeting rules locally without additional network calls for different contexts.

```java [Main.java]
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.ImmutableStructure;
import dev.openfeature.sdk.Value;
import java.util.Map;

// Any arbitrary traits which can be referenced in targeting rules
ImmutableStructure traits = new ImmutableStructure(Map.of("region", new Value("North America")));

EvaluationContext context = new ImmutableContext(
    "12345", // In OpenFeature, the targeting key represents the context's identifier
    Map.of("name", new Value("Example User"), "traits", new Value(traits)));

boolean booleanValue = client.getBooleanValue("my-config-key", false, context);
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```java [Main.java]
EvaluationContext tenant = new ImmutableContext(
    "acme",
    Map.of(
        "kind", new Value("tenant"),
        "name", new Value("Acme Inc."),
        "traits", new Value(new ImmutableStructure(Map.of("plan", new Value("enterprise"))))));

boolean booleanValue = client.getBooleanValue("my-config-key", false, tenant);
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 1.6.0 of the provider.

</template>

<template v-slot:openfeature-python="">

The context can be provided as the third argument to value getter functions of the OpenFeature client. The OpenFeature Python provider evaluates targeting rules locally without additional network calls for different contexts.

```python [main.py]
from openfeature.evaluation_context import EvaluationContext

context = EvaluationContext(
    "12345",  # In OpenFeature, the targeting key represents the context's identifier
    {
        "name": "Example User",
        # Any arbitrary traits which can be referenced in targeting rules
        "traits": {"region": "North America"},
    },
)

boolean_value = client.get_boolean_value("my-config-key", False, context)
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```python [main.py]
tenant = EvaluationContext("acme", {"kind": "tenant", "name": "Acme Inc.", "traits": {"plan": "enterprise"}})

boolean_value = client.get_boolean_value("my-config-key", False, tenant)
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 1.5.0 of the provider.

</template>

<template v-slot:openfeature-dotnet="">

The context can be provided as the third argument to value getter methods of the OpenFeature client. The OpenFeature .NET provider evaluates targeting rules locally without additional network calls for different contexts.

```csharp [Program.cs]
using OpenFeature.Model;

var context = EvaluationContext.Builder()
    .SetTargetingKey("12345") // In OpenFeature, the targeting key represents the context's identifier
    .Set("name", "Example User")
    // Any arbitrary traits which can be referenced in targeting rules
    .Set("traits", Structure.Builder().Set("region", "North America").Build())
    .Build();

var booleanValue = await client.GetBooleanValueAsync("my-config-key", false, context);
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```csharp [Program.cs]
var tenant = EvaluationContext.Builder()
    .SetTargetingKey("acme")
    .Set("kind", "tenant")
    .Set("name", "Acme Inc.")
    .Set("traits", Structure.Builder().Set("plan", "enterprise").Build())
    .Build();

var booleanValue = await client.GetBooleanValueAsync("my-config-key", false, tenant);
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 1.5.0 of the provider.

</template>

<template v-slot:openfeature-go="">

The context is the last argument of every getter of the OpenFeature client. The OpenFeature Go provider evaluates targeting rules locally without additional network calls for different contexts.

```go [main.go]
import "github.com/open-feature/go-sdk/openfeature"

user := openfeature.NewEvaluationContext(
    "12345", // In OpenFeature, the targeting key represents the context's identifier
    map[string]any{
        "name": "Example User",
        // Any arbitrary traits which can be referenced in targeting rules
        "traits": map[string]any{"region": "North America"},
    },
)

booleanValue := client.Boolean(ctx, "my-config-key", false, user)
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```go [main.go]
tenant := openfeature.NewEvaluationContext(
    "acme",
    map[string]any{
        "kind":   "tenant",
        "name":   "Acme Inc.",
        "traits": map[string]any{"plan": "enterprise"},
    },
)

booleanValue := client.Boolean(ctx, "my-config-key", false, tenant)
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given. Context kinds are available from version 0.2.0 of the provider.

</template>

<template v-slot:openfeature-php="">

The context is the third argument of every getter of the OpenFeature client. The OpenFeature PHP provider evaluates targeting rules locally without additional network calls for different contexts.

```php [index.php]
use OpenFeature\implementation\flags\Attributes;
use OpenFeature\implementation\flags\EvaluationContext;

$user = new EvaluationContext(
    '12345', // In OpenFeature, the targeting key represents the context's identifier
    new Attributes([
        'name' => 'Example User',
        // Any arbitrary traits which can be referenced in targeting rules
        'traits' => ['region' => 'North America'],
    ]),
);

$booleanValue = $client->getBooleanValue('my-config-key', false, $user);
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```php [index.php]
$tenant = new EvaluationContext(
    'acme',
    new Attributes([
        'kind' => 'tenant',
        'name' => 'Acme Inc.',
        'traits' => ['plan' => 'enterprise'],
    ]),
);

$booleanValue = $client->getBooleanValue('my-config-key', false, $tenant);
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given.

</template>

<template v-slot:openfeature-ruby="">

The context is the `evaluation_context` argument of every getter of the OpenFeature client. The OpenFeature Ruby provider evaluates targeting rules locally without additional network calls for different contexts.

```ruby [main.rb]
user = OpenFeature::SDK::EvaluationContext.new(
  targeting_key: "12345", # In OpenFeature, the targeting key represents the context's identifier
  name: "Example User",
  traits: { "region" => "North America" } # Any arbitrary traits which can be referenced in targeting rules
)

boolean_value = client.fetch_boolean_value(flag_key: "my-config-key", default_value: false, evaluation_context: user)
```

To evaluate flags for an entity other than a user, such as a tenant, set the context kind with a top-level `kind` attribute:

```ruby [main.rb]
tenant = OpenFeature::SDK::EvaluationContext.new(
  targeting_key: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: { "plan" => "enterprise" }
)

boolean_value = client.fetch_boolean_value(flag_key: "my-config-key", default_value: false, evaluation_context: tenant)
```

Leaving `kind` out means `user`. A `kind` inside `traits` is an ordinary trait, not the context kind. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and flags still resolve successfully, as if no context had been given.

</template>

<template v-slot:python="">

The context can be provided as the third argument to `get_value`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```python [main.py]
from configdirector import Context

client.get_value("my-boolean-config-key", False, Context(id="user-id", name="Example User"))
```

It can also be provided as the fourth argument to `watch`:

```python [main.py]
def on_change(value: bool) -> None:
    print(f"new-checkout is now {value}")

subscription = client.watch(
  "new-checkout",
  False,
  on_change,
  Context(
    id="user-id",
    name="Example User",
    traits={"region": "North America"}
  )
)
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```python [main.py]
tenant = Context(id="acme", kind="tenant", name="Acme Inc.", traits={"plan": "enterprise"})

client.get_value("my-boolean-config-key", False, tenant)
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

</template>

<template v-slot:java="">

The context can be provided as the last argument to any of the getters. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```java [Main.java]
import com.configdirector.Context;

Context context = Context.builder()
    .id("12345")
    .name("Example User")
    .trait("region", "North America") // Any arbitrary traits which can be referenced in targeting rules
    .build();

client.getBoolean("my-boolean-config-key", false, context);
```

It can also be provided as the last argument to any of the watches:

```java [Main.java]
import com.configdirector.Context;
import com.configdirector.Subscription;

Subscription subscription = client.watchBoolean(
    "new-checkout",
    false,
    value -> System.out.println("new-checkout is now " + value),
    Context.builder()
        .id("12345")
        .name("Example User")
        .trait("region", "North America")
        .build());
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```java [Main.java]
Context tenant = Context.builder()
    .id("acme")
    .kind("tenant")
    .name("Acme Inc.")
    .trait("plan", "enterprise")
    .build();

client.getBoolean("my-boolean-config-key", false, tenant);
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.9.0 of the SDK.

</template>

<template v-slot:dotnet="">

The context can be provided as the last argument to any of the getters. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```csharp [Program.cs]
using ConfigDirector;

var context = new Context
{
    Id = "12345",
    Name = "Example User",
    Traits =
    {
        ["region"] = "North America", // Any arbitrary traits which can be referenced in targeting rules
    },
};

client.GetValue("my-boolean-config-key", false, context);
```

It can also be provided as the fourth argument to `Watch`:

```csharp [Program.cs]
using ConfigDirector;

var subscription = client.Watch(
    "new-checkout",
    false,
    value => Console.WriteLine($"new-checkout is now {value}"),
    new Context
    {
        Id = "12345",
        Name = "Example User",
        Traits = { ["region"] = "North America" },
    });
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `Kind`:

```csharp [Program.cs]
var tenant = new Context
{
    Id = "acme",
    Kind = "tenant",
    Name = "Acme Inc.",
    Traits = { ["plan"] = "enterprise" },
};

client.GetValue("my-boolean-config-key", false, tenant);
```

Leaving `Kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.8.0 of the SDK.

</template>

<template v-slot:go="">

The context is the last argument of every value method. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```go [main.go]
import "github.com/ConfigDirector/go-sdks/configdirector"

user := configdirector.UserContext{
    ID:   "12345",
    Name: "Example User",
    Traits: map[string]any{
        "region": "North America", // Any arbitrary traits which can be referenced in targeting rules
    },
}

client.BoolValue("my-boolean-config-key", false, user)
```

It is also the third argument of every watch:

```go [main.go]
unwatch := client.WatchBool("new-checkout", false, user, func(value bool) {
    log.Printf("new-checkout is now %t", value)
})
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `Kind`:

```go [main.go]
tenant := configdirector.UserContext{
    ID:   "acme",
    Kind: "tenant",
    Name: "Acme Inc.",
    Traits: map[string]any{
        "plan": "enterprise",
    },
}

client.BoolValue("my-boolean-config-key", false, tenant)
```

Leaving `Kind` empty means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 0.3.0 of the SDK.

</template>

<template v-slot:php="">

The context is the last argument of `getValue`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```php [index.php]
use ConfigDirector\Context;

$user = new Context(
    id: '12345',
    name: 'Example User',
    traits: [
        'region' => 'North America', // Any arbitrary traits which can be referenced in targeting rules
    ],
);

$client->getValue('my-boolean-config-key', false, $user);
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```php [index.php]
$tenant = new Context(
    id: 'acme',
    kind: 'tenant',
    name: 'Acme Inc.',
    traits: ['plan' => 'enterprise'],
);

$client->getValue('my-boolean-config-key', false, $tenant);
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given.

</template>

<template v-slot:ruby="">

The context is the last argument of `get_value`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```ruby [main.rb]
user = ConfigDirector::Context.new(
  id: "12345",
  name: "Example User",
  traits: { "region" => "North America" } # Any arbitrary traits which can be referenced in targeting rules
)

client.get_value("my-boolean-config-key", false, user)
```

It is also the third argument of `watch`:

```ruby [main.rb]
subscription = client.watch("new-checkout", false, user) do |enabled|
  puts "new-checkout is now #{enabled}"
end
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`:

```ruby [main.rb]
tenant = ConfigDirector::Context.new(
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: { "plan" => "enterprise" }
)

client.get_value("my-boolean-config-key", false, tenant)
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given.

</template>

<template v-slot:nextjs="">

The browser connects with the context given to the provider's `context` prop. Give it there when the page loads, for example from a cookie read in the root layout as shown in [Configure the client provider](https://docs.configdirector.com/sdks/meta/nextjs#configure-the-client-provider), so the first connection carries it.

To change the context afterwards, for example when a user signs in, call `updateContext` from the `useContext` hook where the change happens:

```tsx [YourComponent.tsx]
"use client";

import { useConfigValue, useContext } from "@configdirector/nextjs-sdk/client";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);
  const { updateContext } = useContext();

  const onUpdate = async () => {
    await updateContext({
      id: "654321",
      name: "Another User",
      traits: {
        region: "Australia",
      },
    });
  };

  return (
    <div>
      <p>my-config-key: {String(value)}</p>
      <button type="button" onClick={onUpdate}>
        Update context
      </button>
    </div>
  );
}

export default YourComponent;
```

Rendering the provider with a different `context` prop updates the context the same way.

A context given while the page first renders goes out with the first connection, whether it comes from the provider's `context` prop or from an `updateContext` call in an effect that runs when a component mounts: the browser connects once the page's first render and its effects are done. `updateContext` is the same function on every render, so it is safe to list in an effect's dependencies. A context equal to the one the provider already has, given through the prop or through `updateContext`, opens no new connection.

On server routes, the context is provided at evaluation time as the third argument to `getValue`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```ts [route.ts]
import { getConfigClient } from "@configdirector/nextjs-sdk/server";

export async function GET() {
  const client = getConfigClient();
  const value = client.getValue("my-config-key", false, {
    id: "654321",
    name: "Another User",
    traits: {
      region: "Australia",
    },
  });
  return Response.json({ "my-config-key": value });
}
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`. It works the same in `updateContext` and in `getValue`:

```ts [route.ts]
const value = client.getValue("my-config-key", false, {
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.10.0 of the SDK.

</template>

<template v-slot:nuxt="">

The context can be updated via the `useConfigDirectorContext` composable:

```vue [YourComponent.vue]
<script setup lang="ts">
const { updateContext } = useConfigDirectorContext();
const { value } = useConfigDirectorValue("my-config-key", false);

const onUpdate = () => {
  updateContext({
    id: "654321",
    name: "Another User",
    traits: {
      region: "Australia",
    },
  });
};
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
  <button type="button" @click="onUpdate">Update Context</button>
</template>
```

On server resource handlers, the context is provided at evaluation time as the third argument to `getValue`. Unlike client SDKs, the server SDKs are able to evaluate targeting rules for the given context locally without additional network calls.

```ts [server-resource.get.ts]
export default defineEventHandler(async (_event) => {
  const client = useConfigDirectorServerClient();
  return client.getValue("my-config-key", false, {
    id: "654321",
    name: "Another User",
    traits: {
      region: "Australia",
    },
  });
});
```

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with `kind`. It works the same in `updateContext` and in `getValue`:

```ts [server-resource.get.ts]
return client.getValue("my-config-key", false, {
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});
```

Leaving `kind` out means `user`. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.10.0 of the SDK.

</template>
</sdk-tabs>

1. You can now configure targeting rules by navigating to your config in the dashboard. Targeting rules are the very first tab on the config view:

![Targeting rules example](https://docs.configdirector.com/img/screenshots/targeting-rules-sample.webp)

## Next steps

Prefer to manage projects, configs, targeting rules, and segments as code, or from an AI coding assistant? See the [Terraform provider](https://docs.configdirector.com/integrations/terraform) and the [MCP server](https://docs.configdirector.com/integrations/mcp).


## Sitemap

See the full [sitemap](https://docs.configdirector.com/sitemap.md) for all pages.
