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

EDIT ON GITHUB

Aliasing users

Read time: 2 minutes
Last edited: May 20, 2022

Overview

This topic explains how to alias the users of various LaunchDarkly SDKs. This feature is available for both client-side and server-side SDKs, although its behavior differs between client-side and server-side SDKs.

Aliased users

There are situations in which multiple LaunchDarkly users can represent one person. For example, this can happen when a person initially logs into an application. The person might be represented by an anonymous user before they log in, and a different user after they log in. In that case, that one person is identified by two different users as denoted by different user keys. Our SDKs can associate these two LaunchDarkly users by sending an alias event.

All LaunchDarkly SDKs offer the ability to manually send an alias event. Additionally, client-side SDKs automatically send an alias event when identifying a known user if the previous user was anonymous. To lean more, read Associating anonymous users with logged in users. You can disable this behavior if necessary. To learn how, read Configuration.

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

  • Client-side SDKs
  • Server-side SDKs

Client-side SDKs

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

.NET (client-side)

Expand .NET (client-side) code sample

To manually send an alias event:

client.Alias(newUser, previousUser);

To learn more, read LdClient.Alias and ConfigurationBuilder.AutoAliasingOptOut.

Android

Expand Android code sample

To manually send an alias event:

client.alias(newUser, previousUser);

C/C++ (client-side)

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

To manually send an alias event:

LDClientAlias(client, newUser, previousUser);

Electron

Expand Electron code sample

To manually send an alias event:

client.alias(newUser, previousUser);

Flutter

Expand Flutter code sample

To manually send an alias event:

await LDClient.alias(newUser, previousUser);

iOS

Expand iOS code sample

To manually send an alias event:

LDClient.get()!.alias(context: newUser, previousContext: previousUser)

JavaScript

Expand JavaScript code sample

Both alias parameters must have key attributes. If the LaunchDarkly client auto-generated a unique identifier for one of your users, you can access the user's complete object with the getUser method.

To manually send an alias event:

const previousUser = client.getUser();
client.alias(newUser, previousUser);

Node.js (client-side)

Expand Node.js (client-side) code sample

To manually send an alias event:

client.alias(newUser, previousUser);

React

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

React Native

Expand React Native code sample

To manually send an alias event:

client.alias(user, previousUser);
// to send an alias event in a different environment than the default,
// pass in the environment key (optional)
client.alias(user, previousUser, environment);

Roku

Expand Roku code sample

To manually send an alias event:

client.alias(user, previousUser)

Server-side SDKs

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

.NET (server-side)

Expand .NET (server-side) code sample

To manually send an alias event:

client.Alias(newUser, previousUser);

Apex

Expand Apex code sample

To manually send an alias event:

client.alias(newUser, previousUser)

C/C++ (server-side)

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

To manually send an alias event:

LDClientAlias(client, newUser, previousUser);

Erlang

Expand Erlang code sample

To manually send an alias event:

ldclient:alias(User, PreviousUser)

Go

Expand Go code sample

To manually send an alias event:

client.Alias(newUser, previousUser)

Haskell

Expand Haskell code sample

To manually send an alias event:

alias client newUser previousUser

Java

Expand Java code sample

To manually send an alias event:

client.alias(user, previousUser);

Lua

Expand Lua code sample

To manually send an alias event:

client:alias(newUser, previousUser)

Node.js (server-side)

Expand Node.js (server-side) code sample

To manually send an alias event:

client.alias(newUser, previousUser);

PHP

Expand PHP code sample

To manually send an alias event:

$client->alias($user, $previousUser);

Python

Expand Python code sample

To manually send an alias event:

ldclient.get().alias(new_user, previous_user)

Ruby

Expand Ruby code sample

To manually send an alias event:

client.alias(new_user, previous_user)

Rust

Expand Rust code sample

To manually send an alias event:

client.alias(user, previous_user);