Skip to content

Setting user IDs

Learn how to set user IDs through the Braze SDK. These are unique identifiers that let you track users across devices and platforms, import their data through the user data API, and send targeted messages through the messaging API. If you don’t assign a unique ID to a user, Braze will assign them an anonymous ID instead—however, you won’t be able to use these features until you do.

Setting a user ID

To set a user ID, call the changeUser() method after the user initially log ins. IDs should be unique and follow our naming best practices.

If you’re hashing a unique identifier instead, be sure to normalize the input of your hashing function. For example, when hashing an email address, remove any leading or trailing spaces and account for localization.

1
Braze.getInstance(context).changeUser(YOUR_USER_ID_STRING);
1
Braze.getInstance(context).changeUser(YOUR_USER_ID_STRING)
1
AppDelegate.braze?.changeUser(userId: "YOUR_USER_ID")
1
[AppDelegate.braze changeUser:@"YOUR_USER_ID_STRING"];

For a standard Web SDK implementation, you can use the following method:

1
braze.changeUser(YOUR_USER_ID_STRING);

If you’d like to use Google Tag Manager instead, you can use the Change User tag type to call the changeUser method. Use it whenever a user logs in or is otherwise identified with their unique external_id identifier.

Be sure to enter the current user’s unique ID in the External User ID field, typically populated using a data layer variable sent by your website.

A dialog box showing the Braze Action Tag configuration settings. Settings included are "tag type" and "external user ID".

1
BrazePlugin.changeUser("YOUR_USER_ID");
1
m.Braze.setUserId(YOUR_USER_ID_STRING)
1
AppboyBinding.ChangeUser("YOUR_USER_ID_STRING");
1
UBraze->ChangeUser(TEXT("YOUR_USER_ID_STRING"));

Setting a user alias

You can use a user alias to assign third-party IDs to a Braze user, so you can more-easily manage external data.

They consists of two parts: a name and a label. The name refers to the identifier itself, while the label refers to the type of identifier it belongs to. For example, if you have a user in a third-party customer support platform with the external ID 987654, you can assign them an alias in Braze with the name 987654 and the label support_id, so you can track them across platforms.

1
Braze.getInstance(context).getCurrentUser().addAlias(ALIAS_NAME, ALIAS_LABEL);
1
Braze.getInstance(context).currentUser?.addAlias(ALIAS_NAME, ALIAS_LABEL)
1
Appboy.sharedInstance()?.user.addAlias(ALIAS_NAME, ALIAS_LABEL)
1
 [[Appboy sharedInstance].user addAlias:ALIAS_NAME withLabel:ALIAS_LABEL];
1
braze.getUser().addAlias(ALIAS_NAME, ALIAS_LABEL);
1
2
3
4
{
  "alias_name" : (required, string),
  "alias_label" : (required, string)
}

ID Naming best practices

We recommend that you create user IDs using the Universally Unique Identifier (UUID) standard, meaning they are 128-bit strings that are random and well distributed.

Alternatively, you can hash an existing unique identifier (such as a name or email address) to generate your user IDs instead. If you do so, be sure to implement SDK authentication, so you can prevent user impersonation.

While its essential that you correctly name your user IDs from the start, you can always rename them in the future using the /users/external_ids/rename endpoint.

Recommended Not Recommended
123e4567-e89b-12d3-a456-836199333115 JonDoe829525552
8c0b3728-7fa7-4c68-a32e-12de1d3ed2d5 [email protected]
f0a9b506-3c5b-4d86-b16a-94fc4fc3f7b0 CompanyName-1-2-19
2d9e96a1-8f15-4eaf-bf7b-eb8c34e25962 jon-doe-1-2-19

Preserving anonymous user history

You can only preserve anonymous user history in the following cases. For more information, see Identified user profiles.

Case Explanation
User has not been previously identified Anonymous history is merged with user profile upon identification.
User has been previously identified in-app or via API Anonymous history is not merged with user profile upon identification.
HOW HELPFUL WAS THIS PAGE?
New Stuff!