Skip to main content

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 private context and user attributes in client-side SDKs:

.NET (client-side)

In the client-side .NET SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • When creating the LaunchDarkly Configuration object, you can call the AllAttributesPrivate method, which takes in a boolean parameter. If true, all context attributes except the kind and key are removed for all contexts before the SDK sends the context to LaunchDarkly.
  • When creating the LaunchDarkly Configuration object, you can call the PrivateAttributes method, which takes any number of attribute names or slash-delimited paths to designated JSON properties within an attribute, such as /address/street. If any context has a custom or built-in attribute that matches one of these names, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked private
      var configAllPrivate = Configuration
        .Builder("example-mobile-key", ConfigurationBuilder.AutoEnvAttributes.Enabled)
        .AllAttributesPrivate(true)
        .Build();
      LdClient client = LdClient.Init(configAllPrivate, context);

      // Two attributes marked private
      var configSomePrivate = Configuration.Builder("example-mobile-key")
        .PrivateAttributes("email", "address")
        .Build();
      LdClient client = LdClient.Init(configSomePrivate, context);
You can also mark attributes as private when building the context object by calling Private() on the context builder.For example:
      var context = Context.Builder("example-context-key")
          .Set("email", "sandy@example.com")
          .Private("email")
          .Build();
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Android

In the Android SDK you can define private attributes for the entire LaunchDarkly client. When creating the LDConfig object, call the privateAttributes method, which takes in a set of custom or built-in attributes as a parameter. If any context has a custom or built-in attribute named in this set, the SDK removes it before sending the context to LaunchDarkly.Here’s how to configure private attributes:
      // All attributes marked private
      LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
          .mobileKey("example-mobile-key")
          .events(
            Components.sendEvents()
                .allAttributesPrivate(true)
          )
          .build();

      // Two attributes marked private
      LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
          .mobileKey("example-mobile-key")
          .events(
              Components.sendEvents()
                  .privateAttributes("name", "group")
          )
          .build();
You can also mark attributes as private when building the context object by using the private versions of the builder methods to set the attributes. For example:
      LDContext context = LDContext.builder("example-context-key")
          .set("email", "sandy@example.com")
          .set("name", "Sandy")
          .set("group", "Global Health Services")
          .privateAttributes("name", "group")
When the SDK sends this context back to LaunchDarkly, it removes the name and group attributes.

C++ (client-side)

In the C++ SDK there are two ways to define private attributes for the LaunchDarkly client:
  • When using the ConfigBuilder, you can call AllAttributesPrivate(). When you do this, all context attributes except the kind and key are removed before the SDK sends the context to LaunchDarkly.
  • When using the ConfigBuilder, you can configure a set of PrivateAttributes(). If any context has an attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
Here’s how:
      /* sets all attributes private */
      auto config_builder = client_side::ConfigBuilder("example-mobile-key");
      config_builder.Events().AllAttributesPrivate(true);
      auto config_all_private = config_builder.Build();

      /* sets "email" and "address" private */
      auto config_builder = client_side::ConfigBuilder("example-mobile-key");
      config_builder.Events().PrivateAttributes({"email", "address"});
      auto configSomePrivate = config_builder.Build();
You can also define private attributes for a particular context by calling .SetPrivate() in the ContextBuilder.Here’s how:
      auto context = ContextBuilder()
        .Kind("user", "example-user-key")
        .Name("Sandy Smith")
        .SetPrivate("email", "sandy@example.com")
        .Build();
To learn more, read ContextBuilder.

Electron

To mark all user attributes except the key as private, use the allAttributesPrivate option:
      const user = {
        key: 'example-user-key',
        name: 'Sandy Smith',
        email: 'sandy@example.com'
      };

      const client = LDElectron.initialize('example-client-side-id', user, {
        allAttributesPrivate: true
      });
In the above example, the SDK removes the name and email attributes.You can also specify an array of which attributes should be private with the privateAttributeNames option. You can configure this option on a per-user basis by specifying which attributes should be private in your user object.This option is configured in both the user object and the configuration object:
      const user = {
        key: 'example-user-key',
        name: 'Sandy Smith',
        email: 'sandy@example.com',
        privateAttributeNames: ['email']
      };

      const client = LDElectron.initialize('example-client-side-id', user, {
        privateAttributeNames: ['email']
      });
In the above example, the SDK sends only the key and name back to LaunchDarkly.

Flutter

In the Flutter SDK, you can define private attributes for the entire LaunchDarkly client. When you create the LDConfig object, you can set all attributes private for all contexts. You can also provide a list of attributes to the globalPrivateAttributes option. If any context has an attribute named in this set, the SDK removes it before sending the context to LaunchDarkly.
      final config = LDConfig(
        CredentialSource.fromEnvironment(),
        AutoEnvAttributes.enabled,
        allAttributesPrivate: true, // all attributes marked private
        globalPrivateAttributes: ['user/email', 'user/group'], // two attributes marked private for the 'user' context kind
      )
You can also mark attributes as private when building the context object by using the private optional parameter. For example:
      final context = LDContextBuilder()
        .kind('user', 'example-user-key'),
        .setString('name', 'Sandy')
        .setString('email', 'sandy@example.com', private: true)
        .setString('group', 'microsoft', private: true)
        .build();
When the SDK sends this context back to LaunchDarkly, the email and group attributes are removed.To learn more about the configuration options for private attributes, read allAttributesPrivate and globalPrivateAttributes. To learn more about setting private attributes for a specific context, read LDContext.

iOS

In the iOS SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • When creating the LDConfig object, you can set the allContextAttributesPrivate attribute to true.
  • When creating the LDConfig object, you can set the privateContextAttributes property to a list of References, such as [Reference("name"), Reference("/address/state")]. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked private
      config = LDConfig(mobileKey: "example-mobile-key", autoEnvAttributes: .enabled)
      config.allContextAttributesPrivate = true

      // Two attributes marked private
      config = LDConfig(mobileKey: "example-mobile-key", autoEnvAttributes: .enabled)
      config.privateContextAttributes = [Reference("email"), Reference("address")]
You can also mark attributes as private on a particular LDContext instance, for example:
      var contextBuilder = LDContextBuilder(key: "example-context-key")
      contextBuilder.trySetValue("name", .string("Sandy"))
      contextBuilder.trySetValue("group", .array([LDValue(stringLiteral: "microsoft")]))
      contextBuilder.addPrivateAttribute(Reference("name"))
      contextBuilder.addPrivateAttribute(Reference("group"))

      let context = try contextBuilder.build().get()

Java

Script
You can configure the private attributes option either in the configuration object or in the context object.In the configuration object, to mark all attributes except the key as private in the JavaScript SDK, use the allAttributesPrivate option:

      // All attributes marked private
      const ldclient = ld.initialize('example-client-side-id', context, options = {
        allAttributesPrivate: true
      });

      try {
        await client.waitForInitialization(5);
        proceedWithSuccessfullyInitializedClient();
      } catch(err) {
        // Client failed to initialized or timed out
        // variation() calls return fallback values until initialization completes
      }

To learn more, read allAttributesPrivate.In the configuration object, to mark some attributes as private specify your array of attributes in the privateAttributes configuration option:

      // Two attributes marked private
      const ldclient = ld.initialize('example-client-side-id', context, options = {
        privateAttributes: ['email', 'name']
      });

      try {
        await client.waitForInitialization(5);
        proceedWithSuccessfullyInitializedClient();
      } catch(err) {
        // Client failed to initialized or timed out
        // variation() calls return fallback values until initialization completes
      }

To learn more, read privateAttributes.In the context object, specify your array of attributes in the privateAttributes field of the reserved _meta property.Here’s how:
      const context = {
        kind: 'user',
        key: 'example-context-key',
        name: 'Sandy Smith',
        email: 'sandy@example.com',
        _meta: {
          privateAttributes: ['email']
        }
      };

To learn more, read privateAttributes.

Node.js (client-side)

To mark all attributes except the key as private in the Node.js SDK, you can use the allAttributesPrivate option:
      const context = {
        kind: 'user',
        key: 'example-user-key',
        name: 'Sandy Smith',
        email: 'sandy@example.com'
      };
      // All attributes marked private
      const client = ld.initialize('example-client-side-id', context, {
        allAttributesPrivate: true
      });
      // Two attributes marked private
      const client = ld.initialize('example-client-side-id', context, {
        privateAttributes: ['email', 'name']
      });
You can also specify an array of which attributes should be private with the privateAttributes option. You can configure this option on a per-context basis by specifying which attributes should be private in your context object.You can configure this option in both the context object and the configuration object:
      const context = {
        kind: 'user',
        key: 'example-user-key',
        name: 'Sandy Smith',
        email: 'sandy@example.com'
        _meta: {
          privateAttributes: ['email']
        }
      };

      const client = ld.initialize('example-client-side-id', context, {
        privateAttributes: ['email']
      });
In the above example, the SDK sends only the context key and name back to LaunchDarkly.

React Native

You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:
      // All attributes marked private
      const options = {
        allAttributesPrivate: true
      }
      const client = new ReactNativeLDClient('example-mobile-key', AutoEnvAttributes.Enabled, options);

      // Two attributes marked private
      const options = {
        privateAttributes: ['email', 'address']
      }
      const client = new ReactNativeLDClient('example-mobile-key', AutoEnvAttributes.Enabled, options);
To learn more, read allAttributesPrivate and privateAttributes.You can also mark an attribute as private for a particular context:
      const context = {
        kind: 'user',
        key: 'example-user-key',
        firstName: 'Sandy',
        lastName: 'Smith',
        email: 'sandy@example.com',
        address: {
          street: '123 Main St',
          city: 'Springfield'
        },
        _meta: {
          privateAttributes: ['email', '/address/street']
        }
      };
For attributes that are objects, you can mark specific fields private, using the / delimiter followed by the attribute name, then the / delimiter followed by the JSON property within the value. In the example, the attribute "address": { "street": "Main St", "city": "Springfield" } has only the /address/street marked as private.

React Web

All context-related functionality provided by the JavaScript SDK is also available in the React Web SDK.

Roku

You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:
      ' All attributes marked private
      config = LaunchDarklyConfig("example-mobile-key", launchDarklyTaskNode)
      config.setAllAttributesPrivate(true)

      LaunchDarklySGInit(config, context)
      client = LaunchDarklySG(launchDarklyTaskNode)

      ' Two attributes marked private
      config = LaunchDarklyConfig("example-mobile-key", launchDarklyTaskNode)
      config.addPrivateAttribute("email")
      config.addPrivateAttribute("address")

      LaunchDarklySGInit(config, context)
      client = LaunchDarklySG(launchDarklyTaskNode)
You can also mark an attribute as private for a particular context:
      ' when creating a context
      context = LaunchDarklyCreateContext({
          "kind": "user",
          "key": "context-key-123-abc",
          "email": "sandy@example.com",
          "_meta": { privateAttributes: ["email"] }
      })

      ' for an existing context
      context.addPrivateAttribute("email")
      context.addPrivateAttribute("/address/street")