- Home
- Documentation
- Client Setup
- iOS
- Create App
- Get the SDK
- Enable Capability
- Register Devices
- Handle Notifications
- Subscribe to Topics
- Setup APNs Authentication
- Send Test Notification
- Android
- Create App
- Get the SDK
- Register Devices
- Modify Launcher Activity
- Modify AndroidManifest
- Setup BroadcastReceiver
- Parse Notification Data
- Subscribe to Topics
- Send Test Notification
- Web Push
- Create App
- Get the SDK
- Register Visitors
- Handle Notifications
- Subscribe to Topics
- Send Test Notification
- Additional Platforms
- Migration Guides
- Backend Setup
-
API Reference - SDK Reference
- Additional Resources
Got Feedback?
We'd love to hear what you have to say about our documentation. Let us know how we can improve it.
Register Visitors
Your website visitors need to be uniquely identified to receive push notifications.
Every visitor is assigned a unique device token that you can use to push it at any given time. Once the visitor has been assigned a device token, it should be stored in your application's backend database.
Web Push Registration
Add the following code to register the visitor's browser for push notifications.
Please make sure to populate the appId
variable with your Pushy App ID (Pushy Dashboard -> Click your app -> App Settings -> App ID):
// Add an import if you installed from npm
import Pushy from 'pushy-sdk-web';
// Register visitor's browser for push notifications
Pushy.register({ appId: 'your-app-id' }).then(function (deviceToken) {
// Print device token to console
console.log('Pushy device token: ' + deviceToken);
// Send the token to your backend server via an HTTP GET request
//fetch('https://your.api.hostname/register/device?token=' + deviceToken);
// Succeeded, optionally do something to alert the user
}).catch(function (err) {
// Handle registration errors
console.error(err);
});
Note: Registration will fail if the user declines the Web Push permission dialog, in which case notification preferences for your hostname must be cleared in the browser settings for the dialog to be displayed again:
- Firefox: Enter
about:preferences#content
in the address bar - Chrome: Enter
chrome://settings/content/notifications
in the address bar