When your application supports multiple user profiles on a single device, it's important to ensure that push notifications and user-specific data (like tags) are correctly associated with the currently active user. Pushwoosh allows a device to be associated with one User ID at a time. Here's how to manage this:
1. When a User Logs In or Switches Profiles:
- Update the User ID: After the user successfully logs in or switches to their profile, call the
setUserIdmethod from the Pushwoosh SDK, providing their unique User ID. This action links the device to this specific user.// Example: Pushwoosh.setUserId("USER_ID_FOR_CURRENT_PROFILE"); - Update User-Specific Tags: Immediately after calling
setUserId, you should also callsetTagsto apply tags relevant to the newly active user. This ensures that segmentation and targeting are accurate for the current user. User-specific tags are tied to the User ID, so updating the User ID and then setting tags ensures the correct tags are associated with the active user on that device.// Example: Pushwoosh.setTags({ "user_level": "premium", "interests": "sports" });
2. When a User Logs Out:
- Disassociate User ID: When a user logs out, call
setUserIdagain, passing an empty string (or an appropriate null/default value as per SDK documentation) to remove the association between the device and the logged-out user.// Example: Pushwoosh.setUserId("");
Important Considerations:
- Timing of
setUserId: ThesetUserIdmethod should typically be called after the Pushwoosh SDK has been initialized (e.g., afterPushwoosh.init()) and the device has been registered (e.g., afterPushwoosh.registerDevice()). Do not customize theregisterDevice()call for this purpose. - One Active User ID per Device: A device (identified by its Hardware ID - HWID) can only be associated with one User ID at any given time. Calling
setUserIdwith a new ID will overwrite the previous User ID association for that device. It is not possible to associate multiple User IDs with a single device simultaneously. - User-Specific vs. Device-Specific Tags:
- User-specific tags are tied to the User ID. They will reflect the data of the currently active user after
setUserIdandsetTagsare called. - Device-specific tags are associated only with the device (HWID) and are not affected by User ID changes.
- User-specific tags are tied to the User ID. They will reflect the data of the currently active user after
- Best Practice: Always update the User ID using
setUserIdand then immediately update the relevant tags usingsetTagseach time a user logs in or switches profiles. This ensures data consistency, as user information stored on the backend might become outdated between sessions.
This approach ensures that push notifications and user data are correctly managed for the active user profile on the shared device.
Comments
0 comments
Please sign in to leave a comment.