Skip to content

Set a custom User ID and link it to multiple devices

Pushwoosh offers several methods to assign and manage UserIDs:

By default, when an app with Pushwoosh SDK is launched for the first time, it sets a device HWID as a User ID. However, you can set a custom user ID at various points depending on the app’s design and user flow. For this, use the setUserId method provided by the Pushwoosh SDK.

Here are some key moments when you can set or update a custom User ID:

  • When the user registers in the app
  • When the user logs in
  • When the user makes a purchase or subscription
  • When the user interacts with specific features, etc.

iOS example

[[Pushwoosh sharedInstance] setUserId:@"userId"];

Android example

Pushwoosh.getInstance().setUserId("testUser");

When a user logs out, it’s recommended to reset their User ID to a default value using another setUserId call. When the user logs in again, update the User ID to the custom value specific to that user.

If the User ID changes (e.g., if one user logs out and another user logs in), call setUserId to update the User ID associated with that device. This ensures that the correct User ID is always linked to the device, allowing personalized notifications to be sent to the appropriate user.

Use the registerEmail or registerEmailUser API method to associate an external User ID with a specified email address.

Please note that registerEmailUser does not register an email address in your user base; it should be used only for assigning user IDs to email addresses that have been registered already by registerEmail request.

While primarily used to register a new device in Pushwoosh, this method can also set a User ID at the time of device registration.

If you pass a custom User ID in this call (for example, “userId”: “Alex”), it will be associated with the device. If no UserID is provided, the device will be associated with an anonymous User ID equal to the hardware ID (HWID)

To associate customer phone numbers with UserId using the /registerDevice method, please specify the phone number in the “hwid” parameter.

This API method allows you to associate an external User ID with a specified device or transfer a device between users while retaining device tags, for example when a user logs out and a new user logs in.

This method can be used before the device is registered or before obtaining the push token, for example, when you need to pre-register a user in Pushwoosh. Learn more