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.
Client-side SDKs
Here are the configuration options for anonymous contexts in client-side SDKs.- .NET (client-side)
- Android
- C++ (client-side)
- Electron
- Flutter
- iOS
- JavaScript
- Node.js (client-side)
- React Native
- React Web: The React Web SDK relies on the JavaScript SDK for context-related functionality.
- Roku
- Vue: The Vue SDK relies on the JavaScript SDK for context-related functionality.
.NET (client-side)
Expand .NET (client-side) code sample
Expand .NET (client-side) code sample
anonymous attribute is true: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:Android
Expand Android code sample
Expand Android code sample
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.C++ (client-side)
Expand C++ (client-side) code sample
Expand C++ (client-side) code sample
ContextBuilder.Electron
Expand Electron code sample
Expand Electron code sample
Flutter
Expand Flutter code sample
Expand Flutter code sample
anonymous.iOS
Expand iOS code sample
Expand iOS code sample
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:JavaScript
Expand JavaScript code sample
Expand JavaScript code sample
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:Node.js (client-side)
Expand Node.js (client-side) code sample
Expand Node.js (client-side) code sample
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:React Native
Expand React Native code sample
Expand React Native code sample
anonymous property and set the context key to an empty string.Here’s how: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.Using a shared key between anonymous contexts in React Native for Android
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.Expand React Native v7.x-v9.x for Android code sample
Expand React Native v7.x-v9.x for Android code sample
- have an Android application
- are using the React Native SDK in versions 7.x through 9.x
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.React Web
All context-related functionality provided by the JavaScript SDK is also available in the React Web SDK.Roku
Expand Roku code sample
Expand Roku code sample
Vue
All context-related functionality provided by the JavaScript SDK SDK is also available in the Vue SDK.Server-side SDKs
Here are the configuration options for anonymous contexts in server-side SDKs:- .NET (server-side)
- Apex
- C++ (server-side)
- Erlang
- Go
- Haskell
- Java
- Lua
- Node.js (server-side)
- PHP
- Python
- Ruby
- Rust
.NET (server-side)
Expand .NET (server-side) code sample
Expand .NET (server-side) code sample
Apex
Expand Apex code sample
Expand Apex code sample
C++ (server-side)
Expand C++ (server-side) code sample
Expand C++ (server-side) code sample
ContextBuilder.Erlang
Expand Erlang code sample
Expand Erlang code sample
Go
Expand Go code sample
Expand Go code sample
EventsConfiguration.Haskell
Expand Haskell code sample
Expand Haskell code sample
configSetOmitAnonymousContexts.Java
Expand Java code sample
Expand Java code sample
Lua
Expand Lua code sample
Expand Lua code sample
makeContext.Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
PHP
Expand PHP code sample
Expand PHP code sample
Python
Expand Python code sample
Expand Python code sample
omit_anonymous_contexts.Ruby
Expand Ruby code sample
Expand Ruby code sample
omit_anonymous_contexts.Rust
Expand Rust code sample
Expand Rust code sample
omit_anonymous_contexts.Edge SDKs
Here are the configuration options for anonymous contexts in edge SDKs.Akamai
Expand Akamai code sample
Expand Akamai code sample
Cloudflare
Expand Cloudflare code sample
Expand Cloudflare code sample
Fastly
Expand Fastly code sample
Expand Fastly code sample
Vercel
Expand Vercel code sample
Expand Vercel code sample
AI SDKs
Here are the configuration options for anonymous contexts in AI SDKs..NET AI
Expand .NET AI SDK code sample
Expand .NET AI SDK code sample
Go AI
Expand Go AI SDK code sample
Expand Go AI SDK code sample
Java AI
Expand Java AI SDK code sample
Expand Java AI SDK code sample
Node.js (server-side) AI
Expand Node.js (server-side) AI SDK code sample
Expand Node.js (server-side) AI SDK code sample
Python AI
Expand Python AI SDK code sample
Expand Python AI SDK code sample
omit_anonymous_contexts.Ruby AI
Expand Ruby AI SDK code sample
Expand Ruby AI SDK code sample
omit_anonymous_contexts.