Pushpad Logo Pushpad

Targeting users

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 Express
https://pushpad.xyz/projects/123/subscription/edit?uid=33&uid_signature=4b9503324d1c97ecfc551dbb377452c85da8ebb9
Pushpad Pro (Javascript SDK)
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).