Service worker events related to web push notifications - push-notification

In web push notifications documentation, I see that service worker can get triggered by few events like push, notificationclick. For tracking CTR, notificationclick event is very important. Similarly, is there any event like 'rejectnotification' that gets triggered when user rejects notification. So, service worker can track users rejecting notifications.

I assume that by rejected you mean close? If so there is no such event. There used to be an onclose event but is now deprecated.
https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclose

There is a notificationclose event, but only for persistent notifications.
https://notifications.spec.whatwg.org/#closing-a-notification

There is a notificationclose event as described here:
https://developers.google.com/web/updates/2016/03/notifications?hl=en

Related

Does FCM provides any methods for topic subscription similar to onNewToken?

FCM sends an event via onNewToken() whenever an app is installed in a device. Do we have any similar methods available to capture the event for topic subscription or unsubscription, when a device is subscribed to a topic (or) unsubscribed from a topic?
Looking for a way to store the topic subscription details along with the deviceToken for every topic created for an app.
I could not see any such methods similar to onNewToken() for topic subscription events.
Since the token can be refreshed by the server outside of the application's control, the server notifies the client when the topic changes.
Since your application itself subscribes to a topic, you already know when it happens and can track that yourself. So there is no server-to-client notification for when a client subscribes to a topic.

FCM web push message received in DevTools, but event not dispatched

I've been working in bulk web push notifications, migrating from OneSignal to Firebase. I've created a single FCM topic to which all users are subscribed immediately on startup.
At first messages arrive on the browser and the notification is shown correctly, but randomly after a few hours and in some devices, notifications cease to show. I've been recording every push message received using DevTools, and noticed that the messages are being received but the push event not dispatched in those cases.
In which cases something like this may happen? It's worth noting that the service worker has been healthly with no errors whatsoever.
Thanks

Firebase messaging not triggering onResume / onLaunch properly

There are no problems with the code, because if I press on the notification it triggers onResume, however if the app it's killed or the user deletes the notification no callbacks are triggered.
Right now I'm saving notifications locally on an SQL db, so when a user logs in back it shows how many notifications he hasn't read. However, If I can't trigger no callback when he deletes the notification or when the app is killed (Actually when the user logs in back, after a couple of seconds onMessage is called with the notification sent while the app was killed, however this still bothers me 'cause I can't get user's attention with notifications) I can't save them locally and when he logs in back in the app, those notifications that he dismissed won't ever be back.
Is there a way to callback a function when the user dismisses notifications or when my app is killed?
Basically as you know, notifications are designed to be removed by users.
So if you want users to see all the notifications from your service, you should consider with another UX something like notifications tab (Facebook, Instagram has)
And, manage all notifications from the server, set flag if it is been activated or not.
As far as I know, there is no callback when the user dismissed the one.
I hope it can help you to decide your service design.

Google calendar API notification

I'm making a web application which uses the Google calendar API. People can create events and see them in the application. When an user changes an event all the attendees of that event get an email about the change. For sending the email I use:
EventsResource.UpdateRequest updateRequest = new EventsResource.UpdateRequest(service, eventToUpdate, CalendarId, eventToUpdate.Id)
{
SendNotifications = true,
};
Now Google calendar monitors the event and when something changes a notification is send. But I can never find any documentation about when the notification is triggered. For as far as I now an email is send when the user changes the following: Summary and description.
Does anybody know all the elements that trigger the notification?
AFAIK, it is any changes in your resources that you currently under watch. Based from the documentation:
Currently, the Google Calendar API supports notifications for changes to the Acl, CalendarList, Events, and Settings resources.
It is safe to say that any changes from the about will trigger the application to send a notification.
Hope this helps.

Not Seeing "Opened" Firebase Notification Stats

I'm manually handling firebase notifications by overriding the onHandle intent of the FirebaseMessagingService.
And using the intent I generate a notification.
Is there a way to manually report the notification opened to the Firebase at all because I'm not getting opened statistics reported back to the firebase console.
As above, even when letting firebase notifications get handled per normal, these open notifications are not being reported either.
Thanks!
The stats shown in the notifications panel of the Firebase console are only for messages sent from that notification panel. There is currently no way to trigger the stats for messages sent through the Firebase Cloud Messaging API directly.
Update: since late 2018 the Firebase now also reports messages sent through called to the Firebase Cloud Messaging API.
According to https://firebase.google.com/docs/cloud-messaging/understand-delivery only "Sends" work for data-only messages:
Sends — The data message or notification message has been enqueued for delivery or has been successfully passed to a third-party service like APNs for delivery. See lifetime of a message for more information.
Impressions (available only for notification messages on Android devices) — The display notification has been displayed on the device.
Opens — The user opened the notification message.
For those curious to know my workaround at this time.
We run push campaigns.
For each campaign we created a distinct, reusable event.
We register the event "campaign_received" and "campaign_opened"
When a message is received, we trigger the event.
When the notification is opened, we trigger the event.
Then, under each event, we just select the event, and file their stats per day, week, month, etc.
One needs to select the event to get to the event dashboard area, since the event list view shows the total amount of events sent and or received.
For bespoke notifications the 500 event limit might be reached quite quickly, so be sure to bundle your notifications into reusable event categories if possible.

Resources