When a user is active on multiple devices, device-specific tags can become outdated on one device when updated on another. This can lead to users receiving incorrect notifications based on old information.
The best practice to ensure data consistency is to use User-Specific Tags. These tags are associated with a User Profile (identified by a UserID) and apply to all devices linked to that user.
How to Implement User-Specific Tags
Instead of setting tags for each device (hwid), you should set them for the user (userId). When a user's data changes, a single API call to update the user-level tag will synchronize the information across all their devices.
Example Scenario:
- A user logs into their iPad. Your system assigns a user-specific tag via the API:
client_ids: [1, 2, 3]. - Later, the user logs into their iPhone. Their account information changes, and beneficiary
3is removed. - Your backend system makes a single API call to update the tag for that user's
UserID, setting the new value:client_ids: [1, 2]. - This change is applied to the user's profile. Now, both the iPad and the iPhone are associated with the updated tag
client_ids: [1, 2]. - If you later send a notification targeting users where the
client_idstag contains3, this user will be correctly excluded, and neither of their devices will receive the notification.
Correctly Using the /setTags API
To update tags from your backend, use the /setTags method. Ensure your API request is structured correctly:
- Use the current endpoint:
https://api.pushwoosh.com/json/1.3/setTags - Pass your Device API Token in the
Authorizationheader. - In the request body, specify the
userIdto apply the tag at the user level.
Here is a sample cURL request to set a user-specific tag:
curl --location 'https://api.pushwoosh.com/json/1.3/setTags' \
--header 'Authorization: Token YOUR_DEVICE_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"request": {
"application": "YOUR_APP_CODE",
"userId": "USER_ID_TO_UPDATE",
"tags": {
"client_ids": [1, 2]
}
}
}'
By managing tags at the user level, you maintain data consistency and ensure your targeting is always based on the most current information, regardless of which device the user is currently using.
Comments
0 comments
Please sign in to leave a comment.