When a visitor subscribes to web push notifications before logging in, they are registered as an anonymous subscriber: their User ID is automatically set equal to the device Hardware ID (HWID).
To attach that existing subscription to a known user after login or sign-up, call registerUser() from the Web SDK.
Here's how:
- Anonymous subscription: a visitor subscribes while not logged in; their User ID equals the device HWID.
- User authentication: the visitor logs in or registers on your site.
-
Set the real User ID: call
registerUser()with your own unique identifier. Theapiobject is not a global - the SDK passes it to the callback you queue withPushwoosh.push():
You can also pass the User ID up front in the// Run this after the user has successfully logged in or registered. Pushwoosh.push(function (api) { api.registerUser('YOUR_USER_ID'); });initcall (userId: 'YOUR_USER_ID') when it is already known at page load.
The device is then transferred from the anonymous user to the User ID you provided, and you can target the subscriber through their user profile. Note that device tags are preserved during the transfer, while user-specific tags are re-read from the new user's profile (or reset to defaults if the user is new).
References: Web Push SDK 3.0, User-centric API - registerUser, Users (User IDs).
Comments
0 comments
Please sign in to leave a comment.