This topic explains how to configure contexts as anonymous in LaunchDarkly SDKs. These features are available for all SDKs.
Each SDK lets you designate anonymous contexts. Anonymous contexts don’t appear on your Contexts list, so you can’t search for them, and you can’t search for or autocomplete by their keys. If you use multi-contexts, you can choose to make only some contexts anonymous. To learn more, read Multi-contexts.
In some client-side SDKs, if you don’t provide a key or set it to null, and set anonymous to true, then the SDK generates a random key for you. If you generate keys for anonymous contexts, session IDs or UUIDs work best.
To learn more, read Anonymous contexts.
Details about each SDK’s configuration are available in the SDK-specific sections below.
A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: “users.” To learn more, read Contexts.
Here are the configuration options for anonymous contexts in client-side SDKs.
To distinguish logged-in end users from anonymous end users in the SDK:
To auto-generate a key for any context whose anonymous attribute is true:
If you set this option, you must still specify a non-null key as a placeholder when you construct the Context, because the SDK does not allow a Context to exist with a null key. When you pass this context to SDK methods like Init or Identify, the SDK replaces the placeholder key with a generated key.
In this example, the placeholder key is “placeholder-key”, but it could be any non-empty string:
To distinguish logged-in end users from anonymous end users in the SDK:
If you set this option, you must still specify a non-null key as a placeholder when you construct the LDContext, because this SDK does not allow a Context to exist with a null key. When you pass this context to SDK methods like Init or Identify, the SDK replaces the placeholder key with a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.
To distinguish logged-in end users from anonymous end users in the SDK:
To learn more, read ContextBuilder.
To distinguish logged-in end users from anonymous end users in the SDK:
To create an anonymous user with an auto-generated key, specify the “anonymous” property and omit the “key” property. The LaunchDarkly client creates a unique key for this user and caches it locally:
To distinguish logged-in end users from anonymous end users in the SDK:
To learn more, read anonymous.
To distinguish logged-in end users from anonymous end users in the SDK:
Alternatively, you can omit the key parameter. The client will automatically set the isAnonymous property for the context, and set the key to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.
Here’s how:
To create an anonymous context, specify the anonymous property and omit the key property. The client will automatically set the key to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.
Here’s how:
To distinguish logged-in end users from anonymous end users in the SDK:
You can also have the SDK generate the key for you. Specify the anonymous property and omit the key property. The client will automatically set the key to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.
Here’s how:
To create an create an anonymous context, specify the anonymous property and set the context key to an empty string.
Here’s how:
In version 10 of the SDK, you must include the key attribute when building the anonymous context. If you set the key to an empty string, the client will automatically set the key to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots. We strongly recommend having the client manage the key for anonymous contexts. If you set the key to a non-empty string, the client uses that value as the key. However, the key may not be stable across restarts or reboots.
The SDK gives a usage error if you omit the key attribute. It also gives a usage error if you set the key to an empty string and do not mark the context as anonymous.
In versions 7 through 9 of the SDK, you may omit the context key when building an anonymous context, and the client will automatically set it to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.
It is possible to use one, shared key between anonymous contexts. However, we do not recommend this. Using a shared key between anonymous contexts means that some features will be limited or will not work as expected. To learn more, read Use a shared key between anonymous contexts.
If you are using an older version of the React Native SDK on Android, there is some additional configuration required if you want to use a shared key between anonymous contexts.
If you do choose to use a shared key between anonymous contexts, and you:
then you must also explicitly configure the SDK to allow using a shared key between anonymous contexts. The generateAnonymousKeysAndroid configuration option defaults to true, which means that the SDK will automatically generate unique keys for anonymous contexts. If you need to use a shared key between anonymous contexts, then you must set this option to false.
To learn more, read generateAnonymousKeys.
The React Native SDK for iOS generates a context key for anonymous contexts only if you do not supply one. No additional SDK configuration is required if you are using a shared key for anonymous contexts with the React Native SDK for iOS.
All context-related functionality provided by the JavaScript SDK is also available in the React Web SDK.
To distinguish logged-in end users from anonymous end users in the SDK:
Here are the configuration options for anonymous contexts in server-side SDKs:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To learn more, read ContextBuilder.
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read EventsConfiguration.
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read configSetOmitAnonymousContexts.
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To learn more, read makeContext.
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read omit_anonymous_contexts.
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read omit_anonymous_contexts.
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read omit_anonymous_contexts.
Here are the configuration options for anonymous contexts in edge SDKs.
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
Here are the configuration options for anonymous contexts in AI SDKs.
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list.
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read omit_anonymous_contexts.
To distinguish logged-in end users from anonymous end users in the SDK:
Anonymous contexts do not appear on the Contexts list. Optionally, you can configure the SDK to omit data from anonymous contexts when sending related events to LaunchDarkly. Depending on how your application uses contexts, this can significantly decrease the amount of data your application sends to LaunchDarkly. To learn more, read omit_anonymous_contexts.