• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""
EXPAND ALL

EDIT ON GITHUB

User configuration

Read time: 27 minutes
Last edited: Aug 10, 2022

Overview

This topic explains how to configure user objects in LaunchDarkly SDKs. These features are available for both client-side and server-side SDKs.

Configuring user objects

Every LaunchDarkly SDK lets you configure user objects to return specific data to LaunchDarkly. Any attributes you pass to LaunchDarkly become available on the Users list. A user's attribute values determine which variation of a feature flag the user receives.

The user key is the only mandatory user attribute. User keys must be a string type. User keys must be unique, deterministic, and should not contain Personally Identifiable Information (PII). User keys must be consistent, which means the same person must correspond to the same user key across different services to contribute to consistent flag evaluations and accurate monthly active user (MAU) counts.

When you set a user key, consider where you will use it. User keys are transmitted to LaunchDarkly, so if your security best practices require you to obscure employee information when it is sent to third-party services, you may want to compose user keys of a unique identifier that is not PII and that has been hashed and salted.

Using built-in and custom attributes

Attributes other than the user key are optional. There are two types of attributes: built-in attributes, which are LaunchDarkly names, and custom attributes, which you can name anything you choose.

Built-in attributes include common identifiers for users, like firstName and email. For a list of all built-in user attributes LaunchDarkly supports, read Built-in user attributes.

Custom attributes let you target users according to any data that you want to send to LaunchDarkly, including organizations, groups, and account plans. Custom attributes values can be booleans, numbers, strings, or arrays. If you set the value of a custom attribute to a JSON object, it won't appear on your Users list. To learn more, read Custom user attributes.

Custom and built-in attributes cannot share keys

If you create a custom attribute with a key already in use by a built-in attribute, the SDK will behave unpredictably during feature flag evaluation. For a list of built-in attributes and their keys, read Built-in user attributes.

Using private attributes

Each SDK lets you configure users with private attributes. You can use private user attributes for targeting purposes, but these attributes are removed from user data sent back to LaunchDarkly.

Designating anonymous users

Each SDK lets you designate anonymous users. Anonymous users don't appear on your Users list, so you can't search for those users, and you can't search for or autocomplete by anonymous user keys. If you use the same user key for every anonymous user, you also can't use Experimentation with anonymous users, because tracking events are attributed to the user key.

In client-side SDKs, if you don't provide a user key or set it to null, and set anonymous to true, then the SDK generates a random user key for you.

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

Details about each SDK's configuration are available in the SDK-specific sections below.

  • Client-side SDKs
  • Server-side SDKs

Client-side SDKs

Here are the configuration options for user entities in client-side SDKs.

.NET (client-side)

Expand .NET (client-side) code sample

In the client-side .NET SDK, you can construct a simple User that only has a key by calling User.WithKey, or use User.Builder which allows setting all properties.

Here's an example:

LDUser user = User.Builder("aa0ceb")
.FirstName("Ernestina")
.LastName("Evans")
.Email("ernestina@example.com")
.Custom("group", "admins")
.Build();

The argument to Builder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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. The client-side .NET SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the client-side .NET SDK


You can optionally configure the client-side .NET SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

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 user attributes except the key for all users are removed before the SDK sends the user to LaunchDarkly.
  • When creating the LaunchDarkly Configuration object, you can call the PrivateAttributeName method, which takes in a string attribute, names a parameter, and adds it to an internally managed list of private attributes. This method may be called multiple times to mark additional attributes as private. If any user has a custom or built-in attribute named in the private attributes list, the SDK removes it before sending the user to LaunchDarkly.

You can also mark attributes as private when building the user object by calling AsPrivateAttribute() immediately after setting the attribute.

For example:

var user = User.Builder("aa0ceb")
.Email("test@example.com").AsPrivateAttribute()
.Build();

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the client-side .NET SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUser user = User.Builder("aa0ceb")
.Anonymous(true)
.Build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

In Android or iOS, you can also allow the SDK to create a key for an anonymous user based on a unique device identifier as defined by the DeviceInfo Xamarin plugin. It will do so if you set the key to null and set the anonymous flag:

LDUser user = User.Builder((string)null).Anonymous(true).Build();

Android

Expand Android code sample

In the Android SDK, use a builder pattern to construct users.

Here's an example:

LDUser user = new LDUser.Builder("aa0ceb")
.email("fake@example.com")
.firstName("Jake")
.lastName("Fake")
.custom("group", "microsoft")
.build();

The argument to Builder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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. The Android SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the Android SDK


You can optionally configure the Android SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Android SDK you can define private attributes for the entire LaunchDarkly client. When creating the LDConfig object, call the setPrivateAttributeNames method, which which takes in a set of custom or built-in attributes as a parameter. If any user has a custom or built-in attribute named in this set, the SDK removes it before sending the user to LaunchDarkly.

Here's how to configure private user attributes:

HashSet<String> privateAttributes = new HashSet<>();
privateAttributes.add("name"); // built-in attribute
privateAttributes.add("group"); // custom attribute
LDConfig ldConfig = new LDConfig.Builder()
.setPrivateAttributeNames(privateAttributes)
.build();

You can also mark attributes as private when building the user object by using the private versions of the builder methods to set the attributes. For example:

LDUser user = new LDUser.Builder("aa0ceb")
.email("fake@example.com")
.privateName("Jane")
.privateCustom("group", "microsoft")
.build();

When the SDK sends this user back to LaunchDarkly, it removes the name and group attributes.

Anonymous users in the Android SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUser user = new LDUser.Builder("user key")
.anonymous(true)
.build();

You can leave the key parameter in the Builder null or make it an empty string. The client will automatically set it to a LaunchDarkly-specific, device-unique string that is consistent between app restarts and device reboots.

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

C/C++ (client-side)

Expand C/C++ (client-side) code sample

In the C/C++ (client-side) SDK, you can construct a user using LDUserNew.

Here's an example:

struct LDJSON *attributes, *groups;
groups = LDNewArray();
LDArrayPush(groups, LDNewText("Google"));
LDArrayPush(groups, LDNewText("Microsoft"));
attributes = LDNewObject();
LDObjectSetKey("groups", groups);
struct LDUser *user = LDUserNew("aa0ceb");
LDUserSetFirstName(user, "Jake");
LDUserSetLastName(user, "Fake");
LDUserSetCustomAttributesJSON(user, attributes);

The argument to LDUserNew is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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.

Private user attributes in the C/C++ SDK


You can optionally configure the C/C++ SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the C/C++ SDK there are two ways to define private attributes for the LaunchDarkly client:

  • When creating the LDConfig object, you can set the allAttributesPrivate value to true. When you do this, all user attributes except the key are removed before the SDK sends the user to LaunchDarkly.
  • When creating the LDConfig object, you can configure a map of privateAttributeNames. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.
struct LDConfig *config = LDConfigNew("YOUR_MOBILE_KEY");
// Mark all attributes private
LDConfigSetAllAttributesPrivate(config, true);

Anonymous users in the C/C++ SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

struct LDUser *user = LDUserNew("aa0ceb");
LDUserSetAnonymous(user, true);

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

Electron

Expand Electron code sample
Personally-identifying user keys

By default, when the SDK requests feature flags from LaunchDarkly, it makes an HTTP GET request with the user properties encoded in the URL. If you do not want user keys or other properties to be in request URLs, enable the useReport option in your client configuration. The SDK sends user data in the body of an HTTP REPORT request instead.

Here's an example of a user:

const user = {
key: 'aa0ceb',
firstName: 'Ernestina',
lastName: 'Evans',
email: 'ernestina@example.com',
custom: {
groups: ['Google', 'Microsoft']
}
};

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

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.

Private user attributes in the Electron SDK


You can optionally configure the SDK to treat all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but the SDK removes them from the user data sent back to LaunchDarkly.

To mark all user attributes except the key as private, you can use the allAttributesPrivate option:

const user = {
key: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com'
};
const client = LDElectron.initialize('YOUR_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: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com',
privateAttributeNames: ['email']
};
const client = LDElectron.initialize('YOUR_CLIENT_SIDE_ID', user, {
privateAttributeNames: ['email']
});

In the above example, the SDK sends only the key and name back to LaunchDarkly.

Anonymous users in the Electron SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

// 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.
const anonymousUser = { anonymous: true };
// You can also specify any key you want:
const anonymousUser2 = { key: 'aa0ceb', anonymous: true };

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

Flutter

Expand Flutter code sample

In the Flutter SDK, use a builder pattern to construct users.

Here's an example:

LDUser user = LDUserBuilder('aa0ceb')
.email('fake@example.com')
.firstName('Jake')
.lastName('Fake')
.custom('group', LDValue.ofString('microsoft'))
.build();

The argument to LDUserBuilder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes values can be booleans, numbers, strings, or arrays. Custom attribute values in the Flutter SDK use the LDValue class to support the various underlying types for the values. If you enter a custom value on the Users list that looks like a number or a boolean, the SDK interprets it that way. The Flutter SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the Flutter SDK


Optionally, you can configure the Flutter SDK to treat some or all user attributes as private user attributes. You can use private user attributes for targeting purposes. They are removed from the user data sent back to LaunchDarkly.

In the Flutter SDK, you can define private attributes for the entire LaunchDarkly client. When you create the LDConfig object, you can call the setPrivateAttributeNames method, which which takes in a set of custom or built-in attributes as a parameter. If any user has a custom or built-in attribute named in this set, the SDK removes it before sending the user to LaunchDarkly.

Set<String> privateAttributes =
{ 'name' // built-in attribute
, 'group' // custom attribute
};
LDConfig ldConfig = new LDConfigBuilder()
.setPrivateAttributeNames(privateAttributes)
.build();

You can also mark attributes as private when building the user object by using the private versions of the builder methods to set the attributes. For example:

LDUser user = LDUserBuilder('aa0ceb')
.email('fake@example.com')
.privateName('Jane')
.privateCustom('group', LDValue.ofString('microsoft'))
.build();

When the SDK sends this user back to LaunchDarkly, the name and group attributes are removed.

Anonymous users in the Flutter SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUser user = LDUserBuilder('user key')
.anonymous(true)
.build();

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

iOS

Expand iOS code sample

You can pass optional properties to the user object in iOS:

var user = LDUser(key: "YOUR_USER_KEY")
user.name = "Human Person"
user.email = "human@example.com"

Here, we added the user's full name and email address. To learn more about the specific user properties that are available in this SDK, read the SDK's API docs.

Private user attributes in the iOS SDK


You can optionally configure the iOS SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data the SDK sends to LaunchDarkly.

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 allUserAttributesPrivate attribute to true.
  • When creating the LDConfig object, you can set the privateUserAttributes property to a list of UserAttributes, such as [UserAttribute.BuiltIn.name, UserAttribute.forName("group")]. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

You can also mark attributes as private on a particular LDUser instance, for example:

var user = LDUser(key: "USER_KEY", name: "USER_NAME", custom: ["group": "beta"])
user.privateAttributes = [UserAttribute.BuiltIn.name, UserAttribute.forName("group")]

Anonymous users in the iOS SDK


You can declare an LDUser to be an anonymous, not logged-in user:

var user = LDUser(key: "USER_KEY")
user.isAnonymous = true
// Or have the SDK use a device persistent key. This sets `isAnonymous` by default.
let user = LDUser()

You must generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

JavaScript

Expand JavaScript code sample
Personally-identifying user keys

If the key attribute you rely on in your user JSON contains personally identifiable information, you should enable the useReport option by sending the user JSON as a JSON base64 URL-encoded path parameter. When you enable useReport, the SDK fetches flag settings by sending the user JSON in the body of a REPORT request instead, hiding that information from request logs.

Here's an example of a user:

const user = {
key: 'aa0ceb',
firstName': 'Ernestina',
lastName': 'Evans',
email': 'ernestina@example.com',
custom: {
groups: ['Google', 'Microsoft']
}
};

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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.

Private user attributes in the JavaScript SDK


You can optionally configure the JavaScript SDK to treat all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

To mark all user attributes except the key as private in the JavaScript SDK, you can use the allAttributesPrivate option:

const user = {
key: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com'
};
const ldclient = ld.initialize('YOUR_CLIENT_SIDE_ID', user, options = {
allAttributesPrivate: true
});

In the above example, the name and email attributes are removed.

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: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com',
privateAttributeNames: ['email']
};
const ldclient = ld.initialize('YOUR_CLIENT_SIDE_ID', user, options = {
privateAttributeNames: ['email']
});

In the above example, the SDK sends only the user's key and name back to LaunchDarkly.

Parameters for JS SDK < 2.0

SDK versions earlier than 2.0 use snake case rather than camel case in the options object. private_attribute_names and all_attributes_private are the parameter names that should be used. privateAttributeNames is still valid when you specify it in the user object.

Anonymous users in the JavaScript SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

// Starting with version 2.10.0 of the JavaScript SDK, to create
// an anonymous user you can specify the "anonymous" property and
// omit the "key" property. In doing so, the LaunchDarkly client
// auto-generates a unique identifier for this user. The
// identifier is saved in local storage and reused in future
// browser sessions to ensure a constant experience.
const anonymousUser = { anonymous: true };
// If you are using earlier SDK versions, you need to specify
// the "key" property as earlier versions do not auto-generate the
// property.
//
// Here you need to generate a unique key for anonymous
// users. You can use the session ID or a UUID.
//
// We suggest storing the user's key in a cookie, otherwise you
// might create a new user for each page request.
const anonymousUser2 = { key: 'aa0ceb', anonymous: true };

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

Node.js (client-side)

Expand Node.js (client-side) code sample
Personally-identifying user keys

By default, when the SDK requests feature flags from LaunchDarkly, it makes an HTTP GET request with the user properties encoded in the URL. If you do not want user keys or other properties to be in request URLs, enable the useReport option in your client configuration. The SDK sends user data in the body of an HTTP REPORT request instead.

Here's an example of a user:

const user = {
key: 'aa0ceb',
firstName: 'Ernestina',
lastName: 'Evans',
email: 'ernestina@example.com',
custom: {
groups: ['Google', 'Microsoft']
}
};

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

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.

Private user attributes in the Node.js SDK


You can optionally configure the SDK to treat all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

To mark all user attributes except the key as private in the JavaScript SDK, you can use the allAttributesPrivate option:

const user = {
key: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com'
};
const client = ld.initialize('YOUR_CLIENT_SIDE_ID', user, {
allAttributesPrivate: true
});

In the above example, the name and email attributes are removed.

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: 'aa0ceb',
name: 'Grace Hopper',
email: 'gracehopper@example.com'
privateAttributeNames: ['email']
};
const client = ld.initialize('YOUR_CLIENT_SIDE_ID', user, {
privateAttributeNames: ['email']
});

In the above example, the SDK sends only the user's key and name back to LaunchDarkly.

Anonymous users in the Node.js SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

// 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.
const anonymousUser = { anonymous: true };
// You can also specify any key you want:
const anonymousUser2 = { key: "aa0ceb", anonymous: true };

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

React

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

Unlike the JavaScript SDK, the React SDK does not require a user object for initialization. If you do not specify one, the React SDK uses an anonymous user by default.

React Native

Expand React Native code sample

Here is a complete user configuration object utilizing all available fields:

let user = {
key: '2fbfa269b78e24c8e967f482b89c939b',
name: 'grace_hopper',
firstName: 'Grace',
lastName: 'Hopper',
email: 'gracehopper@example.net',
anonymous: false,
privateAttributeNames: ['name'],
country: 'USA',
avatar: 'avatar',
ip: '192.0.2.1',
secondary: '',
custom: {'groups': 'users'}
};

The first attribute in the object is the user's key. In this case we've used the value 2fbfa269b78e24c8e967f482b89c939b. The user key is the only mandatory user attribute. The key should also uniquely identify each user. You can use any value such as a primary key, an email address, or a hash, as long as the same user always has the same key. We recommend using a hash if possible.

Private user attributes in the React Native SDK


Private attributes allow you to specify keys you do not want to send to the LaunchDarkly servers. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly. When the SDK sends this user back to LaunchDarkly, it removes the name attribute.

Anonymous user attributes in the React Native SDK


The anonymous key lets you distinguish logged out or unregistered users while still using LaunchDarkly. Anonymous users work just like regular users, except that they do not appear on your Users page in LaunchDarkly. This prevents unauthenticated users from diluting useful data on the Users list.

We recommend using the same user key for every initialization and then replacing that with the actual user key when you know who the user is. This way LaunchDarkly counts the initialization user key only once against your MAU, instead of every time you initialize.

Roku

Expand Roku code sample

You can create a user object with:

user = LaunchDarklyUser("my-user-key")

User objects can be customized with:

user.setFirstName(String)
user.setLastName(String)
user.setEmail(String)
user.setName(String)
user.setAvatar(String)
user.setCustom(AssociativeArray)

Private user attributes in the Roku SDK


Users can have specific fields marked as private with:

user.addPrivateAttribute(String)

Anonymous users in the Roku SDK


Designate an anonymous user with:

user.setAnonymous(Boolean)

Server-side SDKs

Here are the configuration options for user entities in server-side SDKs:

.NET (server-side)

Expand .NET (server-side) code sample

In the .NET SDK, the User class has a WithKey method for creating a simple user with only a key, and a Builder method for building a user with other properties.

Here's an example:

LDUser user = User.Builder("aa0ceb")
.FirstName("Ernestina")
.LastName("Evans")
.Email("ernestina@example.com")
.Custom("groups", LdValue.ArrayOf(LdValue.Of("Google"), LdValue.Of("Microsoft")))
.Build();

The argument to Builder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes values can be booleans, numbers, strings, or arrays. The SDK uses the LdValue type to represent arrays and objects. If you enter a custom value on the Users list that looks like a number or a boolean, the SDK interprets it that way. The .NET SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the .NET SDK


You can optionally configure the .NET SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the .NET SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • When creating the LaunchDarkly Configuration object, you can configure Events Events with AllAttributesPrivate, which takes in a boolean parameter. If true, the SDK removes all user attributes for all users before sending the user to LaunchDarkly, except the key.
  • Or, you can can configure Events with PrivateAttributes, which takes in a list of specific UserAttribute names. If any user has a custom or built-in attribute named in the private attributes list, the SDK removes it before sending the user to LaunchDarkly.

You can also mark attributes as private when building the user object by calling AsPrivateAttribute() after setting the attribute on the user builder.

For example:

var user = User.Builder("aa0ceb")
.Email("test@example.com").AsPrivateAttribute()
.Build();

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the .NET SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

var user = User.Builder("aa0ceb")
.Anonymous(true)
.Build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Apex

Expand Apex code sample

Here's an example of a user:

LDUser user = new LDUser.Builder('aa0ceb')
.setFirstName('Ernestina')
.setLastName('Evans')
.setEmail('ernestina@example.com')
.setCustom(new LDValueObject.Builder()
.set('groups', new LDValueArray.Builder()
.add(LDValue.of('Google'))
.add(LDValue.of('Microsoft'))
.build()
)
.build()
)
.build();

The argument to Builder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Anonymous users in the Apex SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUser user = new LDUser.Builder('abc123')
.setAnonymous(true)
.build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Private user attributes in the Apex SDK


Optionally, you can configure the Apex SDK to treat some or all user attributes as private user attributes. You can use private user attributes for targeting, but they are redacted from the user data sent back to LaunchDarkly.

In the Apex SDK there are two ways to define private attributes for the LaunchDarkly client:

  • When creating the LDConfig object, you can use setAllAttributesPrivate(true). When you do this, all user attributes, except the key, are redacted before the SDK sends the user to LaunchDarkly.

    Here's how:

    LDConfig config = new LDConfig.Builder()
    .setAllAttributesPrivate(true)
    .build();
  • You can also define private attribute names on a per-user basis.

    Here's how:

    Set<String> privateAttributes = new Set<String>();
    privateAttributes.add('firstName');
    LDUser user = new LDUser.Builder('aa0ceb')
    .setFirstName('alice')
    .setPrivateAttributeNames(privateAttributes)
    .build();

C/C++ (server-side)

Expand C/C++ (server-side) code sample

Here's an example of a user:

struct LDUser *user = LDUserNew("aa0ceb");
LDUserSetFirstName(user, "Ernestina");
LDUserSetLastName(user, "Evans");
LDUserSetEmail(user, "ernestina@example.com");
struct LDJSON *tmp;
struct LDJSON *custom = LDNewObject();
struct LDJSON *groups = LDNewArray();
tmp = LDNewText("Google");
LDArrayPush(groups, tmp);
tmp = LDNewText("Microsoft");
LDArrayPush(groups, tmp);
LDObjectSetKey(custom, "groups", groups);
LDUserSetCustom(user, custom);

The argument to LDUserNew is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

LDUserFree(user);

When you are done with an LDUser ensure that you free the structure.

Private user attributes in the C/C++ SDK


You can optionally configure the C/C++ SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the C/C++ SDK there are three ways to define private attributes for the LaunchDarkly client:

  • When creating the LDConfig object, you can use LDConfigSetAllAttributesPrivate. When you do this, all user attributes (except the key) for the user are removed before the SDK sends the user to LaunchDarkly.

For example:

LDConfigSetAllAttributesPrivate(config, true);
  • When creating the LDConfig object, you can list specific private attributes with LDConfigAddPrivateAttribute. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.
LDConfigAddPrivateAttribute(config, "email");
  • You can also define private attribute names on a per-user basis. For example:
LDUserAddPrivateAttribute(user, "email");

Anonymous users in the C/C++ SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUserSetAnonymous(user, true);

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Erlang

Expand Erlang code sample

Here's an example of a user:

Map = #{
    key => <<"aa0ceb">>,
    secondary => <<"abc">>,
    ip => <<"198.51.100.0">>,
    country => <<"your-country">>,
    email => <<"foo@bar.com">>,
    first_name => <<"a">>,
    last_name => <<"z">>,
    avatar => <<"ratavA">>,
    name => <<"foobar">>,
    anonymous => false,
    <<"custom-key">> => <<"custom-value">>
},
User = ldclient_user:new_from_map(Map)

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Anonymous users in the Erlang SDK


Here's how to create anonymous users in the Erlang SDK:

Key = <<"aa0ceb">>,
Anonymous = true,
Map = #{
    key => Key,
    anonymous => Anonymous,
},
User = ldclient_user:new_from_map(Map)

You must still generate a unique key for anonymous users. We recommend using Session IDs or UUIDs.

Private user attributes in the Erlang SDK


You can configure the Erlang SDK to treat some or all user attributes as private user attributes. You can use private user attributes to target users without sending data associated with that user back to LaunchDarkly.

To learn more about private user attributes, read Using private user attributes.

When you create the Options map, use the private_attributes key to set private user attributes. When you do this, the SDK does not send the user attributes you specify to LaunchDarkly.

The SDK always sends the user key

The user key is not optional. You cannot set it as a private user attribute.

Here's how to set user attributes as private:

ldclient:start_instance("YOUR_SDK_KEY", my_instance, #{private_attributes => [email]})

Go

Expand Go code sample

The Go SDK defines a User struct and a UserBuilder.

Here's an example:

import (
"gopkg.in/launchdarkly/go-sdk-common.v2/lduser"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldvalue" // for custom attributes read below
)
// User with only a key
user1 := lduser.NewUser("user1-key")
// User with a key plus other attributes
user2 := lduser.NewUserBuilder("user2-key").
FirstName("Ernestina").
LastName("Events").
Email("ernestina@example.com").
Custom("groups", ldvalue.ArrayOf(
ldvalue.String("Google"), ldvalue.String("Microsoft"))).
Build()

The most common attribute is the user's key. In this case we used the strings "user1-key" and "user2-key". The user key is the only mandatory user attribute. The key should also uniquely identify each user. You can use a primary key, an email address, or a hash, as long as the same user always has the same key. We recommend using a hash if possible.

To learn more about the available attributes, read User and UserBuilder.

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes values can be booleans, numbers, strings, or arrays. In SDK versions 4.16.0 and later, these types are all represented by the ldvalue.Value type; earlier versions use the catch-all Go type interface{}. If you enter a custom value on the Users list that looks like a number or a boolean, LaunchDarkly interprets it that way. The Go SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the Go SDK


You can optionally configure the Go SDK to treat some or all user attributes as Private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Go SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • You can set the configuration option AllAttributesPrivate to true. If you enable this, the SDK removes all user attributes for all users before it sends the user to LaunchDarkly, except the key.
  • You can set the configuration option PrivateAttributeNames to a list of attribute names. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

Here's how to to define private attributes:

import (
ld "gopkg.in/launchdarkly/go-server-sdk.v5"
"gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents"
)
var config ld.Config
// Make all attributes private for all users
config.Events = ldcomponents.SendEvents().AllAttributesPrivate(true)
// Or, make just the name and email attributes private for all users
config.Events = ldcomponents.SendEvents().
PrivateAttributeNames(lduser.NameAttribute, lduser.EmailAttribute)

You can also define a set of private attributes on the user object itself. In this example, Email is private for this user in addition to any private attributes that were specified globally:

import (
"gopkg.in/launchdarkly/go-sdk-common.v2/lduser"
)
user := lduser.NewUserBuilder("user-key").
FirstName("Ernestina").
LastName("Events").
Email("ernestina@example.com").AsPrivateAttribute().
Build()

Anonymous users in the Go SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

import (
"gopkg.in/launchdarkly/go-sdk-common.v2/lduser"
)
// Anonymous user with only a key
user1 := lduser.NewAnonymousUser("user1-key")
// Anonymous user with a key plus other attributes
user2 := lduser.NewUserBuilder("user2-key").
Anonymous(true).
Country("US").
Build()

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Haskell

Expand Haskell code sample

Here's an example of a user:

{-# LANGUAGE OverloadedStrings #-}
import LaunchDarkly.Server.User
import Data.Function ((&))
user :: User
user = (makeUser "aa0ceb")
& setFirstName "Ernestina"
& setLastName "Evans"
& setEmail "ernestina@example.com"

The argument to makeUser is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Private user attributes in the Haskell SDK


Optionally, you can configure the Haskell SDK to treat some or all user attributes as private user attributes. You can use private user attributes for targeting purposes without sending data about the user associated with them back to LaunchDarkly.

To learn more about private user attributes, read Using private user attributes.

When you create the Config object, use configSetAllAttributesPrivate to set all user attributes as private. When you do this, all user attributes (except the key) are removed before the SDK sends the user to LaunchDarkly.

Here's how:

config' = configSetAllAttributesPrivate True config

When you create the Config object, you can list specific private attributes with configSetPrivateAttributeNames. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

Here's an example:

import Data.Set (fromList)
config' = configSetPrivateAttributeNames (fromList ["email"]) config

You can also define private attribute names on a per-user basis.

For example:

import Data.Set (fromList)
user' = userSetPrivateAttributeNames (fromList ["email"]) user

Anonymous users in the Haskell SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

user` = userSetAnonymous True user

You still must generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Java

Expand Java code sample

In the Java SDK, use a builder pattern to construct users.

Here's an example:

LDUser user = new LDUser.Builder("aa0ceb")
.firstName("Ernestina")
.lastName("Evans")
.email("ernestina@example.com")
.custom("groups",
LDValue.buildArray().add("Google").add("Microsoft").build())
.build()

The argument to Builder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Our Javadoc for LDUser.Builder shows you all the attributes that LaunchDarkly supports by default.

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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. The Java SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the Java SDK


You can optionally configure the Java SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Java SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • When creating the LDConfig object, you can call the allAttributesPrivate method, which takes in a boolean parameter. If true, all user attributes except the key for all users are removed before the SDK sends the user to LaunchDarkly.
  • When creating the LDConfig object, you can call the privateAttributes method, which takes in a set of custom or built-in attributes as a parameter. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

Here's how to define private attributes:

LDConfig configWithAllAttributesPrivate = new LDConfig.Builder()
.events(
Components.sendEvents()
.allAttributesPrivate(true)
)
.build();
LDConfig configWithSpecificAttributesPrivate = new LDConfig.Builder()
.events(
Components.sendEvents()
.privateAttributes(UserAttribute.NAME, UserAttribute.EMAIL,
UserAttribute.forName("someCustomAttribute"))
)
.build();

You can also mark attributes as private when building the user object by calling the equivalent “private” user builder method. For example:

LDUser user = new LDUser.Builder("aa0ceb")
.privateEmail("test@example.com")
.build();

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the Java SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

LDUser user = new LDUser.Builder("aa0ceb")
.anonymous(true)
.build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this. Each unique user key registers a user in the system, so capture and reuse your anonymous user's key between requests.

Lua

Expand Lua code sample

Here's an example of a user:

local user = ld.makeUser({
key = "aa0ceb",
firstName = "Ernestina",
lastName = "Evans",
email = "ernestina@example.com",
custom = {
groups = { "Google", "Microsoft" }
}
})

The argument to ld.makeUser is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

To learn more about configuration options, read the API docs.

Node.js (server-side)

Expand Node.js (server-side) code sample

In the Node.JS SDK, users are JSON objects.

Here's an example:

const user = {
"key": "aa0ceb",
"firstName": "Ernestina",
"lastName": "Evans",
"email": "ernestina@example.com",
"custom": {
"groups": ["Google", "Microsoft"]
}
};

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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.

Private user attributes in the Node.js SDK


You can optionally configure the Node.js SDK to treat some or all user attributes as Private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Node.js SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • In the LaunchDarkly config, you can set allAttributesPrivate to true. If you enable this, the SDK removes all user attributes for all users before sending the user to LaunchDarkly, except the key.
  • In the LaunchDarkly config object, you can define a list of privateAttributeNames. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

You can also define a set of privateAttributeNames on the user object. For example:

var user = {
"key": "aa0ceb",
"email": "test@example.com",
"privateAttributeNames": ["email"],
};

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the Node.js SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

const user = {"key":"aa0ceb", "anonymous": true};

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

PHP

Expand PHP code sample

In the PHP SDK, use a builder pattern to construct users.

Here's an example:

$user = (new LDUserBuilder("aa0ceb"))->firstName("Ernestina")->lastName("Evans")->email("ernestina@example.com")->custom(["groups" => array("Google","Microsoft")])->build();

The first argument to LDUserBuilder is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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. The PHP SDK is strongly-typed, so be aware of this distinction.

Private user attributes in the PHP SDK


You can optionally configure the PHP SDK to treat some or all user attributes as private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the PHP SDK there are two ways to define private attributes for the entire LaunchDarkly client:

In the LaunchDarkly config, you can set allAttributesPrivate to true. If you enable this, the SDK removes all user attributes for all users before sending the user to LaunchDarkly, except the key. In the LaunchDarkly config object, you can define a list of privateAttributeNames. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

You can also mark attributes as private when building the user object by calling the equivalent "private" LDUserBuilder method.

For example:

$user = (new LDUserBuilder('aa0ceb'))
->privateEmail('test@example.com')
->build();

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the PHP SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

$user = (new LDUserBuilder("aa0ceb"))->anonymous(true)->build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Python

Expand Python code sample

In the Python SDK, users are dictionaries.

Here's an example:

user = {
"key": "aa0ceb",
"firstName": "Ernestina",
"lastName": "Evans",
"email": "ernestina@example.com",
"custom": {
"groups": ["Google", "Microsoft"]
}
}

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, 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 "aa0ceb".

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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.

Private user attributes in the Python SDK


You can optionally configure the Python SDK to treat some or all user attributes as Private user attribute. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Python SDK there are two ways to define private attributes for the LaunchDarkly client:

  • In the LaunchDarkly config, you can set all_attributes_private to true. If you enable this, the SDK removes all user attributes for all users before sending the user to LaunchDarkly, except the key.
  • In the LaunchDarkly config object, you can define a list of private_attribute_names. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

You can also define a set of privateAttributeNames on the user object. For example:

user = {
"key": "aa0ceb",
"email": "test@example.com",
"privateAttributeNames": ["email"]
}

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the Python SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

user = { "key":"aa0ceb", "anonymous": True }

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this. Anonymous users still count toward your plan's MAU limit, so make sure you capture and reuse your anonymous user's key between requests.

Ruby

Expand Ruby code sample

In the Ruby SDK, users are hashes.

Here's an example:

user = {
key: "aa0ceb",
firstName: "Ernestina",
lastName: "Evans",
email: "ernestina@example.com",
custom: {
groups: ["Google", "Microsoft"]
}
}

The key property is the user's key. The key should uniquely identify each user. You can use a primary key, an email address, or a hash string, as long as the same user always has the same key. We recommend using a hash string if possible. In this example the hash string is "aa0ceb".

User attribute keys must be symbols

All user attribute keys, for both built-in and custom attributes, must be symbols and not strings.

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes 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.

Private user attributes in the Ruby SDK


You can optionally configure the Ruby SDK to treat some or all user attributes as Private user attributes. Private user attributes can be used for targeting purposes, but are removed from the user data sent back to LaunchDarkly.

In the Ruby SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • In the LaunchDarkly config, you can set all_attributes_private to true. If you enable this, the SDK removes all user attributes for all users before sending the user to LaunchDarkly, except the key.
  • In the LaunchDarkly config object, you can define a list of private_attribute_names. If any user has a custom or built-in attribute named in this list, the SDK removes it before sending the user to LaunchDarkly.

You can also define a set of privateAttributeNames on the user object. For example:

user = {
key: "aa0ceb",
firstName: "Ernestina",
lastName: "Evans",
email: "ernestina@example.com",
custom: {
groups: ["Google", "Microsoft"]
},
privateAttributeNames: ['email']
}

When the SDK sends this user back to LaunchDarkly, it removes the email attribute.

Anonymous users in the Ruby SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

user = { key: "aa0ceb", anonymous: true }

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Rust

Expand Rust code sample

The Rust SDK defines a User struct and a UserBuilder.

Here's an example:

// User with only a key
let user1 = User::with_key("user1-key").build();
// User with a key plus other attributes
let custom = hashmap! {
"groups".into() => vec!["Google", "Microsoft"].into(),
};
let mut builder = User::with_key("user2-key");
builder.first_name("Ernestina");
builder.last_name("Evans");
builder.email("ernestina@example.com");
builder.custom(custom);
let user2 = builder.build();

The most common attribute is the user's key. In the example, the strings "user1-key" and "user2-key" are the user keys. The user key is the only mandatory user attribute. The key should also uniquely identify each user. You can use a primary key, an email address, or a hash string, as long as the same user always has the same key. We recommend using a hash string if possible.

To learn more about the available attributes, read User and UserBuilder.

Interpreting custom attribute types

Most of the built-in attributes, like names and email addresses, expect string values. Custom attributes values can be booleans, numbers, strings, or arrays. These types are all represented by the AttributeValue type. The Rust SDK is strongly-typed, so be aware of this distinction.

Anonymous users in the Rust SDK


You can distinguish logged-in users from anonymous users in the SDK.

Here's how:

// Anonymous user with only a key
let user1 = User::with_key("user1-key").anonymous(true).build();
// Anonymous user with a key plus other attributes
let user2 = User::with_key("user2-key").
anonymous(true).
country("US").
build();

You still need to generate a unique key for anonymous users. Session IDs or UUIDs work best for this.