User IDs
Assign your own user IDs to integrate WonderPush with your systems
You can assign your own user IDs to installations in WonderPush. This allows you to target users by user ID and lets you tightly integrate WonderPush with your systems.
Assigning your own user IDs
Assigning your own user IDs depends on the platform (adapt THIS_USER_ID
) with your own user ID:
window.WonderPush = window.WonderPush || [];
WonderPush.push(['setUserId', "THIS_USER_ID"]);
WonderPush.setUserId("THIS_USER_ID")
[WonderPush setUserId:@"THIS_USER_ID"];
WonderPush.setUserId("THIS_USER_ID");
WonderPush.setUserId("THIS_USER_ID");
You only need to specify the userId
once: it persists until next time you specify a userId
or null
.
Removing a user ID
User IDS can be disassociated from the current device Installation id using the Wonderpush SDK unsetUserId
method. It is recommended to call this method when the user logs out of your app or website.
WonderPush.unsetUserId()
WonderPush.setUserId(null);
[WonderPush setUserId:nil];
WonderPush.setUserId(nil)
There are cases where the current user ID can change:
- when anonymous users log into your app / website, user ID goes from
null
to something, - when the user logs in with another account.
When the user ID changes, a new installation is created. This means that all the tags, properties and events you've sent before changing the user ID will not be attached to the new installation. This ensures that data doesn't get mixed up between different user accounts.
Targeting users with the API
You can use the targetUserIds
parameter of the Send notifications API call to target one or more users.
# Sending a notificaton to 2 users: userID1 and userID2
# Adapt ACCESS_TOKEN
curl -XPOST https://management-api.wonderpush.com/v1/deliveries?accessToken=ACCESS_TOKEN -d notification='{"alert":{"text":"test"}}' -d targetUserIds=userID1,userID2
// Sending a notificaton to 2 users: userID1 and userID2
// Adapt WONDERPUSH_ACCESS_TOKEN, WONDERPUSH_APPLICATION_ID
$client = new \WonderPush\WonderPush(WONDERPUSH_ACCESS_TOKEN, WONDERPUSH_APPLICATION_ID);
$client->deliveries()->create(array(
'notification' => array(
'alert' => array(
'text' => 'test',
),
),
'targetUserIds' => ['userID1','userID2'],
));
Targeting users via the online dashboard
To target one or more users from the target tab of the notification edition interface, setup a criterion of type User id is equal to.

Updated 5 months ago