Why replacing previous notifications
By default, push notifications are standalone entities. They're displayed one by one in chronological order on a user's Android notification tray.
However, if you're likely to send many notifications in quick succession (e.g. if your app is a messaging service), it's probably best to merge them โ when you send one, it replaces earlier ones.
Using Progressier
If you're using Progressier to send push notifications, you can configure your integration to systematically replace previous notifications that may still be on a user lockscreen.
Simply go to Settings > Danger Zone > Push Settings and enable "Notification overwriting". From now on, all notifications sent from the dashboard and/or API will automatically overwrite previous push notifications.
Using the Web Push API
If you're handling notifications on your own, update the code displaying the notification in the push event listener of your service worker so that it includes a tag
. When a notification is displayed with a tag
, it will automatically replace other notifications using that same tag.
const title = "Notification title";
const options = {
tag: "name",
renotify: true,
};
registration.showNotification(title, options);
The renotify
parameter is optional. As the name suggests, this option allows you to make the receiving device vibrate and/or play a system sound (depending on users' device preferences) when a notification replaces one sent earlier.
Note that renotify
can only be set to true
and can only be used if your push notification options include a tag
. Setting renotify
to true when there is no tag will result in the following error, and the notification will not be shown.
TypeError: Failed to execute 'showNotification' on 'ServiceWorkerRegistration': Notifications which set the renotify flag must specify a non-empty tag