Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Client-side SDKs
Here are the configuration options for 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
.NET (client-side)
Expand .NET (client-side) code sample
Expand .NET (client-side) code sample
In the client-side .NET SDK, you can construct a Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
Context that only has a key by calling Context.New. The context kind defaults to “user,” or you can supply a different context kind. Alternatively, you can use Context.Builder, which allows setting all properties.The argument to Builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes, which you can set with
.Name() and .Kind(), expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be any JSON type, including booleans, numbers, strings, arrays, or objects. The SDK uses the LdValue type to represent arrays and objects. The client-side .NET SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the .NET (client-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the .NET (client-side) SDK, read Anonymous contexts and users.Android
Expand Android code sample
Expand Android code sample
In the Android SDK, use a builder pattern to construct contexts. The argument to Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes, which you can set with
.name() and .kind(), expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be any JSON type, including boolean, number, string, array, or object. The Android SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Android SDK, read Private attributes.To learn how to configure anonymous contexts in the Android SDK, read Anonymous contexts and users.Version 4 of the Android SDK replaced users with contexts. Starting in version 5, the deprecated
LDUser is removed. To learn more about replacing users with contexts, read the [Android SDK 3.x to 4.0 migration guide](/sdk/client-side/android/migration-3-to-C++ (client-side)
Expand C++ (client-side) code sample
Expand C++ (client-side) code sample
In the C++ (client-side) SDK, you can construct a context using the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn how to configure private attributes in the C++ (client-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the C++ (client-side) SDK, read Anonymous contexts and users.
ContextBuilder. The arguments to .Kind() are the context kind and key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key, an email address, or a hash for the key, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The name and kind attributes, which you can set with
.Name() and .Kind(), expect string values. Other attribute values can be any JSON type, including boolean, number, string, array, or object.Electron
Expand Electron code sample
Expand Electron code sample
Here’s an example of a user:The To learn how to configure private attributes in the Electron SDK, read Private attributes.To learn how to configure anonymous users in the Electron SDK, read Anonymous contexts and users.
key property is the user’s key. The key should uniquely identify each user. You can use a primary key or a hash, as long as the same user always has the same key. We recommend using a hash if possible. In this example, the hash is "example-user-key".Most of the built-in attributes, like names and email addresses, expect string values. Custom attribute values can be booleans, numbers, strings, or arrays. If you enter a custom value on the Users list that looks like a number or a boolean, the SDK interprets it that way.
Flutter
Expand Flutter code sample
Expand Flutter code sample
In the Flutter SDK, use a builder pattern to construct contexts. The arguments to Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn how to configure private attributes in the Flutter SDK, read Private attributes.To learn how to configure anonymous contexts in the Flutter SDK, read Anonymous contexts and users.
LDContextBuilder are the context’s kind and key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The required
kind and optional name attributes expect string values. Other attribute values can be any JSON type, including boolean, number, string, array, or object. Attribute values in the Flutter SDK use the LDValue class to support the various underlying types for the values. The Flutter SDK is strongly-typed, so be aware of this distinction.Starting in version 4, the Flutter SDK provides setters so that you do not have to create an LDValue yourself. Instead, you can use setBool, setNum, and setString when adding attributes to a context.iOS
Expand iOS code sample
Expand iOS code sample
In the iOS SDK, you can construct a context using Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:You can define additional attributes for a context by passing in a name and value for each. Additional attributes can be any JSON type, including boolean, number, string, array, or object.If an attribute is a JSON object, then in your flag or segment targeting, you can use
LDContextBuilder. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:/ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn more about the specific context properties that are available in this SDK, read LDContextBuilder.To learn how to configure private attributes in the iOS SDK, read Private attributes.To learn how to configure anonymous contexts in the iOS SDK, read Anonymous contexts and users.Version 8 of the iOS SDK replaced users with contexts. Starting in version 9, the deprecated
LDUser is removed. To learn more about replacing users with contexts, read the iOS SDK 7.x to 8.0 migration guides for Swift or Objective-C and Best practices for upgrading users to contexts.Java
ScriptExpand JavaScript code sample
Expand JavaScript code sample
In the JavaScript SDK, construct a context using key/value pairs for the context attributes. Contexts use the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
LDContext type. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example of a context:The optional
name and kind attributes expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attributes can be booleans, numbers, strings, arrays, or JSON objects./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the JavaScript SDK, read Private attributes.To learn how to configure anonymous contexts in the JavaScript SDK, read Anonymous contexts and users.Node.js (client-side)
Expand Node.js (client-side) code sample
Expand Node.js (client-side) code sample
In the Node.js (client-side) SDK, construct a context using key/value pairs for the context attributes. Contexts use the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:The
LDContext type. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example of a context:kind and name attributes expect string values. Other attribute values can be booleans, numbers, strings, arrays, or JSON objects.If an attribute is a JSON object, then in your flag or segment targeting, you can use / as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Node.js (client-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the Node.js (client-side) SDK, read Anonymous contexts and users.React Native
Expand React Native code sample
Expand React Native code sample
In the React Native SDK, construct a context using key/value pairs for the context attributes. Contexts use the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If the context is anonymous, you should set the
LDContext type.The first attribute in the object is the key. In the React Native SDK, both key and kind are required. They are the only mandatory attributes. The combination of key and kind must uniquely identify each context. You can use any value for the key, such as a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:key to an empty string. The SDK will automatically set the key to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.Other attributes can be booleans, numbers, strings, arrays, or JSON objects.If an attribute is a JSON object, then in your flag or segment targeting, you can use / as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the React Native SDK, read Private attributes.To learn how to configure anonymous contexts in the React Native SDK, read Anonymous contexts and users.React Web
All context-related functionality provided by the JavaScript SDK is also available in the React Web SDK. Unlike the JavaScript SDK, the React Web SDK does not require a context object for initialization. If you do not specify one, the React SDK uses an anonymous context by default.Roku
Expand Roku code sample
Expand Roku code sample
In the Roku SDK, use Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
LaunchDarklyCreateContext to construct a context. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional
name and kind attributes expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attributes can be booleans, numbers, strings, arrays, or JSON objects./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Roku SDK, read Private attributes.To learn how to configure anonymous contexts in the Roku SDK, read Anonymous contexts and users.