When your app supports several user profiles on one device, make sure push notifications and user data always follow the profile that is currently active. In Pushwoosh a device (identified by its HWID) is linked to exactly one User ID at a time.
1. When a user logs in or switches profiles:
-
Set the User ID. After login, call the SDK's
setUserIdmethod with that profile's identifier. The device is transferred to the new user, keeping its device tags.// iOS (Swift) Pushwoosh.sharedInstance().setUserId("USER_ID_FOR_CURRENT_PROFILE") // Android (Java/Kotlin) Pushwoosh.getInstance().setUserId("USER_ID_FOR_CURRENT_PROFILE"); // Web SDK Pushwoosh.push(function (api) { api.registerUser("USER_ID_FOR_CURRENT_PROFILE"); }); -
Refresh user tags. Right after
setUserId, callsetTagswith the values that belong to the new profile, so segmentation and personalization are correct for the active user.Pushwoosh.sharedInstance().setTags(["user_level": "premium", "interests": "sports"])
2. When a user logs out:
- Call
setUserIdagain with a default value - the documented approach is to reset it to the device's original HWID, which is what an anonymous device uses. Do not pass an empty string: it is not a valid identifier and does not reliably detach the profile.// Reset to the anonymous default (device HWID) Pushwoosh.sharedInstance().setUserId(Pushwoosh.sharedInstance().getHWID())
Important considerations:
-
Timing: call
setUserIdafter the SDK is initialized and the device is registered for push notifications. -
One active User ID per device: calling
setUserIdwith a new value overwrites the previous association. A device cannot belong to two User IDs at once. - Device limit per user: a User ID can hold up to 20 devices. When a 21st is added, Pushwoosh removes one existing device (the oldest inactive non-email device) instead of rejecting the registration.
- User vs device tags: user-specific tags follow the User ID and change with the profile; device-specific tags stay with the HWID and are unaffected by User ID changes.
- Transition side effect: when a device moves between users, device tags are preserved while user-specific tags are re-read from the new user's profile (or reset to defaults if the user is new).
See Users (User IDs).
Comments
0 comments
Please sign in to leave a comment.