- 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
- Ionic
- Flutter
- Python
- macOS
- Angular
- Electron
- Cordova
- Capacitor
- PhoneGap
- React Native
- MAUI (Android)
- Xamarin (Android)
- 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.
Handle Notifications
Any notifications you send to your users are displayed in a browser push banner:
You can customize the notification title, message body, and image displayed, as well as the URL that will open when the notification is tapped by sending the following data
payload to the Send Notifications API:
{
"title": "Test Notification", // Notification title
"url": "https://pushy.me/", // Opens when tapped
"message": "Hello World!", // Notification body text
"image": "https://example.com/image.png" // Optional image
}
In case your web page is open, you can define a listener that will be invoked to execute any relevant action in response to the notification being received.
Optionally add the following code to handle notifications, after Pushy.register()
:
// Handle push notifications (only when web page is open)
Pushy.setNotificationListener(function (data) {
// Print notification payload data
console.log('Received notification: ' + JSON.stringify(data));
// Attempt to extract the "message" property from the payload: {"message":"Hello World!"}
let message = data.message || 'Test notification';
// Display an alert with message sent from server
alert('Received notification: ' + message);
});
Parse Notification Data
Any payload data that you send with your push notifications is made available to your web page via the data
parameter of the setNotificationListener
callback.
If you were to send a push notification with the following data
payload:
{"id": 1, "message": "Hello World!"}
Then you'd be able to retrieve these values in your setNotificationListener
callback like so:
let id = data.id;
let message = data.message;