If the user is logged in on your website and you want to be able to send notifications targetted specifically to him, you can keep track of his id by adding a
uid param. For example:
pushpad('uid', '33', '4b9503324d1c97ecfc551dbb377452c85da8ebb9');
uid_signature is the HMAC-SHA1 signature of the user id. The string is hex-encoded. The key is the user token that can be found in account settings.
You can use the libraries to easily generate the signature. For example:
pushpad('uid', '<?= $current_user_id ?>', '<?= Pushpad::signature_for($current_user_id); ?>');
Warning: if you use a token with full access to generate the signature, that signature is valid for any project of your account. A user may use the signature to subscribe with the same uid to any of your projects. For this reason you should always use tokens with restricted access to generate the signatures.
Warning: the signature is only checked before setting the user ID associated to the subscription. However the user ID can be removed and tags can be altered even without the signature.
If you adopt the method above when you subscribe users to push notifications, it's easy to target specific users or group of users when you send the notifications.
The advantage of this method is that you will never have the problem of keeping the data synchronized between your server and Pushpad, since the only piece of information is the
uid which never changes (use the primary key of the user in your database for example).
Is a user subscribed to push notifications?
Sometimes you might want to know whether a user is subscribed to your push notifications. This can be used for example to customize the appearances of the page or to provide a fallback for users who are not subscribed (e.g. send them an email).
When a user is surfing your website you can use the
statuscallback is useless, and you must detect this second case with the
When you send a push notification with the libraries or the REST API, you can read the returned
uidsarray to determine which of the users you specified as recipients are actually subscribed to your notifications. For example if you set
["user1", "user2"]as the recipients, but only the first is subscribed, the you get
["user1"]in response (and the delivery to
"user2"is simply ignored). This is only available if you specify some
uidsin the request: it's not available for broadcast notifications.
You can retrieve the subscriptions for a given
uidfrom the dashboard or with the REST API.