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.
note:
For wrapper SDKs not listed, use the relevant native Android or Swift method instead.
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.

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"));
|
warning:
Do not assign a static default ID or call changeUser()
when a user logs out. Doing so will prevent you from re-engaging any previously logged-in users on shared devices. Instead, keep track of all user IDs separately and ensure your app’s logout process allows for switching back to a previously logged-in user. When a new session starts, Braze will automatically refresh the data for the newly-active profile.
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 |
warning:
Avoid sharing details about how you create user IDs, as this may expose your organization to malicious attacks or data removal.
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. |
note:
After you set a user ID, that profile cannot be reverted to an anonymous user.