> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Identifying and changing contexts

> This topic explains how to use the identify feature in LaunchDarkly SDKs.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

This topic explains how to use the identify feature in LaunchDarkly SDKs. Identify is available for client-side and server-side SDKs.

## Using identify to change contexts and users

The identify feature's behavior differs between client-side and server-side SDKs.

Client-side SDKs are configured to operate for one end user at a time, identified or anonymous. In these SDKs, the identify feature allows you to change the context, such as when an end user logs in or changes their settings. Identifying contexts and users causes LaunchDarkly to index them.

To associate two contexts with each other, such as your representations of an end user before and after they log in, call identify with a multi-context that contains both contexts. The association between the two contexts that comprise your multi-context doesn't persist between sessions. You must call identify with the multi-context each time.

Here is an example of a multi-context, though each SDK sends context data to LaunchDarkly in a slightly different format:

<CodeGroup>
  ```json title="Example multi-context" theme={null}
      {
        "kind": "multi",
        "user": {
          "key": "example-user-key",
          "name": "Sandy",
          "email": "sandy@example.com"
        },
        "device": {
          "key": "example-device-key",
          "type": "iPhone",
          "deviceId": 12345
        }
      }
  ```
</CodeGroup>

Server-side SDKs operate for multiple end users concurrently. Unlike in client-side SDKs, server-side SDKs do not have a notion of "changing the user context" because contexts or users are directly passed to client method invocations for actions such as evaluating flag variations. In server-side SDKs, the only impact of identifying contexts and users is that they are added to the **Contexts** list. However, in most applications this is not needed because they are automatically indexed when used for a flag evaluation. Instead, you should provide the evaluation object in a variation or all flags call to get the expected flag evaluation. To learn more, read [Evaluating flags](/sdk/features/evaluating) and [Getting all flags](/sdk/features/all-flags).

To learn more about the differences in how SDKs identify and use users and contexts, read [Choosing an SDK type](/sdk/concepts/client-side-server-side).

<Note title="Newer versions of LaunchDarkly SDKs replace users with contexts">
  A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users." To learn more, read [Contexts](/home/flags/contexts).

  Creating contexts and evaluating flags based on them is supported in the latest major versions of [most of our SDKs](/sdk). For these SDKs, the code samples on this page include the two most recent versions.
</Note>

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

* [Client-side SDKs](#client-side-sdks)
* [Server-side SDKs](#server-side-sdks)

## Client-side SDKs

This feature is available in the following client-side SDKs:

* [.NET (client-side)](#net-client-side)
* [Android](#android)
* [C++ (client-side)](#c-client-side)
* [Electron](#electron)
* [Flutter](#flutter)
* [iOS](#ios)
* [JavaScript](#javascript)
* [Node.js (client-side)](#nodejs-client-side)
* [React](#react)
* [React Native](#react-native)
* [Roku](#roku)

### .NET (client-side)

<Accordion title="Expand .NET (client-side) code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The identify method tells the client to change the current context and obtain the feature flag values for the new context. In the .NET SDK, you can use either the `Identify` or `IdentifyAsync` method to switch contexts.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `Identify()` or `IdentifyAsync()` so that the person receives the correct feature flag settings for their account.

  In general, however, we recommend composing the new context as a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `Identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    You may want to wait until the flag values for the new context have been loaded before proceeding. You can do this either by calling the synchronous method `Identify` with a timeout, or by calling the asynchronous method `IdentifyAsync` and awaiting the result.

    Here's how:

  <CodeGroup>
    ```csharp title=".NET SDK v3.0+ (C#)" theme={null}
          var updatedContext = Context.Builder("example-context-key")
              .Set("email", "sandy@example.com")
              .Build();

          // Synchronous method
          client.Identify(updatedContext, TimeSpan.FromSeconds(5));

          // Asynchronous method
          await client.IdentifyAsync(updatedContext);
    ```
  </CodeGroup>

  To learn more, read [`Identify`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/client/api/LaunchDarkly.Sdk.Client.LdClient.html#LaunchDarkly_Sdk_Client_LdClient_Identify_) and [`IdentifyAsync`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/client/api/LaunchDarkly.Sdk.Client.LdClient.html#LaunchDarkly_Sdk_Client_LdClient_IdentifyAsync_).
</Accordion>

### Android

<Accordion title="Expand Android code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how:

  <CodeGroup>
    ```java title="Android SDK v4.0+ (Java)" theme={null}
          LDContext updatedContext = LDContext.builderFromContext(context)
              .email("sandy@example.com")
              .build();

          client.identify(updatedContext);
    ```

    ```kotlin title="Android SDK v4.0+ (Kotlin)" theme={null}
          val updatedContext: LDContext = LDContext.builderFromContext(context)
              .email("sandy@example.com")
              .build()

          client.identify(updatedContext)
    ```
  </CodeGroup>

  The `identify()` call loads any saved flag values for the new user context and immediately triggers an update of the latest flags from LaunchDarkly.

  `identify()` returns a [Future](https://developer.android.com/reference/java/util/concurrent/Future) to indicate completion. If you want to be sure subsequent code is using the latest values from the server, you can wait for the Future using `get`.

  To learn more, read [`identify`](https://launchdarkly.github.io/android-client-sdk/com/launchdarkly/sdk/android/LDClient.html#identify\(com.launchdarkly.sdk.LDContext\)).
</Accordion>

### C++ (client-side)

<Accordion title="Expand C++ (client-side) code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The identify method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `Identify` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `Identify` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how to update your initial context when you have additional information:

  <CodeGroup>
    ```cpp title="C++ SDK v3 (native)" theme={null}
          /* before end user logs in */
          auto context = ContextBuilder()
            .Kind("device", "example-device-key")
            .Build();

          /* after end user logs in */
          auto updated_context = ContextBuilder(context)
            .Kind("user", "example-user-key")
            .Name("Sandy")
            .Kind("organization", "example-organization-key")
            .Name("Global Health Services")
            .Build();
    ```
  </CodeGroup>

  After you update the context, you must call identify with the updated context in order to evaluate flags based on the updated information.

  Here's how to use the identify method to switch contexts:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" theme={null}
          client.IdentifyAsync(updated_context);
    ```

    ```c title="C++ SDK v3.0 (C binding)" theme={null}
          LDClientSDK_Identify(client, updated_context, LD_NONBLOCKING, NULL);
    ```

    ```c title="C SDK v2.x" theme={null}
          LDClientIdentify(client, newUser);
    ```
  </CodeGroup>

  You can also examine the result to determine if the identification succeeded. Here's how:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" theme={null}
          auto identify_result = client.IdentifyAsync(updated_context);
          auto status = identify_result.wait_for(maxwait);

          if (status == std::future_status::ready) {
            /* The client's attempt to identify succeeded or failed in the specified amount of time. */
            if (identify_result.get()) {
              /* Identification succeeded */
            } else {
              /* Identification failed */
            }
          } else {
            /* The specified timeout was reached, but the client is still identifying. */
          }
    ```

    ```c title="C++ SDK v3.0 (C binding)" theme={null}
          bool identified_successfully;
          if (LDClientSDK_Identify(client, updated_context, maxwait, &identified_successfully)) {
            /* The client's attempt to identify succeeded or failed in the specified amount of time. */
            if (identified_successfully) {
              /* Identification succeeded. */
            else {
              /* Identification failed. */
            }
          } else {
             /* The specified timeout was reached, but the client is still identifying. */
          }
    ```
  </CodeGroup>

  The `IdentifyAsync` call loads any saved flag values for the new context and immediately triggers an update of the latest flags from LaunchDarkly. Because this method re-fetches flag settings for the updated context, you should not call it at high frequency. The intended use case for switching contexts is the login/logout flow. To learn more, read [`IdentifyAsync`](https://launchdarkly.github.io/cpp-sdks/libs/client-sdk/docs/html/classlaunchdarkly_1_1client__side_1_1Client.html#a62fc1fe135495b72fa37ecedf5a2c7e2).
</Accordion>

### Electron

<Accordion title="Expand Electron code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current user and obtain the feature flag values for the new user.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how:

  <CodeGroup>
    ```js title="JavaScript" theme={null}
          const newUser = { key: 'example-user-key', name: 'Sandy' };

          client.identify(newUser, (newFlags) => {
            console.log('value of flag for this user is: ' + newFlags['example-flag-key']);
            console.log('this should be the same: ' + client.variation('example-flag-key'));
          });

          // or:
          client.identify(newUser).then((newFlags) => {
            // as above
          });
    ```

    ```ts title="TypeScript" theme={null}
          import * as LDElectron from 'launchdarkly-electron-client-sdk';

          const newUser: LDElectron.LDUser = {
            key: 'someone-else', name: 'John',
          };

          client.identify(newUser, (newFlags) => {
            console.log('value of flag for this user is: ' + newFlags['example-flag-key']);
            console.log('this should be the same: ' + client.variation('example-flag-key'));
          });

          // or:
          client.identify(newUser).then((newFlags) => {
            // as above
          });
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/electron-client-sdk/interfaces/_launchdarkly_electron_client_sdk_.ldelectronmainclient.html#identify).
</Accordion>

### Flutter

<Accordion title="Expand Flutter code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how:

  <CodeGroup>
    ```dart title="Flutter SDK v4, single context" theme={null}
          final updatedContext = LDContextBuilder()
            .kind('user', 'example-user-key')
            .setString('email', 'sandy@example.com'))
            .build();

          await client.identify(updatedContext);
    ```

    ```dart title="Flutter SDK v4, multi-context" theme={null}
          final updatedMultiContext = LDContextBuilder()
            .kind('user', 'example-user-key')
            .kind('device', 'example-device-key')
            .build();

          await client.identify(updatedMultiContext);
    ```

    ```dart title="Flutter SDK v3.x, single context" theme={null}
          LDContextBuilder builder = LDContextBuilder();
          builder.kind('user', 'example-user-key')
              .set('email', LDValue.ofString('sandy@example.com'));
          LDContext updatedContext = builder.build();

          await LDClient.identify(updatedContext);
    ```

    ```dart title="Flutter SDK v3.x, multi-context" theme={null}
          LDContextBuilder builder = LDContextBuilder();
          builder.kind('user', 'example-user-key');
          builder.kind('device', 'example-device-key');

          LDContext updatedMultiContext = builder.build();

          await LDClient.identify(updatedMultiContext);
    ```

    ```dart title="Flutter SDK v2.x, single context" theme={null}
          LDContextBuilder builder = LDContextBuilder();
          builder.kind('user', 'example-user-key')
              .set('email', LDValue.ofString('sandy@example.com'));
          LDContext updatedContext = builder.build();

          await LDClient.identifyWithContext(updatedContext);
    ```

    ```dart title="Flutter SDK v2.x, multi-context" theme={null}
          LDContextBuilder builder = LDContextBuilder();
          builder.kind('user', 'example-user-key');
          builder.kind('device', 'example-device-key');

          LDContext updatedMultiContext = builder.build();

          await LDClient.identifyWithContext(updatedMultiContext);
    ```

    ```dart title="Flutter SDK v1.x" theme={null}
          LDUser updatedUser = LDUserBuilder('user key')
              .email('sandy@example.com')
              .build();

          await LDClient.identify(updatedUser);
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://pub.dev/documentation/launchdarkly_flutter_client_sdk/latest/launchdarkly_flutter_client_sdk/LDClient/identify.html).
</Accordion>

### iOS

<Accordion title="Expand iOS code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    If the client app does not identify an `LDContext`, `LDClient` creates an anonymous default context, which can affect which feature flags LaunchDarkly delivers to the `LDClient`. Client apps should follow the [Apple Privacy Policy](https://apple.com/legal/privacy) when collecting end user information.

    Here's how:

  <CodeGroup>
    ```swift title="iOS SDK v8.0+ (Swift)" theme={null}
          let newContext = try LDContextBuilder(key: "example-context-key").build().get();

          // You can also call identify with a completion
          LDClient.get()!.identify(context: newContext) {
              // Flags have been retrieved for the new context
          }
    ```

    ```objectivec title="iOS SDK v8.0+ (Objective-C)" theme={null}
          LDContextBuilder *builder = [[LDContextBuilder alloc] initWithKey:@"example-context-key"];
          ContextBuilderResult *result = builder.build;

          if (result.success) {
              LDContext *context = result.success;
          }
          [[LDClient get] identifyWithContext:newContext];

          // You can also call identify with a completion
          [[LDClient get] identifyWithContext:newContext completion:^() {
              // Flags have been retrieved for the new context
          }];
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/ios-client-sdk/Classes/ObjcLDClient.html#/c:@M@LaunchDarkly@objc\(cs\)LDClient\(im\)identifyWithContext:).
</Accordion>

### Java

Script

<Accordion title="Expand JavaScript code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    If you provide a callback function, it is called with a map of flag keys and values after the flag values for the new context are available. After that point, `variation()` uses the new values. You can also use a Promise for the same purpose. When you use a Promise, it is important that you handle the rejection case. Otherwise, it will become an unhandled Promise rejection, which is a serious error on some platforms.

    It is possible that the `identify()` call will fail. If you are using a callback, the callback will receive an error value, and calls to [evaluate a flag](/sdk/features/evaluating) will still return flag values for the previous context.

    Here's how to identify a new context:

  <CodeGroup>
    ```js title="JavaScript SDK v3+, single context" theme={null}
          client.identify(newContext, hash, function() {
            console.log("New context's flags available");
          });
    ```

    ```js title="JavaScript SDK v3+, multi-context" theme={null}
          const newMultiContext = {
            kind: 'multi',
            user: {
              key: 'example-user-key',
              name: 'Anna',
              role: 'doctor'
            },
            device: {
              key: 'example-device-key',
              platform: 'Android'
            }
          }

          client.identify(newMultiContext, hash, function() {
            console.log("New context's flags available");
          });
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/js-client-sdk/interfaces/LDClient.html#identify).

  If you are using the [LaunchDarkly observability SDKs](/sdk/observability), calling `identify()` also automatically indexes your sessions so that you can [search for sessions](/home/observability/session-replay) based on context attributes.

  If your contexts are extraordinarily large, you may need to configure the JavaScript SDK to send the evaluation context as a request body. To learn more, read [Using REPORT in the JavaScript SDK](/guides/account/user-data#use-report-in-the-javascript-sdk).

  <Warning title="You must use a hash parameter while in secure mode">
    The hash parameter is the hash for the new context, assuming that the context's key has changed. The hash parameter is only required in secure mode. If secure mode is not enabled, pass in `null` for the hash.
  </Warning>
</Accordion>

### Node.js (client-side)

<Accordion title="Expand Node.js (client-side) code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how:

  <CodeGroup>
    ```js title="Node.js SDK v3.0, single context" theme={null}
          client.identify(newContext, () => {
            console.log("New context's flags available");
          });

          // or, with a Promise:
          client.identify(newContext).then(() => {
            console.log("New context's flags available");
          });
    ```

    ```js title="Node.js SDK v3.0, multi-context" theme={null}
          const newMultiContext = {
            kind: 'multi',
            user: {
              key: 'aa0ceb',
              name: 'Anna',
              role: 'doctor'
            },
            device: {
              key: 'example-device-key',
              platform: 'Android'
            }
          }

          client.identify(newMultiContext, () => {
            console.log("New context's flags available");
          });

          // or, with a Promise:
          client.identify(newMultiContext).then(() => {
            console.log("New context's flags available");
          });
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/node-client-sdk/interfaces/LDClient.html#identify).
</Accordion>

### React

<Accordion title="Expand React code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    Here's how:

  <CodeGroup>
    ```js title="JavaScript" theme={null}
          import { useLDClient } from 'launchdarkly-react-client-sdk';

          let ldClient = useLDClient();

          ldClient.identify(newContext, null, () => {
            console.log("New context's flags available");
          });
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/react-native-client-sdk/classes/LDClient.html#identify).
</Accordion>

### React Native

<Accordion title="Expand React Native code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify` method tells the client to change the current context and obtain the feature flag values for the new context.

  <Note title="Version 10 requires an identify call">
    In the React Native SDK version 10, you do not provide a context when you initialize the `ReactNativeLDClient`. You must call `identify` before you can evaluate a feature flag for a specific context. End users will receive fallback values until you call specify a context by calling `identify`.
  </Note>

  If multiple customers use your app on a single device, you may want to change contexts and have separate flag settings for each one. To do this, the SDK stores contexts on a single device using [react-native-async-storage](https://react-native-async-storage.github.io/async-storage/), and supports switching between different contexts. You can use the `identify` method to switch contexts. `identify` loads any saved flag values for the new context and immediately triggers an update of the latest flags from LaunchDarkly.

  You might also call `identify` when your app gathers additional information about the end user. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user. Then you can evaluate flags using attributes from all three context kinds together.

  Here's how:

  <CodeGroup>
    ```ts title="React Native SDK v10" theme={null}
          import { useLDClient } from '@launchdarkly/react-native-client-sdk';

          const client = useLDClient();
          const context: LDContext = {'key': 'example-user-key', 'kind': 'user'};
              client
                .identify(context)
                .catch((e: any) => console.error(`error identifying ${context.key}: ${e}`));

    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/js-core/packages/sdk/react-native/docs/classes/LDClientImpl.html#identify).
</Accordion>

### Roku

<Accordion title="Expand Roku code sample">
  Client-side SDKs are configured to operate for one context at a time, whether identified or anonymous. The `identify()` method tells the client to change the current context and obtain the feature flag values for the new context.

  In some situations, the new context may be an updated version of the existing context. For example, on a sign-in page in a single-page app, you could represent the same person as a multi-context that combines a pre-login anonymous context and a post-login context with the "user" kind. After the person logs in, you can call `identify()` so that the person receives the correct feature flag settings for their account.

  In other situations, the new context may be a multi-context based on multiple identifiers, rather than only pre

  * and post-login contexts. For example, as soon as an end user visits your app, you may initialize the client with a context using a context kind of "device." When the end user logs in, you now also have their user and organization information. You can call `identify()` with a multi-context that contains the "device," "user," and "organization" contexts for the end user.

    To do this:

  <CodeGroup>
    ```brightscript title="Roku SDK v2.0 (BrightScript)" theme={null}
          ' before the end user logs in
          device = {
            "kind": "device",
            "key": "example-device-key",
            "type": "tablet"
          }
          context = LaunchDarklyCreateContext(device)

          ' after the end user logs in
          multi = {
            "kind": "multi",
            "device": device,
            "user": {"key": "example-user-key", "name": "Sandy"},
            "organization": {"key": "example-organization-key", "name": "Acme, Inc."}
          }

          launchDarkly.identify(multi)

    ```

    ```brightscript title="Roku SDK v1.x (BrightScript)" theme={null}
          user = LaunchDarklyUser("example-user-key")

          launchDarkly.identify(user)

    ```
  </CodeGroup>
</Accordion>

## Server-side SDKs

This feature is available in the following server-side SDKs:

* [.NET (server-side)](#net-server-side)
* [Apex](#apex)
* [C++ (server side)](#c-server-side)
* [Erlang](#erlang)
* [Go](#go)
* [Haskell](#haskell)
* [Java](#java)
* [Lua](#lua)
* [Node.js (server side)](#nodejs-server-side)
* [PHP](#php)
* [Python](#python)
* [Ruby](#ruby)
* [Rust](#rust)

### .NET (server-side)

<Accordion title="Expand .NET (server-side) code sample">
  In server-side SDKs, `Identify` creates or updates contexts on LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `Identify`. The `Variation` methods automatically create contexts on the **Contexts** list for you, using the context you pass to each `Variation` method. `Identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `Identify`:

  <CodeGroup>
    ```csharp title=".NET SDK v7.0 (C#)" theme={null}
          client.Identify(context);
    ```
  </CodeGroup>

  To learn more, read [`Identify`](https://launchdarkly.github.io/dotnet-core/pkgs/sdk/server/api/LaunchDarkly.Sdk.Server.LdClient.html#LaunchDarkly_Sdk_Server_LdClient_Identify_).
</Accordion>

### Apex

<Accordion title="Expand Apex code sample">
  In server-side SDKs, `identify` creates or updates users in LaunchDarkly, which makes them available for targeting and autocomplete on the **Users** list.

  To use `identify`:

  <CodeGroup>
    ```java title="Apex" theme={null}
          client.identify(user);
    ```
  </CodeGroup>

  To learn more, read [Other methods](https://github.com/launchdarkly/apex-server-sdk/blob/main/doc.md#other-methods-1).
</Accordion>

### C++ (server-side)

<Accordion title="Expand C++ (server-side) code sample">
  In server-side SDKs, `Identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `Identify`. The `variation` call automatically creates contexts on the **Contexts** list for you, using the evaluation context you pass to each `variation` method. `Identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `Identify`:

  <CodeGroup>
    ```cpp title="C++ SDK v3.0 (native)" theme={null}
          client.Identify(context);
    ```

    ```c title="C++ SDK v3.0 (C binding)" theme={null}
          LDServerSDK_Identify(client, context);
    ```

    ```c title="C SDK v2 (native)" theme={null}
          LDClientIdentify(client, user);
    ```
  </CodeGroup>

  To learn more, read `Identify()` in [`Client`](https://launchdarkly.github.io/cpp-sdks/libs/server-sdk/docs/html/classlaunchdarkly_1_1server__side_1_1Client.html).
</Accordion>

### Erlang

<Accordion title="Expand Erlang code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` methods automatically create contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```erlang title="Erlang SDK v2.0+" theme={null}
          ldclient:identify(#{key => <<"example-context-key">>})
    ```

    ```erlang title="Erlang SDK v1.x" theme={null}
          ldclient:identify(#{key => <<"example-user-key">>})
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://hexdocs.pm/launchdarkly_server_sdk/ldclient.html#identify-1).
</Accordion>

### Go

<Accordion title="Expand Go code sample">
  In server-side SDKs, `Identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `Identify`. The `Variation` method automatically creates contexts on the **Contexts** list for you, using the context you pass to each `Variation` method. `Identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `Identify`:

  <CodeGroup>
    ```go title="Go SDK v7.13.4+, using LDScopedClient" theme={null}
          // There is not an Identify method in the LDScopedClient,
          // so you need to access the method from the LDClient.
          // Then, pass in the scoped client's current context.
          // LDScopedClient is in beta and may change without notice.
          scopedClient.Client().Identify(scopedClient.CurrentContext())
    ```

    ```go title="Go SDK v6+, using LDClient" theme={null}
          client.Identify(context)
    ```
  </CodeGroup>

  To learn more, read [`Identify`](https://pkg.go.dev/gopkg.in/launchdarkly/go-server-sdk.v5#LDClient.Identify).
</Accordion>

### Haskell

<Accordion title="Expand Haskell code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` methods automatically create contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```haskell title="Haskell SDK v4.0" theme={null}
          identify client context
    ```

    ```haskell title="Haskell SDK v3.x" theme={null}
          identify client user
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/haskell-server-sdk/LaunchDarkly-Server-Client.html#v:identify).
</Accordion>

### Java

<Accordion title="Expand Java code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` methods automatically create contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```java title="Java SDK v6.0" theme={null}
          client.identify(context);
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/java-core/lib/sdk/server/com/launchdarkly/sdk/server/LDClient.html#identify-com.launchdarkly.sdk.LDContext-).
</Accordion>

### Lua

<Accordion title="Expand Lua code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` methods automatically create contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```lua title="Lua SDK v2" theme={null}
          client:identify(context)
    ```

    ```lua title="Lua SDK v1.x" theme={null}
          client:identify(user)
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/lua-server-sdk/modules/launchdarkly-server-sdk.html#identify).
</Accordion>

### Node.js (server-side)

<Accordion title="Expand Node.js (server-side) code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` call automatically creates users on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```js title="Node.js SDK v7.x and later" theme={null}
          client.identify(context);
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/js-core/packages/sdk/server-node/docs/interfaces/LDClient.html#identify).
</Accordion>

### PHP

<Accordion title="Expand PHP code sample">
  In server-side SDKs, `identify` creates or updates users in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` call automatically creates contexts on the **Contexts** list for you, using the context you pass to each `variation` call. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```php title="PHP SDK v5.0" theme={null}
          $client->identify($context);
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/php-server-sdk/classes/LaunchDarkly-LDClient.html#method_identify).
</Accordion>

### Python

<Accordion title="Expand Python code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` method automatically creates contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```python title="Python SDK v8.0" theme={null}
          ldclient.get().identify(context)
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.client.LDClient.identify).
</Accordion>

### Ruby

<Accordion title="Expand Ruby code sample">
  In server-side SDKs, `identify` creates or updates contexts in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` call automatically creates contexts on the **Contexts** list for you, using the context you pass to each `variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```ruby title="Ruby SDK v7.0" theme={null}
          client.identify(context)
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://launchdarkly.github.io/ruby-server-sdk/LaunchDarkly/LDClient.html#identify-instance_method).
</Accordion>

### Rust

<Accordion title="Expand Rust code sample">
  In server-side SDKs, `identify` creates or updates users in LaunchDarkly, which makes them available for targeting and autocomplete on the **Contexts** list.

  In most cases, you do not need to call `identify`. The `variation` methods automatically create users or contexts on the **Contexts** list for you, using the context you pass to each `Variation` method. `identify` is useful if you want to pre-populate your **Contexts** list before you launch any features.

  To use `identify`:

  <CodeGroup>
    ```rust title="Rust SDK v1" theme={null}
          client.identify(context);
    ```
  </CodeGroup>

  To learn more, read [`identify`](https://docs.rs/launchdarkly-server-sdk/latest/launchdarkly_server_sdk/struct.Client.html#method.identify).
</Accordion>
