- From: Maxim Salnikov <notifications@github.com>
- Date: Wed, 04 Sep 2024 07:28:44 -0700
- To: w3c/push-api <push-api@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/push-api/issues/386/2329222562@github.com>
Hello!
@collimarco, I believe @myupchar is talking about tracking, not requesting content for the notification. In that case, calling analytics API inside `push` event is valid idea.
I'd improve @nerdysherpas code a bit to leverage `waitUntil` method to have better chance that the browser will not unload service worker earlier than needed
Example similar to the one from my "[Web Push Notifications Done Right](https://www.slideshare.net/slideshow/web-push-notifications-done-right/257599974)" session:
```
self.addEventListener('push', (event) => {
notification = event.data.json();
const analyticsPromise = ... // calling Analytics API
const showNotificationPromise = self.registration.showNotification(
notificationData.title,
notificationData
);
const promiseChain = Promise.allSettled([
analyticsPromise,
showNotificationPromise,
]);
event.waitUntil(promiseChain);
});
```
@myupchar you can also get extra insights about interactions with your notifications by calling analytics API inside `notificationclick` and `notificationclose` events also available in the service worker.
--
Reply to this email directly or view it on GitHub:
https://github.com/w3c/push-api/issues/386#issuecomment-2329222562
You are receiving this because you are subscribed to this thread.
Message ID: <w3c/push-api/issues/386/2329222562@github.com>
Received on Wednesday, 4 September 2024 14:28:47 UTC