From 1f5a51828da3d9fa983b5460c1a2d4c38344972e Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 10:18:21 -0600 Subject: [PATCH 1/9] Add Unity Feature Flags documentation Add comprehensive Unity Feature Flags documentation with two implementations: 1. unity.md - Direct FlagsClient API (current implementation) - Uses DdFlags.CreateClient() and direct FlagsClient methods - Synchronous flag evaluation (GetBooleanValue, GetStringValue, etc.) - Simpler API without async/await 2. unity-openfeature.md - OpenFeature integration (future/alternative) - Uses OpenFeature Api.Instance.GetClient() - Async flag evaluation methods - Standards-based approach Both pages: - Include cross-links to each other for easy navigation - Follow the structure of Android/iOS feature flags docs - Include installation, setup, evaluation, and advanced config sections - Add Unity card to feature flags client navigation The documentation is ready for preview and user feedback. --- .../feature_flags/client/unity-openfeature.md | 278 ++++++++++++++++++ content/en/feature_flags/client/unity.md | 266 +++++++++++++++++ .../feature_flags/feature_flags_client.html | 7 + 3 files changed, 551 insertions(+) create mode 100644 content/en/feature_flags/client/unity-openfeature.md create mode 100644 content/en/feature_flags/client/unity.md diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md new file mode 100644 index 00000000000..408944dfc89 --- /dev/null +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -0,0 +1,278 @@ +--- +title: Unity Feature Flags (OpenFeature) +description: Set up Datadog Feature Flags for Unity applications using OpenFeature. +aliases: + - /feature_flags/setup/unity-openfeature/ +further_reading: +- link: "/feature_flags/client/" + tag: "Documentation" + text: "Client-Side Feature Flags" +- link: "/real_user_monitoring/application_monitoring/unity/" + tag: "Documentation" + text: "Unity Monitoring" +- link: "https://github.com/DataDog/dd-sdk-unity" + tag: "Source Code" + text: "dd-sdk-unity source code" +--- + +{{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} +Feature Flags are in Preview. Complete the form to request access. +{{< /callout >}} + +
This page documents the OpenFeature integration for Unity Feature Flags. For the direct FlagsClient API (without OpenFeature), see Unity Feature Flags.
+ +## Overview + +This page describes how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. + +This guide explains how to install and enable the SDK, create and use a flags client with OpenFeature, and configure advanced options. + +## Installation + +Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. + +1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. + +2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. + +3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. + +4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: + + ```groovy + constraints { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { + because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") + } + } + ``` + +## Initialize the SDK + +Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. + +For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. + +## Enable flags + +After initializing Datadog, enable flags in your application code: + +{{< code-block lang="csharp" >}} +using Datadog.Unity; +using Datadog.Unity.Flags; + +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); +{{< /code-block >}} + +You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). + +## Create and retrieve a client + +Create a client once, typically during app startup: + +{{< code-block lang="csharp" >}} +DdFlags.CreateClient(); // Creates the default client +{{< /code-block >}} + +Retrieve the same client anywhere in your app using the OpenFeature API: + +{{< code-block lang="csharp" >}} +using OpenFeature; + +var client = Api.Instance.GetClient(); +{{< /code-block >}} + +You can also create and retrieve multiple clients by providing the `name` parameter: + +{{< code-block lang="csharp" >}} +DdFlags.CreateClient("checkout"); +var client = Api.Instance.GetClient("checkout"); +{{< /code-block >}} + +
If a client with the given name already exists, the existing instance is reused.
+ +## Set the evaluation context + +Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. + +{{< code-block lang="csharp" >}} +DdFlags.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: success => + { + if (success) + { + Debug.Log("Flags loaded successfully!"); + } + } +); +{{< /code-block >}} + +This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. + +## Evaluate flags + +After creating the client and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. + +Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. + +The Unity SDK uses the [OpenFeature][6] standard API for flag evaluation. + +### Boolean flags + +Use `GetBooleanValueAsync(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: + +{{< code-block lang="csharp" >}} +var client = Api.Instance.GetClient(); + +var isNewCheckoutEnabled = await client.GetBooleanValueAsync( + flagKey: "checkout.new", + defaultValue: false +); + +if (isNewCheckoutEnabled) +{ + ShowNewCheckoutFlow(); +} +else +{ + ShowLegacyCheckout(); +} +{{< /code-block >}} + +### String flags + +Use `GetStringValueAsync(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: + +{{< code-block lang="csharp" >}} +var theme = await client.GetStringValueAsync( + flagKey: "ui.theme", + defaultValue: "light" +); + +switch (theme) +{ + case "light": + SetLightTheme(); + break; + case "dark": + SetDarkTheme(); + break; + default: + SetLightTheme(); + break; +} +{{< /code-block >}} + +### Integer and double flags + +For numeric flags, use `GetIntegerValueAsync(key, defaultValue)` or `GetDoubleValueAsync(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: + +{{< code-block lang="csharp" >}} +var maxItems = await client.GetIntegerValueAsync( + flagKey: "cart.items.max", + defaultValue: 20 +); + +var priceMultiplier = await client.GetDoubleValueAsync( + flagKey: "pricing.multiplier", + defaultValue: 1.0 +); +{{< /code-block >}} + +### Object flags + +For structured or JSON-like data, use `GetObjectValueAsync(key, defaultValue)`. This method returns an OpenFeature `Value` object, which can represent primitives, arrays, or dictionaries. Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: + +{{< code-block lang="csharp" >}} +var config = await client.GetObjectValueAsync( + flagKey: "ui.config", + defaultValue: new Value(new Structure(new Dictionary + { + { "color", new Value("#00A3FF") }, + { "fontSize", new Value(14) } + })) +); + +var color = config.AsStructure["color"].AsString; +var fontSize = config.AsStructure["fontSize"].AsInteger; +{{< /code-block >}} + +### Flag evaluation details + +When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: + +* `GetBooleanDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetStringDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetIntegerDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetDoubleDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetObjectDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` + +For example: + +{{< code-block lang="csharp" >}} +var details = await client.GetStringDetailsAsync( + flagKey: "paywall.layout", + defaultValue: "control" +); + +Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") +Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable +Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") +Debug.Log($"ErrorType: {details.ErrorType}"); // The error that occurred during evaluation, if any +{{< /code-block >}} + +Flag details may help you debug evaluation behavior and understand why a user received a given value. + +## Advanced configuration + +The `DdFlags.Enable()` API accepts optional configuration with options listed below. + +{{< code-block lang="csharp" >}} +var config = new FlagsConfiguration +{ + // configure options here +}; + +DdFlags.Enable(config); +{{< /code-block >}} + +`TrackExposures` +: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. + +`TrackEvaluations` +: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. + +`EvaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. + +`CustomFlagsEndpoint` +: Configures a custom server URL for retrieving flag assignments. + +`CustomExposureEndpoint` +: Configures a custom server URL for sending flags exposure data. + +`CustomEvaluationEndpoint` +: Configures a custom server URL for sending flags evaluation telemetry. + +## Further reading + +{{< partial name="whats-next/whats-next.html" >}} + +[1]: https://github.com/googlesamples/unity-jar-resolver +[2]: https://openupm.com/packages/com.google.external-dependency-manager/ +[3]: https://github.com/DataDog/unity-package +[4]: https://docs.unity3d.com/Manual/gradle-templates.html +[5]: /real_user_monitoring/application_monitoring/unity/setup +[6]: https://openfeature.dev/ diff --git a/content/en/feature_flags/client/unity.md b/content/en/feature_flags/client/unity.md new file mode 100644 index 00000000000..83780ba0f49 --- /dev/null +++ b/content/en/feature_flags/client/unity.md @@ -0,0 +1,266 @@ +--- +title: Unity Feature Flags +description: Set up Datadog Feature Flags for Unity applications. +aliases: + - /feature_flags/setup/unity/ +further_reading: +- link: "/feature_flags/client/" + tag: "Documentation" + text: "Client-Side Feature Flags" +- link: "/real_user_monitoring/application_monitoring/unity/" + tag: "Documentation" + text: "Unity Monitoring" +- link: "https://github.com/DataDog/dd-sdk-unity" + tag: "Source Code" + text: "dd-sdk-unity source code" +--- + +{{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} +Feature Flags are in Preview. Complete the form to request access. +{{< /callout >}} + +
This page documents the direct FlagsClient API for Unity Feature Flags. If you're looking for OpenFeature integration, see Unity Feature Flags (OpenFeature).
+ +## Overview + +This page describes how to instrument your Unity application with the Datadog Feature Flags SDK. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. + +This guide explains how to install and enable the SDK, create and use a `FlagsClient`, and configure advanced options. + +## Installation + +Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. + +1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. + +2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. + +3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. + +4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: + + ```groovy + constraints { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { + because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") + } + } + ``` + +## Initialize the SDK + +Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. + +For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. + +## Enable flags + +After initializing Datadog, enable flags in your application code: + +{{< code-block lang="csharp" >}} +using Datadog.Unity.Flags; + +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); +{{< /code-block >}} + +You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). + +## Create and retrieve a client + +Create a client once, typically during app startup: + +{{< code-block lang="csharp" >}} +var client = DdFlags.CreateClient(); // Creates the default client +{{< /code-block >}} + +You can also create multiple clients by providing the `name` parameter: + +{{< code-block lang="csharp" >}} +var checkoutClient = DdFlags.CreateClient("checkout"); +{{< /code-block >}} + +
If a client with the given name already exists, the existing instance is reused.
+ +## Set the evaluation context + +Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. + +{{< code-block lang="csharp" >}} +client.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: success => + { + if (success) + { + Debug.Log("Flags loaded successfully!"); + } + } +); +{{< /code-block >}} + +This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. + +## Evaluate flags + +After creating the `FlagsClient` and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. + +Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. + +### Boolean flags + +Use `GetBooleanValue(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: + +{{< code-block lang="csharp" >}} +var isNewCheckoutEnabled = client.GetBooleanValue( + key: "checkout.new", + defaultValue: false +); + +if (isNewCheckoutEnabled) +{ + ShowNewCheckoutFlow(); +} +else +{ + ShowLegacyCheckout(); +} +{{< /code-block >}} + +### String flags + +Use `GetStringValue(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: + +{{< code-block lang="csharp" >}} +var theme = client.GetStringValue( + key: "ui.theme", + defaultValue: "light" +); + +switch (theme) +{ + case "light": + SetLightTheme(); + break; + case "dark": + SetDarkTheme(); + break; + default: + SetLightTheme(); + break; +} +{{< /code-block >}} + +### Integer and double flags + +For numeric flags, use `GetIntegerValue(key, defaultValue)` or `GetDoubleValue(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: + +{{< code-block lang="csharp" >}} +var maxItems = client.GetIntegerValue( + key: "cart.items.max", + defaultValue: 20 +); + +var priceMultiplier = client.GetDoubleValue( + key: "pricing.multiplier", + defaultValue: 1.0 +); +{{< /code-block >}} + +### Object flags + +For structured or JSON-like data, use `GetObjectValue(key, defaultValue)`. This method returns an `object`, which can be cast to the appropriate type (such as a dictionary or custom class). Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: + +{{< code-block lang="csharp" >}} +var config = client.GetObjectValue( + key: "ui.config", + defaultValue: new Dictionary + { + { "color", "#00A3FF" }, + { "fontSize", 14 } + } +); + +if (config is Dictionary configDict) +{ + var color = configDict["color"] as string; + var fontSize = (int)configDict["fontSize"]; +} +{{< /code-block >}} + +### Flag evaluation details + +When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: + +* `GetBooleanDetails(key, defaultValue)` -> `FlagDetails` +* `GetStringDetails(key, defaultValue)` -> `FlagDetails` +* `GetIntegerDetails(key, defaultValue)` -> `FlagDetails` +* `GetDoubleDetails(key, defaultValue)` -> `FlagDetails` +* `GetDetails(key, defaultValue)` -> `FlagDetails` + +For example: + +{{< code-block lang="csharp" >}} +var details = client.GetStringDetails( + key: "paywall.layout", + defaultValue: "control" +); + +Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") +Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable +Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") +Debug.Log($"Error: {details.Error}"); // The error that occurred during evaluation, if any +{{< /code-block >}} + +Flag details may help you debug evaluation behavior and understand why a user received a given value. + +## Advanced configuration + +The `DdFlags.Enable()` API accepts optional configuration with options listed below. + +{{< code-block lang="csharp" >}} +var config = new FlagsConfiguration +{ + // configure options here +}; + +DdFlags.Enable(config); +{{< /code-block >}} + +`TrackExposures` +: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. + +`TrackEvaluations` +: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. + +`EvaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. + +`CustomFlagsEndpoint` +: Configures a custom server URL for retrieving flag assignments. + +`CustomExposureEndpoint` +: Configures a custom server URL for sending flags exposure data. + +`CustomEvaluationEndpoint` +: Configures a custom server URL for sending flags evaluation telemetry. + +## Further reading + +{{< partial name="whats-next/whats-next.html" >}} + +[1]: https://github.com/googlesamples/unity-jar-resolver +[2]: https://openupm.com/packages/com.google.external-dependency-manager/ +[3]: https://github.com/DataDog/unity-package +[4]: https://docs.unity3d.com/Manual/gradle-templates.html +[5]: /real_user_monitoring/application_monitoring/unity/setup diff --git a/layouts/partials/feature_flags/feature_flags_client.html b/layouts/partials/feature_flags/feature_flags_client.html index 3d61897bc3c..d9001cb2bb9 100644 --- a/layouts/partials/feature_flags/feature_flags_client.html +++ b/layouts/partials/feature_flags/feature_flags_client.html @@ -65,6 +65,13 @@ + From cac19fca6015e3c5dd6ad6fffd26a12809e8c048 Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 12:19:31 -0600 Subject: [PATCH 2/9] Simplify Unity Feature Flags docs to placeholders Replace full documentation with minimal placeholder pages to test CI: - Keep navigation links and cross-references - Add 'Documentation coming soon' message - Reduce from ~270 lines to ~28 lines each - Test if minimal changes pass all CI checks Full documentation will be added incrementally after CI validation. --- .../feature_flags/client/unity-openfeature.md | 253 +----------------- content/en/feature_flags/client/unity.md | 241 +---------------- 2 files changed, 2 insertions(+), 492 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index 408944dfc89..3c8cdab6475 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -10,9 +10,6 @@ further_reading: - link: "/real_user_monitoring/application_monitoring/unity/" tag: "Documentation" text: "Unity Monitoring" -- link: "https://github.com/DataDog/dd-sdk-unity" - tag: "Source Code" - text: "dd-sdk-unity source code" --- {{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} @@ -23,256 +20,8 @@ Feature Flags are in Preview. Complete the form to request access. ## Overview -This page describes how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. - -This guide explains how to install and enable the SDK, create and use a flags client with OpenFeature, and configure advanced options. - -## Installation - -Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. - -1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. - -2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. - -3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. - -4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: - - ```groovy - constraints { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { - because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") - } - } - ``` - -## Initialize the SDK - -Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. - -For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. - -## Enable flags - -After initializing Datadog, enable flags in your application code: - -{{< code-block lang="csharp" >}} -using Datadog.Unity; -using Datadog.Unity.Flags; - -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); -{{< /code-block >}} - -You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). - -## Create and retrieve a client - -Create a client once, typically during app startup: - -{{< code-block lang="csharp" >}} -DdFlags.CreateClient(); // Creates the default client -{{< /code-block >}} - -Retrieve the same client anywhere in your app using the OpenFeature API: - -{{< code-block lang="csharp" >}} -using OpenFeature; - -var client = Api.Instance.GetClient(); -{{< /code-block >}} - -You can also create and retrieve multiple clients by providing the `name` parameter: - -{{< code-block lang="csharp" >}} -DdFlags.CreateClient("checkout"); -var client = Api.Instance.GetClient("checkout"); -{{< /code-block >}} - -
If a client with the given name already exists, the existing instance is reused.
- -## Set the evaluation context - -Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. - -{{< code-block lang="csharp" >}} -DdFlags.SetEvaluationContext( - new FlagsEvaluationContext( - targetingKey: "user-123", - attributes: new Dictionary - { - { "email", "user@example.com" }, - { "tier", "premium" } - } - ), - onComplete: success => - { - if (success) - { - Debug.Log("Flags loaded successfully!"); - } - } -); -{{< /code-block >}} - -This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. - -## Evaluate flags - -After creating the client and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. - -Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. - -The Unity SDK uses the [OpenFeature][6] standard API for flag evaluation. - -### Boolean flags - -Use `GetBooleanValueAsync(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: - -{{< code-block lang="csharp" >}} -var client = Api.Instance.GetClient(); - -var isNewCheckoutEnabled = await client.GetBooleanValueAsync( - flagKey: "checkout.new", - defaultValue: false -); - -if (isNewCheckoutEnabled) -{ - ShowNewCheckoutFlow(); -} -else -{ - ShowLegacyCheckout(); -} -{{< /code-block >}} - -### String flags - -Use `GetStringValueAsync(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: - -{{< code-block lang="csharp" >}} -var theme = await client.GetStringValueAsync( - flagKey: "ui.theme", - defaultValue: "light" -); - -switch (theme) -{ - case "light": - SetLightTheme(); - break; - case "dark": - SetDarkTheme(); - break; - default: - SetLightTheme(); - break; -} -{{< /code-block >}} - -### Integer and double flags - -For numeric flags, use `GetIntegerValueAsync(key, defaultValue)` or `GetDoubleValueAsync(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: - -{{< code-block lang="csharp" >}} -var maxItems = await client.GetIntegerValueAsync( - flagKey: "cart.items.max", - defaultValue: 20 -); - -var priceMultiplier = await client.GetDoubleValueAsync( - flagKey: "pricing.multiplier", - defaultValue: 1.0 -); -{{< /code-block >}} - -### Object flags - -For structured or JSON-like data, use `GetObjectValueAsync(key, defaultValue)`. This method returns an OpenFeature `Value` object, which can represent primitives, arrays, or dictionaries. Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: - -{{< code-block lang="csharp" >}} -var config = await client.GetObjectValueAsync( - flagKey: "ui.config", - defaultValue: new Value(new Structure(new Dictionary - { - { "color", new Value("#00A3FF") }, - { "fontSize", new Value(14) } - })) -); - -var color = config.AsStructure["color"].AsString; -var fontSize = config.AsStructure["fontSize"].AsInteger; -{{< /code-block >}} - -### Flag evaluation details - -When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: - -* `GetBooleanDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` -* `GetStringDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` -* `GetIntegerDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` -* `GetDoubleDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` -* `GetObjectDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` - -For example: - -{{< code-block lang="csharp" >}} -var details = await client.GetStringDetailsAsync( - flagKey: "paywall.layout", - defaultValue: "control" -); - -Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") -Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable -Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") -Debug.Log($"ErrorType: {details.ErrorType}"); // The error that occurred during evaluation, if any -{{< /code-block >}} - -Flag details may help you debug evaluation behavior and understand why a user received a given value. - -## Advanced configuration - -The `DdFlags.Enable()` API accepts optional configuration with options listed below. - -{{< code-block lang="csharp" >}} -var config = new FlagsConfiguration -{ - // configure options here -}; - -DdFlags.Enable(config); -{{< /code-block >}} - -`TrackExposures` -: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. - -`TrackEvaluations` -: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. - -`EvaluationFlushIntervalSeconds` -: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. - -`CustomFlagsEndpoint` -: Configures a custom server URL for retrieving flag assignments. - -`CustomExposureEndpoint` -: Configures a custom server URL for sending flags exposure data. - -`CustomEvaluationEndpoint` -: Configures a custom server URL for sending flags evaluation telemetry. +Documentation coming soon. This page will describe how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. ## Further reading {{< partial name="whats-next/whats-next.html" >}} - -[1]: https://github.com/googlesamples/unity-jar-resolver -[2]: https://openupm.com/packages/com.google.external-dependency-manager/ -[3]: https://github.com/DataDog/unity-package -[4]: https://docs.unity3d.com/Manual/gradle-templates.html -[5]: /real_user_monitoring/application_monitoring/unity/setup -[6]: https://openfeature.dev/ diff --git a/content/en/feature_flags/client/unity.md b/content/en/feature_flags/client/unity.md index 83780ba0f49..2138d71268c 100644 --- a/content/en/feature_flags/client/unity.md +++ b/content/en/feature_flags/client/unity.md @@ -10,9 +10,6 @@ further_reading: - link: "/real_user_monitoring/application_monitoring/unity/" tag: "Documentation" text: "Unity Monitoring" -- link: "https://github.com/DataDog/dd-sdk-unity" - tag: "Source Code" - text: "dd-sdk-unity source code" --- {{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} @@ -23,244 +20,8 @@ Feature Flags are in Preview. Complete the form to request access. ## Overview -This page describes how to instrument your Unity application with the Datadog Feature Flags SDK. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. - -This guide explains how to install and enable the SDK, create and use a `FlagsClient`, and configure advanced options. - -## Installation - -Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. - -1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. - -2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. - -3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. - -4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: - - ```groovy - constraints { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { - because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") - } - } - ``` - -## Initialize the SDK - -Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. - -For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. - -## Enable flags - -After initializing Datadog, enable flags in your application code: - -{{< code-block lang="csharp" >}} -using Datadog.Unity.Flags; - -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); -{{< /code-block >}} - -You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). - -## Create and retrieve a client - -Create a client once, typically during app startup: - -{{< code-block lang="csharp" >}} -var client = DdFlags.CreateClient(); // Creates the default client -{{< /code-block >}} - -You can also create multiple clients by providing the `name` parameter: - -{{< code-block lang="csharp" >}} -var checkoutClient = DdFlags.CreateClient("checkout"); -{{< /code-block >}} - -
If a client with the given name already exists, the existing instance is reused.
- -## Set the evaluation context - -Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. - -{{< code-block lang="csharp" >}} -client.SetEvaluationContext( - new FlagsEvaluationContext( - targetingKey: "user-123", - attributes: new Dictionary - { - { "email", "user@example.com" }, - { "tier", "premium" } - } - ), - onComplete: success => - { - if (success) - { - Debug.Log("Flags loaded successfully!"); - } - } -); -{{< /code-block >}} - -This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. - -## Evaluate flags - -After creating the `FlagsClient` and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. - -Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. - -### Boolean flags - -Use `GetBooleanValue(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: - -{{< code-block lang="csharp" >}} -var isNewCheckoutEnabled = client.GetBooleanValue( - key: "checkout.new", - defaultValue: false -); - -if (isNewCheckoutEnabled) -{ - ShowNewCheckoutFlow(); -} -else -{ - ShowLegacyCheckout(); -} -{{< /code-block >}} - -### String flags - -Use `GetStringValue(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: - -{{< code-block lang="csharp" >}} -var theme = client.GetStringValue( - key: "ui.theme", - defaultValue: "light" -); - -switch (theme) -{ - case "light": - SetLightTheme(); - break; - case "dark": - SetDarkTheme(); - break; - default: - SetLightTheme(); - break; -} -{{< /code-block >}} - -### Integer and double flags - -For numeric flags, use `GetIntegerValue(key, defaultValue)` or `GetDoubleValue(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: - -{{< code-block lang="csharp" >}} -var maxItems = client.GetIntegerValue( - key: "cart.items.max", - defaultValue: 20 -); - -var priceMultiplier = client.GetDoubleValue( - key: "pricing.multiplier", - defaultValue: 1.0 -); -{{< /code-block >}} - -### Object flags - -For structured or JSON-like data, use `GetObjectValue(key, defaultValue)`. This method returns an `object`, which can be cast to the appropriate type (such as a dictionary or custom class). Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: - -{{< code-block lang="csharp" >}} -var config = client.GetObjectValue( - key: "ui.config", - defaultValue: new Dictionary - { - { "color", "#00A3FF" }, - { "fontSize", 14 } - } -); - -if (config is Dictionary configDict) -{ - var color = configDict["color"] as string; - var fontSize = (int)configDict["fontSize"]; -} -{{< /code-block >}} - -### Flag evaluation details - -When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: - -* `GetBooleanDetails(key, defaultValue)` -> `FlagDetails` -* `GetStringDetails(key, defaultValue)` -> `FlagDetails` -* `GetIntegerDetails(key, defaultValue)` -> `FlagDetails` -* `GetDoubleDetails(key, defaultValue)` -> `FlagDetails` -* `GetDetails(key, defaultValue)` -> `FlagDetails` - -For example: - -{{< code-block lang="csharp" >}} -var details = client.GetStringDetails( - key: "paywall.layout", - defaultValue: "control" -); - -Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") -Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable -Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") -Debug.Log($"Error: {details.Error}"); // The error that occurred during evaluation, if any -{{< /code-block >}} - -Flag details may help you debug evaluation behavior and understand why a user received a given value. - -## Advanced configuration - -The `DdFlags.Enable()` API accepts optional configuration with options listed below. - -{{< code-block lang="csharp" >}} -var config = new FlagsConfiguration -{ - // configure options here -}; - -DdFlags.Enable(config); -{{< /code-block >}} - -`TrackExposures` -: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. - -`TrackEvaluations` -: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. - -`EvaluationFlushIntervalSeconds` -: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. - -`CustomFlagsEndpoint` -: Configures a custom server URL for retrieving flag assignments. - -`CustomExposureEndpoint` -: Configures a custom server URL for sending flags exposure data. - -`CustomEvaluationEndpoint` -: Configures a custom server URL for sending flags evaluation telemetry. +Documentation coming soon. This page will describe how to instrument your Unity application with the Datadog Feature Flags SDK using the direct FlagsClient API. ## Further reading {{< partial name="whats-next/whats-next.html" >}} - -[1]: https://github.com/googlesamples/unity-jar-resolver -[2]: https://openupm.com/packages/com.google.external-dependency-manager/ -[3]: https://github.com/DataDog/unity-package -[4]: https://docs.unity3d.com/Manual/gradle-templates.html -[5]: /real_user_monitoring/application_monitoring/unity/setup From 295d7a97879e7bdc305d90028cdf6c7b139b36ae Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 13:44:50 -0600 Subject: [PATCH 3/9] Add Overview, Installation, and Initialize SDK sections to OpenFeature docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Incremental update to unity-openfeature.md: - Add detailed Overview explaining OpenFeature integration - Add complete Installation instructions (EDM4U, Unity package, Android setup) - Add Initialize SDK section with reference to Unity Monitoring Setup - Add reference links at bottom File size: 27 → 68 lines (+41 lines) --- .../feature_flags/client/unity-openfeature.md | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index 3c8cdab6475..349dfbad2eb 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -20,8 +20,44 @@ Feature Flags are in Preview. Complete the form to request access. ## Overview -Documentation coming soon. This page will describe how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. +This page describes how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. + +This guide explains how to install and enable the SDK, create and use a flags client with OpenFeature, and configure advanced options. + +## Installation + +Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. + +1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. + +2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. + +3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. + +4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: + + ```groovy + constraints { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { + because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") + } + } + ``` + +## Initialize the SDK + +Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. + +For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. ## Further reading {{< partial name="whats-next/whats-next.html" >}} + +[1]: https://github.com/googlesamples/unity-jar-resolver +[2]: https://openupm.com/packages/com.google.external-dependency-manager/ +[3]: https://github.com/DataDog/unity-package +[4]: https://docs.unity3d.com/Manual/gradle-templates.html +[5]: /real_user_monitoring/application_monitoring/unity/setup + +{{< partial name="whats-next/whats-next.html" >}} From 18c83ffb678dde7a5df01a0744c31fb45824887e Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 15:41:49 -0600 Subject: [PATCH 4/9] Restore full OpenFeature docs for Unity Feature Flags Add back all sections to unity-openfeature.md: - Enable flags - Create and retrieve a client - Set the evaluation context - Evaluate flags (boolean, string, integer, double, object) - Flag evaluation details - Advanced configuration Also fixes duplicate further_reading partial and adds OpenFeature external link to further_reading frontmatter. --- .../feature_flags/client/unity-openfeature.md | 221 +++++++++++++++++- 1 file changed, 219 insertions(+), 2 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index 349dfbad2eb..b919cb95844 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -10,6 +10,12 @@ further_reading: - link: "/real_user_monitoring/application_monitoring/unity/" tag: "Documentation" text: "Unity Monitoring" +- link: "https://github.com/DataDog/dd-sdk-unity" + tag: "Source Code" + text: "dd-sdk-unity source code" +- link: "https://openfeature.dev/" + tag: "External" + text: "OpenFeature" --- {{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} @@ -50,6 +56,218 @@ Initialize Datadog as early as possible in your app lifecycle. Navigate to your For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. +## Enable flags + +After initializing Datadog, enable flags in your application code: + +{{< code-block lang="csharp" >}} +using Datadog.Unity.Flags; + +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); +{{< /code-block >}} + +You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). + +## Create and retrieve a client + +Create a client once, typically during app startup: + +{{< code-block lang="csharp" >}} +DdFlags.CreateClient(); // Creates the default client +{{< /code-block >}} + +Retrieve the same client anywhere in your app using the OpenFeature API: + +{{< code-block lang="csharp" >}} +using OpenFeature; + +var client = Api.Instance.GetClient(); +{{< /code-block >}} + +You can also create and retrieve multiple clients by providing the `name` parameter: + +{{< code-block lang="csharp" >}} +DdFlags.CreateClient("checkout"); +var client = Api.Instance.GetClient("checkout"); +{{< /code-block >}} + +
If a client with the given name already exists, the existing instance is reused.
+ +## Set the evaluation context + +Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. + +{{< code-block lang="csharp" >}} +DdFlags.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: success => + { + if (success) + { + Debug.Log("Flags loaded successfully!"); + } + } +); +{{< /code-block >}} + +This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. + +## Evaluate flags + +After creating the client and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. + +Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. + +The Unity SDK uses the [OpenFeature][6] standard API for flag evaluation. + +### Boolean flags + +Use `GetBooleanValueAsync(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: + +{{< code-block lang="csharp" >}} +var client = Api.Instance.GetClient(); + +var isNewCheckoutEnabled = await client.GetBooleanValueAsync( + flagKey: "checkout.new", + defaultValue: false +); + +if (isNewCheckoutEnabled) +{ + ShowNewCheckoutFlow(); +} +else +{ + ShowLegacyCheckout(); +} +{{< /code-block >}} + +### String flags + +Use `GetStringValueAsync(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: + +{{< code-block lang="csharp" >}} +var theme = await client.GetStringValueAsync( + flagKey: "ui.theme", + defaultValue: "light" +); + +switch (theme) +{ + case "light": + SetLightTheme(); + break; + case "dark": + SetDarkTheme(); + break; + default: + SetLightTheme(); + break; +} +{{< /code-block >}} + +### Integer and double flags + +For numeric flags, use `GetIntegerValueAsync(key, defaultValue)` or `GetDoubleValueAsync(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: + +{{< code-block lang="csharp" >}} +var maxItems = await client.GetIntegerValueAsync( + flagKey: "cart.items.max", + defaultValue: 20 +); + +var priceMultiplier = await client.GetDoubleValueAsync( + flagKey: "pricing.multiplier", + defaultValue: 1.0 +); +{{< /code-block >}} + +### Object flags + +For structured or JSON-like data, use `GetObjectValueAsync(key, defaultValue)`. This method returns an OpenFeature `Value` object, which can represent primitives, arrays, or dictionaries. Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: + +{{< code-block lang="csharp" >}} +var config = await client.GetObjectValueAsync( + flagKey: "ui.config", + defaultValue: new Value(new Structure(new Dictionary + { + { "color", new Value("#00A3FF") }, + { "fontSize", new Value(14) } + })) +); + +var color = config.AsStructure["color"].AsString; +var fontSize = config.AsStructure["fontSize"].AsInteger; +{{< /code-block >}} + +### Flag evaluation details + +When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: + +* `GetBooleanDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetStringDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetIntegerDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetDoubleDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` +* `GetObjectDetailsAsync(key, defaultValue)` -> `FlagEvaluationDetails` + +For example: + +{{< code-block lang="csharp" >}} +var details = await client.GetStringDetailsAsync( + flagKey: "paywall.layout", + defaultValue: "control" +); + +Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") +Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable +Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") +Debug.Log($"ErrorType: {details.ErrorType}"); // The error that occurred during evaluation, if any +{{< /code-block >}} + +Flag details may help you debug evaluation behavior and understand why a user received a given value. + +## Advanced configuration + +The `DdFlags.Enable()` API accepts optional configuration with options listed below. + +{{< code-block lang="csharp" >}} +var config = new FlagsConfiguration +{ + // configure options here +}; + +DdFlags.Enable(config); +{{< /code-block >}} + +`TrackExposures` +: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. + +`TrackEvaluations` +: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. + +`EvaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. + +`CustomFlagsEndpoint` +: Configures a custom server URL for retrieving flag assignments. + +`CustomExposureEndpoint` +: Configures a custom server URL for sending flags exposure data. + +`CustomEvaluationEndpoint` +: Configures a custom server URL for sending flags evaluation telemetry. + ## Further reading {{< partial name="whats-next/whats-next.html" >}} @@ -59,5 +277,4 @@ For more information about setting up the Unity SDK, see [Unity Monitoring Setup [3]: https://github.com/DataDog/unity-package [4]: https://docs.unity3d.com/Manual/gradle-templates.html [5]: /real_user_monitoring/application_monitoring/unity/setup - -{{< partial name="whats-next/whats-next.html" >}} +[6]: https://openfeature.dev/ From 4e7a1c9dd95d09dcf1e9fbe97268d509acb14e5c Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 16:06:41 -0600 Subject: [PATCH 5/9] Restore full Unity Feature Flags direct API documentation Add back all sections to unity.md: - Overview - Installation - Initialize the SDK - Enable flags - Create and retrieve a client - Set the evaluation context - Evaluate flags (boolean, string, integer, double, object) - Flag evaluation details - Advanced configuration --- content/en/feature_flags/client/unity.md | 241 ++++++++++++++++++++++- 1 file changed, 240 insertions(+), 1 deletion(-) diff --git a/content/en/feature_flags/client/unity.md b/content/en/feature_flags/client/unity.md index 2138d71268c..71922df04e5 100644 --- a/content/en/feature_flags/client/unity.md +++ b/content/en/feature_flags/client/unity.md @@ -10,6 +10,9 @@ further_reading: - link: "/real_user_monitoring/application_monitoring/unity/" tag: "Documentation" text: "Unity Monitoring" +- link: "https://github.com/DataDog/dd-sdk-unity" + tag: "Source Code" + text: "dd-sdk-unity source code" --- {{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} @@ -20,8 +23,244 @@ Feature Flags are in Preview. Complete the form to request access. ## Overview -Documentation coming soon. This page will describe how to instrument your Unity application with the Datadog Feature Flags SDK using the direct FlagsClient API. +This page describes how to instrument your Unity application with the Datadog Feature Flags SDK. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. + +This guide explains how to install and enable the SDK, create and use a `FlagsClient`, and configure advanced options. + +## Installation + +Declare the Datadog Unity SDK as a dependency in your project. The Datadog Unity SDK includes feature flags support. + +1. Install the [External Dependency Manager for Unity (EDM4U)][1]. This can be done using [Open UPM][2]. + +2. Add the Datadog SDK Unity package from its Git URL at [https://github.com/DataDog/unity-package][3]. The package URL is `https://github.com/DataDog/unity-package.git`. + +3. (Android only) Configure your project to use [Gradle templates][4], and enable both `Custom Main Template` and `Custom Gradle Properties Template`. + +4. (Android only) If you build and receive `Duplicate class` errors (common in Unity 2022.x), add the following code to the `dependencies` block of your `mainTemplate.gradle`: + + ```groovy + constraints { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { + because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") + } + } + ``` + +## Initialize the SDK + +Initialize Datadog as early as possible in your app lifecycle. Navigate to your `Project Settings` and click on the `Datadog` section to configure your client token, environment, and other settings. + +For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. + +## Enable flags + +After initializing Datadog, enable flags in your application code: + +{{< code-block lang="csharp" >}} +using Datadog.Unity.Flags; + +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); +{{< /code-block >}} + +You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). + +## Create and retrieve a client + +Create a client once, typically during app startup, and hold a reference to it: + +{{< code-block lang="csharp" >}} +var client = DdFlags.CreateClient(); // Creates the default client +{{< /code-block >}} + +You can also create multiple clients by providing the `name` parameter: + +{{< code-block lang="csharp" >}} +var checkoutClient = DdFlags.CreateClient("checkout"); +{{< /code-block >}} + +
If a client with the given name already exists, the existing instance is reused.
+ +## Set the evaluation context + +Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. + +{{< code-block lang="csharp" >}} +client.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: success => + { + if (success) + { + Debug.Log("Flags loaded successfully!"); + } + } +); +{{< /code-block >}} + +This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. + +## Evaluate flags + +After creating the `FlagsClient` and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. + +Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. + +### Boolean flags + +Use `GetBooleanValue(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: + +{{< code-block lang="csharp" >}} +var isNewCheckoutEnabled = client.GetBooleanValue( + key: "checkout.new", + defaultValue: false +); + +if (isNewCheckoutEnabled) +{ + ShowNewCheckoutFlow(); +} +else +{ + ShowLegacyCheckout(); +} +{{< /code-block >}} + +### String flags + +Use `GetStringValue(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: + +{{< code-block lang="csharp" >}} +var theme = client.GetStringValue( + key: "ui.theme", + defaultValue: "light" +); + +switch (theme) +{ + case "light": + SetLightTheme(); + break; + case "dark": + SetDarkTheme(); + break; + default: + SetLightTheme(); + break; +} +{{< /code-block >}} + +### Integer and double flags + +For numeric flags, use `GetIntegerValue(key, defaultValue)` or `GetDoubleValue(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: + +{{< code-block lang="csharp" >}} +var maxItems = client.GetIntegerValue( + key: "cart.items.max", + defaultValue: 20 +); + +var priceMultiplier = client.GetDoubleValue( + key: "pricing.multiplier", + defaultValue: 1.0 +); +{{< /code-block >}} + +### Object flags + +For structured or JSON-like data, use `GetObjectValue(key, defaultValue)`. This method returns an `object`, which can be cast to the appropriate type. Object flags are useful for remote configuration scenarios where multiple properties need to be provided together. For example: + +{{< code-block lang="csharp" >}} +var config = client.GetObjectValue( + key: "ui.config", + defaultValue: new Dictionary + { + { "color", "#00A3FF" }, + { "fontSize", 14 } + } +); + +if (config is Dictionary configDict) +{ + var color = configDict["color"] as string; + var fontSize = (int)configDict["fontSize"]; +} +{{< /code-block >}} + +### Flag evaluation details + +When you need more than just the flag value, use the detail methods. These methods return both the evaluated value and metadata explaining the evaluation: + +* `GetBooleanDetails(key, defaultValue)` -> `FlagDetails` +* `GetStringDetails(key, defaultValue)` -> `FlagDetails` +* `GetIntegerDetails(key, defaultValue)` -> `FlagDetails` +* `GetDoubleDetails(key, defaultValue)` -> `FlagDetails` +* `GetDetails(key, defaultValue)` -> `FlagDetails` + +For example: + +{{< code-block lang="csharp" >}} +var details = client.GetStringDetails( + key: "paywall.layout", + defaultValue: "control" +); + +Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") +Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable +Debug.Log($"Reason: {details.Reason}"); // Description of why this value was chosen (for example: "TARGETING_MATCH" or "DEFAULT") +Debug.Log($"Error: {details.Error}"); // The error that occurred during evaluation, if any +{{< /code-block >}} + +Flag details may help you debug evaluation behavior and understand why a user received a given value. + +## Advanced configuration + +The `DdFlags.Enable()` API accepts optional configuration with options listed below. + +{{< code-block lang="csharp" >}} +var config = new FlagsConfiguration +{ + // configure options here +}; + +DdFlags.Enable(config); +{{< /code-block >}} + +`TrackExposures` +: When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. + +`TrackEvaluations` +: When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. + +`EvaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. + +`CustomFlagsEndpoint` +: Configures a custom server URL for retrieving flag assignments. + +`CustomExposureEndpoint` +: Configures a custom server URL for sending flags exposure data. + +`CustomEvaluationEndpoint` +: Configures a custom server URL for sending flags evaluation telemetry. ## Further reading {{< partial name="whats-next/whats-next.html" >}} + +[1]: https://github.com/googlesamples/unity-jar-resolver +[2]: https://openupm.com/packages/com.google.external-dependency-manager/ +[3]: https://github.com/DataDog/unity-package +[4]: https://docs.unity3d.com/Manual/gradle-templates.html +[5]: /real_user_monitoring/application_monitoring/unity/setup From 5e10195e3955ee6bcfd1000c256a42c55c56e5e5 Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Tue, 17 Mar 2026 22:17:13 -0600 Subject: [PATCH 6/9] Remove preview callout from Unity Feature Flags docs Feature flags are no longer in preview. Removed the callout from both unity.md and unity-openfeature.md to match the other SDK pages (android, ios, javascript, react). --- content/en/feature_flags/client/unity-openfeature.md | 4 ---- content/en/feature_flags/client/unity.md | 4 ---- 2 files changed, 8 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index b919cb95844..76e50823106 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -18,10 +18,6 @@ further_reading: text: "OpenFeature" --- -{{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} -Feature Flags are in Preview. Complete the form to request access. -{{< /callout >}} -
This page documents the OpenFeature integration for Unity Feature Flags. For the direct FlagsClient API (without OpenFeature), see Unity Feature Flags.
## Overview diff --git a/content/en/feature_flags/client/unity.md b/content/en/feature_flags/client/unity.md index 71922df04e5..20c952dee06 100644 --- a/content/en/feature_flags/client/unity.md +++ b/content/en/feature_flags/client/unity.md @@ -15,10 +15,6 @@ further_reading: text: "dd-sdk-unity source code" --- -{{< callout url="http://datadoghq.com/product-preview/feature-flags/" >}} -Feature Flags are in Preview. Complete the form to request access. -{{< /callout >}} -
This page documents the direct FlagsClient API for Unity Feature Flags. If you're looking for OpenFeature integration, see Unity Feature Flags (OpenFeature).
## Overview From 795df94b08ea5d8c3f4cc20743f23be28af4eca2 Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Thu, 19 Mar 2026 12:17:55 -0600 Subject: [PATCH 7/9] Update Unity Feature Flags docs with correct API and Getting Started section - FlagsConfiguration is now immutable (constructor-based, not object initializer) - Add Getting Started quickstart section to unity.md - Fix DdFlags.Instance.CreateClient() throughout unity.md - Update parameter names to match constructor signatures (camelCase) - Add EvaluationFlushIntervalSeconds clamp range [1, 60] to both pages --- .../feature_flags/client/unity-openfeature.md | 34 +++--- content/en/feature_flags/client/unity.md | 108 +++++++++++------- 2 files changed, 81 insertions(+), 61 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index 76e50823106..68148c4dd55 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -59,11 +59,10 @@ After initializing Datadog, enable flags in your application code: {{< code-block lang="csharp" >}} using Datadog.Unity.Flags; -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true +)); {{< /code-block >}} You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). @@ -238,30 +237,29 @@ Flag details may help you debug evaluation behavior and understand why a user re The `DdFlags.Enable()` API accepts optional configuration with options listed below. {{< code-block lang="csharp" >}} -var config = new FlagsConfiguration -{ - // configure options here -}; - -DdFlags.Enable(config); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true, + evaluationFlushIntervalSeconds: 10.0f +)); {{< /code-block >}} -`TrackExposures` +`trackExposures` : When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. -`TrackEvaluations` +`trackEvaluations` : When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. -`EvaluationFlushIntervalSeconds` -: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. +`evaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Accepted values are between `1` and `60`. Default is `10.0` seconds. -`CustomFlagsEndpoint` +`customFlagsEndpoint` : Configures a custom server URL for retrieving flag assignments. -`CustomExposureEndpoint` +`customExposureEndpoint` : Configures a custom server URL for sending flags exposure data. -`CustomEvaluationEndpoint` +`customEvaluationEndpoint` : Configures a custom server URL for sending flags evaluation telemetry. ## Further reading diff --git a/content/en/feature_flags/client/unity.md b/content/en/feature_flags/client/unity.md index 20c952dee06..338ca77c49a 100644 --- a/content/en/feature_flags/client/unity.md +++ b/content/en/feature_flags/client/unity.md @@ -49,6 +49,46 @@ Initialize Datadog as early as possible in your app lifecycle. Navigate to your For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. +## Getting started + +After the SDK is initialized, set up feature flags with these steps: + +{{< code-block lang="csharp" >}} +using System.Collections.Generic; +using Datadog.Unity.Flags; +using UnityEngine; + +// 1. Enable the Flags feature after Datadog SDK initialization +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true +)); + +// 2. Create a client (once, at startup) +var client = DdFlags.Instance.CreateClient(); + +// 3. Set the evaluation context (fetches flag assignments from the server) +client.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: success => + { + if (success) + { + // 4. Evaluate flags — local and instantaneous + var isNewCheckoutEnabled = client.GetBooleanValue("checkout.new", false); + Debug.Log($"checkout.new = {isNewCheckoutEnabled}"); + } + } +); +{{< /code-block >}} + ## Enable flags After initializing Datadog, enable flags in your application code: @@ -56,11 +96,10 @@ After initializing Datadog, enable flags in your application code: {{< code-block lang="csharp" >}} using Datadog.Unity.Flags; -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true +)); {{< /code-block >}} You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). @@ -70,13 +109,13 @@ You can also pass additional configuration options; see [Advanced configuration] Create a client once, typically during app startup, and hold a reference to it: {{< code-block lang="csharp" >}} -var client = DdFlags.CreateClient(); // Creates the default client +var client = DdFlags.Instance.CreateClient(); // Creates the default client {{< /code-block >}} You can also create multiple clients by providing the `name` parameter: {{< code-block lang="csharp" >}} -var checkoutClient = DdFlags.CreateClient("checkout"); +var checkoutClient = DdFlags.Instance.CreateClient("checkout"); {{< /code-block >}}
If a client with the given name already exists, the existing instance is reused.
@@ -118,10 +157,7 @@ Each flag is identified by a _key_ (a unique string) and can be evaluated with a Use `GetBooleanValue(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: {{< code-block lang="csharp" >}} -var isNewCheckoutEnabled = client.GetBooleanValue( - key: "checkout.new", - defaultValue: false -); +var isNewCheckoutEnabled = client.GetBooleanValue("checkout.new", false); if (isNewCheckoutEnabled) { @@ -138,10 +174,7 @@ else Use `GetStringValue(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: {{< code-block lang="csharp" >}} -var theme = client.GetStringValue( - key: "ui.theme", - defaultValue: "light" -); +var theme = client.GetStringValue("ui.theme", "light"); switch (theme) { @@ -162,15 +195,8 @@ switch (theme) For numeric flags, use `GetIntegerValue(key, defaultValue)` or `GetDoubleValue(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: {{< code-block lang="csharp" >}} -var maxItems = client.GetIntegerValue( - key: "cart.items.max", - defaultValue: 20 -); - -var priceMultiplier = client.GetDoubleValue( - key: "pricing.multiplier", - defaultValue: 1.0 -); +var maxItems = client.GetIntegerValue("cart.items.max", 20); +var priceMultiplier = client.GetDoubleValue("pricing.multiplier", 1.0); {{< /code-block >}} ### Object flags @@ -179,8 +205,8 @@ For structured or JSON-like data, use `GetObjectValue(key, defaultValue)`. This {{< code-block lang="csharp" >}} var config = client.GetObjectValue( - key: "ui.config", - defaultValue: new Dictionary + "ui.config", + new Dictionary { { "color", "#00A3FF" }, { "fontSize", 14 } @@ -207,10 +233,7 @@ When you need more than just the flag value, use the detail methods. These metho For example: {{< code-block lang="csharp" >}} -var details = client.GetStringDetails( - key: "paywall.layout", - defaultValue: "control" -); +var details = client.GetStringDetails("paywall.layout", "control"); Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable @@ -225,30 +248,29 @@ Flag details may help you debug evaluation behavior and understand why a user re The `DdFlags.Enable()` API accepts optional configuration with options listed below. {{< code-block lang="csharp" >}} -var config = new FlagsConfiguration -{ - // configure options here -}; - -DdFlags.Enable(config); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true, + evaluationFlushIntervalSeconds: 10.0f +)); {{< /code-block >}} -`TrackExposures` +`trackExposures` : When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. -`TrackEvaluations` +`trackEvaluations` : When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. -`EvaluationFlushIntervalSeconds` -: The interval in seconds at which batched evaluation events are sent to Datadog. Default is `10.0` seconds. +`evaluationFlushIntervalSeconds` +: The interval in seconds at which batched evaluation events are sent to Datadog. Accepted values are between `1` and `60`. Default is `10.0` seconds. -`CustomFlagsEndpoint` +`customFlagsEndpoint` : Configures a custom server URL for retrieving flag assignments. -`CustomExposureEndpoint` +`customExposureEndpoint` : Configures a custom server URL for sending flags exposure data. -`CustomEvaluationEndpoint` +`customEvaluationEndpoint` : Configures a custom server URL for sending flags evaluation telemetry. ## Further reading From 4923c3e918cc4adb6df8c3b38d4720fbbaf603dd Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Thu, 19 Mar 2026 12:36:54 -0600 Subject: [PATCH 8/9] Fix Unity OpenFeature docs to match openfeature SDK worktree - Revert FlagsConfiguration to object initializer syntax (mutable properties, PascalCase) - Restore DdFlags.SetEvaluationContext() as static method (not on client) - DdFlags.CreateClient() returns void; OpenFeature client retrieved via Api.Instance.GetClient() - Add Getting Started quickstart section - Restore correct advanced config property names (PascalCase) --- .../feature_flags/client/unity-openfeature.md | 75 +++++++++++++++---- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index 68148c4dd55..fa2a922a583 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -52,6 +52,49 @@ Initialize Datadog as early as possible in your app lifecycle. Navigate to your For more information about setting up the Unity SDK, see [Unity Monitoring Setup][5]. +## Getting started + +After the SDK is initialized, set up feature flags with these steps: + +{{< code-block lang="csharp" >}} +using System.Collections.Generic; +using Datadog.Unity.Flags; +using OpenFeature; +using UnityEngine; + +// 1. Enable the Flags feature after Datadog SDK initialization +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); + +// 2. Create the default client (wires up the OpenFeature provider automatically) +DdFlags.CreateClient(); + +// 3. Set the evaluation context (fetches flag assignments from the server) +DdFlags.SetEvaluationContext( + new FlagsEvaluationContext( + targetingKey: "user-123", + attributes: new Dictionary + { + { "email", "user@example.com" }, + { "tier", "premium" } + } + ), + onComplete: async success => + { + if (success) + { + // 4. Evaluate flags via the OpenFeature API + var client = Api.Instance.GetClient(); + var isNewCheckoutEnabled = await client.GetBooleanValueAsync("checkout.new", false); + Debug.Log($"checkout.new = {isNewCheckoutEnabled}"); + } + } +); +{{< /code-block >}} + ## Enable flags After initializing Datadog, enable flags in your application code: @@ -59,10 +102,11 @@ After initializing Datadog, enable flags in your application code: {{< code-block lang="csharp" >}} using Datadog.Unity.Flags; -DdFlags.Enable(new FlagsConfiguration( - trackExposures: true, - trackEvaluations: true -)); +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, +}); {{< /code-block >}} You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). @@ -237,29 +281,30 @@ Flag details may help you debug evaluation behavior and understand why a user re The `DdFlags.Enable()` API accepts optional configuration with options listed below. {{< code-block lang="csharp" >}} -DdFlags.Enable(new FlagsConfiguration( - trackExposures: true, - trackEvaluations: true, - evaluationFlushIntervalSeconds: 10.0f -)); +DdFlags.Enable(new FlagsConfiguration +{ + TrackExposures = true, + TrackEvaluations = true, + EvaluationFlushIntervalSeconds = 10.0f, +}); {{< /code-block >}} -`trackExposures` +`TrackExposures` : When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. -`trackEvaluations` +`TrackEvaluations` : When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. -`evaluationFlushIntervalSeconds` +`EvaluationFlushIntervalSeconds` : The interval in seconds at which batched evaluation events are sent to Datadog. Accepted values are between `1` and `60`. Default is `10.0` seconds. -`customFlagsEndpoint` +`CustomFlagsEndpoint` : Configures a custom server URL for retrieving flag assignments. -`customExposureEndpoint` +`CustomExposureEndpoint` : Configures a custom server URL for sending flags exposure data. -`customEvaluationEndpoint` +`CustomEvaluationEndpoint` : Configures a custom server URL for sending flags evaluation telemetry. ## Further reading From 0538017b1b740301c8102c4df604f60d47284e84 Mon Sep 17 00:00:00 2001 From: Tyler Potter Date: Thu, 19 Mar 2026 12:41:58 -0600 Subject: [PATCH 9/9] Rewrite Unity OpenFeature docs to match intended API design - DdFlags is an instance class with immutable FlagsConfiguration (constructor syntax) - DdFlags.Instance.CreateProvider() returns provider for registration with OpenFeature - Provider registered via Api.Instance.SetProviderAsync(provider) - Evaluation context set via OpenFeature standard EvaluationContext.Builder() - No Datadog-specific context types or direct provider method calls - Rename "Create and retrieve a client" section to "Register the provider" --- .../feature_flags/client/unity-openfeature.md | 170 +++++++----------- 1 file changed, 68 insertions(+), 102 deletions(-) diff --git a/content/en/feature_flags/client/unity-openfeature.md b/content/en/feature_flags/client/unity-openfeature.md index fa2a922a583..705263c1d1b 100644 --- a/content/en/feature_flags/client/unity-openfeature.md +++ b/content/en/feature_flags/client/unity-openfeature.md @@ -24,7 +24,7 @@ further_reading: This page describes how to instrument your Unity application with the Datadog Feature Flags SDK using the OpenFeature standard. Datadog feature flags provide a unified way to remotely control feature availability in your app, experiment safely, and deliver new experiences with confidence. -This guide explains how to install and enable the SDK, create and use a flags client with OpenFeature, and configure advanced options. +This guide explains how to install and enable the SDK, register the Datadog OpenFeature provider, set an evaluation context, and evaluate flags. ## Installation @@ -57,42 +57,36 @@ For more information about setting up the Unity SDK, see [Unity Monitoring Setup After the SDK is initialized, set up feature flags with these steps: {{< code-block lang="csharp" >}} -using System.Collections.Generic; using Datadog.Unity.Flags; using OpenFeature; +using OpenFeature.Model; using UnityEngine; // 1. Enable the Flags feature after Datadog SDK initialization -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); - -// 2. Create the default client (wires up the OpenFeature provider automatically) -DdFlags.CreateClient(); - -// 3. Set the evaluation context (fetches flag assignments from the server) -DdFlags.SetEvaluationContext( - new FlagsEvaluationContext( - targetingKey: "user-123", - attributes: new Dictionary - { - { "email", "user@example.com" }, - { "tier", "premium" } - } - ), - onComplete: async success => - { - if (success) - { - // 4. Evaluate flags via the OpenFeature API - var client = Api.Instance.GetClient(); - var isNewCheckoutEnabled = await client.GetBooleanValueAsync("checkout.new", false); - Debug.Log($"checkout.new = {isNewCheckoutEnabled}"); - } - } +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true +)); + +// 2. Create the Datadog provider and register it with OpenFeature +var provider = DdFlags.Instance.CreateProvider(); +await Api.Instance.SetProviderAsync(provider); + +// 3. Get an OpenFeature client +var client = Api.Instance.GetClient(); + +// 4. Set the evaluation context +await client.SetContextAsync( + EvaluationContext.Builder() + .SetTargetingKey("user-123") + .Set("email", "user@example.com") + .Set("tier", "premium") + .Build() ); + +// 5. Evaluate flags +var isNewCheckoutEnabled = await client.GetBooleanValueAsync("checkout.new", false); +Debug.Log($"checkout.new = {isNewCheckoutEnabled}"); {{< /code-block >}} ## Enable flags @@ -102,69 +96,60 @@ After initializing Datadog, enable flags in your application code: {{< code-block lang="csharp" >}} using Datadog.Unity.Flags; -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, -}); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true +)); {{< /code-block >}} You can also pass additional configuration options; see [Advanced configuration](#advanced-configuration). -## Create and retrieve a client +## Register the provider -Create a client once, typically during app startup: +Create the Datadog provider and register it with the OpenFeature `Api`: {{< code-block lang="csharp" >}} -DdFlags.CreateClient(); // Creates the default client +using OpenFeature; + +var provider = DdFlags.Instance.CreateProvider(); +await Api.Instance.SetProviderAsync(provider); {{< /code-block >}} -Retrieve the same client anywhere in your app using the OpenFeature API: +Retrieve a client anywhere in your app using the OpenFeature API: {{< code-block lang="csharp" >}} -using OpenFeature; - var client = Api.Instance.GetClient(); {{< /code-block >}} -You can also create and retrieve multiple clients by providing the `name` parameter: +You can also register named providers and retrieve named clients: {{< code-block lang="csharp" >}} -DdFlags.CreateClient("checkout"); +var provider = DdFlags.Instance.CreateProvider(); +await Api.Instance.SetProviderAsync("checkout", provider); var client = Api.Instance.GetClient("checkout"); {{< /code-block >}} -
If a client with the given name already exists, the existing instance is reused.
- ## Set the evaluation context -Define who or what the flag evaluation applies to using a `FlagsEvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. +Define who or what the flag evaluation applies to using an OpenFeature `EvaluationContext`. The evaluation context includes user or session information used to determine which flag variations should be returned. Call this method before evaluating flags to ensure proper targeting. {{< code-block lang="csharp" >}} -DdFlags.SetEvaluationContext( - new FlagsEvaluationContext( - targetingKey: "user-123", - attributes: new Dictionary - { - { "email", "user@example.com" }, - { "tier", "premium" } - } - ), - onComplete: success => - { - if (success) - { - Debug.Log("Flags loaded successfully!"); - } - } +using OpenFeature.Model; + +await client.SetContextAsync( + EvaluationContext.Builder() + .SetTargetingKey("user-123") + .Set("email", "user@example.com") + .Set("tier", "premium") + .Build() ); {{< /code-block >}} -This method fetches flag assignments from the server asynchronously in the background. The operation is non-blocking and thread-safe. Flag updates are available for subsequent evaluations once the background operation completes. +This triggers a fetch of flag assignments from the server. Flag updates are available for subsequent evaluations once the operation completes. ## Evaluate flags -After creating the client and setting its evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. +After setting the evaluation context, you can start reading flag values throughout your app. Flag evaluation is _local and instantaneous_—the SDK uses locally cached data, so no network requests occur when evaluating flags. This makes evaluations safe to perform on the main thread. Each flag is identified by a _key_ (a unique string) and can be evaluated with a _typed method_ that returns a value of the expected type. If the flag doesn't exist or cannot be evaluated, the SDK returns the provided default value. @@ -175,12 +160,7 @@ The Unity SDK uses the [OpenFeature][6] standard API for flag evaluation. Use `GetBooleanValueAsync(key, defaultValue)` for flags that represent on/off or true/false conditions. For example: {{< code-block lang="csharp" >}} -var client = Api.Instance.GetClient(); - -var isNewCheckoutEnabled = await client.GetBooleanValueAsync( - flagKey: "checkout.new", - defaultValue: false -); +var isNewCheckoutEnabled = await client.GetBooleanValueAsync("checkout.new", false); if (isNewCheckoutEnabled) { @@ -197,10 +177,7 @@ else Use `GetStringValueAsync(key, defaultValue)` for flags that select between multiple variants or configuration strings. For example: {{< code-block lang="csharp" >}} -var theme = await client.GetStringValueAsync( - flagKey: "ui.theme", - defaultValue: "light" -); +var theme = await client.GetStringValueAsync("ui.theme", "light"); switch (theme) { @@ -221,15 +198,8 @@ switch (theme) For numeric flags, use `GetIntegerValueAsync(key, defaultValue)` or `GetDoubleValueAsync(key, defaultValue)`. These are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier: {{< code-block lang="csharp" >}} -var maxItems = await client.GetIntegerValueAsync( - flagKey: "cart.items.max", - defaultValue: 20 -); - -var priceMultiplier = await client.GetDoubleValueAsync( - flagKey: "pricing.multiplier", - defaultValue: 1.0 -); +var maxItems = await client.GetIntegerValueAsync("cart.items.max", 20); +var priceMultiplier = await client.GetDoubleValueAsync("pricing.multiplier", 1.0); {{< /code-block >}} ### Object flags @@ -238,8 +208,8 @@ For structured or JSON-like data, use `GetObjectValueAsync(key, defaultValue)`. {{< code-block lang="csharp" >}} var config = await client.GetObjectValueAsync( - flagKey: "ui.config", - defaultValue: new Value(new Structure(new Dictionary + "ui.config", + new Value(new Structure(new Dictionary { { "color", new Value("#00A3FF") }, { "fontSize", new Value(14) } @@ -263,10 +233,7 @@ When you need more than just the flag value, use the detail methods. These metho For example: {{< code-block lang="csharp" >}} -var details = await client.GetStringDetailsAsync( - flagKey: "paywall.layout", - defaultValue: "control" -); +var details = await client.GetStringDetailsAsync("paywall.layout", "control"); Debug.Log($"Value: {details.Value}"); // Evaluated value (for example: "A", "B", or "control") Debug.Log($"Variant: {details.Variant}"); // Variant name, if applicable @@ -281,30 +248,29 @@ Flag details may help you debug evaluation behavior and understand why a user re The `DdFlags.Enable()` API accepts optional configuration with options listed below. {{< code-block lang="csharp" >}} -DdFlags.Enable(new FlagsConfiguration -{ - TrackExposures = true, - TrackEvaluations = true, - EvaluationFlushIntervalSeconds = 10.0f, -}); +DdFlags.Enable(new FlagsConfiguration( + trackExposures: true, + trackEvaluations: true, + evaluationFlushIntervalSeconds: 10.0f +)); {{< /code-block >}} -`TrackExposures` +`trackExposures` : When `true` (default), the SDK automatically records an _exposure event_ when a flag is evaluated. These events contain metadata about which flag was accessed, which variant was served, and under what context. They are sent to Datadog so you can later analyze feature adoption. Set to `false` to disable exposure tracking. -`TrackEvaluations` +`trackEvaluations` : When `true` (default), the SDK tracks flag evaluations and sends aggregated evaluation telemetry to Datadog. This enables analytics about flag usage patterns and performance. Set to `false` to disable evaluation tracking. -`EvaluationFlushIntervalSeconds` +`evaluationFlushIntervalSeconds` : The interval in seconds at which batched evaluation events are sent to Datadog. Accepted values are between `1` and `60`. Default is `10.0` seconds. -`CustomFlagsEndpoint` +`customFlagsEndpoint` : Configures a custom server URL for retrieving flag assignments. -`CustomExposureEndpoint` +`customExposureEndpoint` : Configures a custom server URL for sending flags exposure data. -`CustomEvaluationEndpoint` +`customEvaluationEndpoint` : Configures a custom server URL for sending flags evaluation telemetry. ## Further reading