Web Push Notifications done right

Maxim Salnikov
Maxim SalnikovDeveloper Engagement Lead at Microsoft
WEB PUSH
NOTIFICATIONS
DONE RIGHT
Maxim Salnikov
@webmaxru
What is web push
and how to start using it the right way
Maxim Salnikov
• Developer Engagement Lead at Microsoft
• Web Platform tech speaker, writer, trainer
TWITTER: @WEBMAXRU GITHUB: @WEBMAXRU SETTINGS
webmax.ru
Icon Title Body Actions Image
Why Push Notifications?
• Delivered regardless of app/browser state
• High opt-in (79.5%) and direct open (5%) rates*
• Delivery channel is free and reliable
• Rich format capabilities for better engagement
• Easy and fast to set up and start sending
*Data: Airship 2023 Push Notification Benchmarks, median for Android
Milestones
2000
Push Service in
Blackberry –
instant
notification
about a new
email received
2009
Apple Push
Notification
Service on iOS
3.0
Google’s
Android Cloud
To Device
Messaging
2013
Google Cloud
Messaging for
Chrome Apps
and Extensions
APNS for Safari
on OS X 10.9
2015
Web Push API in
Chrome 42
Web Push API in
Firefox 44
Windows
Notification
Service extended
2023
In production on
all major
platforms – after
iOS 16.4 and
Safari on macOS
13 joined.
https://caniuse.com/push-api
80%
of the users
Availability
Web Push prerequisites
• Notifications API and Web Push API are available
• Service Worker is registered and active
• Valid code for the “push” event
• Notifications are allowed for the origin and browser
• On iOS: app is added to the Home Screen
• Device is online
Subscription
User’s device
Backend
2. pushManager.subscribe()
3. pushSubscription {}
"pushSubscription": {
"endpoint": "https://...",
"keys": {
"p256dh": "BKfnjyWE...",
"auth": "iklyQDz..."
}
}
web.push.apple.com
fcm.googleapis.com
push.services.mozilla.com
notify.windows.com
Messaging service
VAPID public key
VAPID private key
Sending notification
User’s device
Backend
Messaging service
2. “push” event to SW + payload
addEventListener('push', (event) => {
showNotification(payload);
});
npm install web-push
'notificationclick'
'notificationclose'
LET’S SUBSCRIBE
Notification permission request -> Subscribing -> Saving subscription
9/3/20XX
Politeness is a must
• Consider alternatives first
• Initiate subscription flow only after explicit user action
• Show pre-request UI with a content and frequency explained
• Confirm by UI that unsubscribing is possible at any time
• Separate notification permission request and subscription
Requesting permission
Notification.requestPermission().then((result) => {
if (result !== 'granted') {
// Plan B on convincing user needed
} else {
// OK to proceed with subscription
}
});
Subscribing
navigator.serviceWorker.getRegistration().then((registration) =>
{
registration.pushManager
.subscribe({
userVisibleOnly: true,
applicationServerKey: VAPID_PUBLIC_KEY,
})
.then((pushSubscription) => {
// Send pushSubscription to the backend. Add context.
});
});
TIME TO PUSH!
Call messaging service -> Process “push” event -> Process actions
9/3/20XX
Notification object
{
"title": "Push.Foo Notification Title",
"actions": [
{
"action": "open_project_repo",
"title": "Show source code"
}
],
"body": "Test notification body",
"image": "https://push.foo/images/social.png",
"icon": "https://push.foo/images/logo.jpg",
"badge": "https://push.foo/images/logo-mask.png",
"requireInteraction": "true",
"tag": "tag"
}
Your best notification
• Transactional, not promotional
• Timely, personal, relevant
• Contains information itself, not just “click to see”
• Contains call-to-action
• Does not repeat itself
• Use emoji🤷
Your OSL->LHR flight✈️
Click here to check-in
fooairline.com
FooAirline ltd.
Online check-in is available
fooairline.com
You can use “push” event to
• Fetch extra data from the backend to use in the notification
• Message a client – for example, to update app UI or icon via
Badging API
• Gather analytics
• Call self.registration.showNotification() – it’s the
only required action
In the service worker
self.addEventListener('push', (event) => {
notification = event.data.json();
const showNotificationPromise = self.registration.showNotification(
notificationData.title,
notificationData
);
const promiseChain = Promise.allSettled([
messageClientPromise,
showNotificationPromise,
]);
event.waitUntil(promiseChain);
});
Use “notificationclick” to
• Open a browser or installed app
• Focus an existing tab with the app
• Use feature detection to check if multiple actions are
available
if ('actions' in window.Notification?.prototype) {}
• Attach analytics code
Summary
• Web Push feature is very
powerful for the businesses and
convenient for the users
• Currently available on all major
platforms
• To keep it relevant, it’s
important to avoid misusing
• Services like OneSignal, Pusher,
Airship etc. can help with a
backend component (and not
only)
IMAGE: PUSH NOTIFICATIONS UI KIT BY ONESIGNAL
Instant Web Push
notification test
- Playground for the Web Push API
- Entire flow from requesting permission to
sending the notification
- Sending to multiple devices
- Specifications, API references, guides + this
deck
HTTPS://PUSH.FOO
LET’S CONNECT
AND CHAT
Maxim Salnikov
salnikov@gmail.com
@webmaxru
1 of 22

Recommended

Prompt Engineering - an Art, a Science, or your next Job Title? by
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
61 views33 slides
ChatGPT and not only: how can you use the power of Generative AI at scale by
ChatGPT and not only: how can you use the power of Generative AI at scaleChatGPT and not only: how can you use the power of Generative AI at scale
ChatGPT and not only: how can you use the power of Generative AI at scaleMaxim Salnikov
37 views42 slides
Using the power of OpenAI with your own data: what's possible and how to start? by
Using the power of OpenAI with your own data: what's possible and how to start?Using the power of OpenAI with your own data: what's possible and how to start?
Using the power of OpenAI with your own data: what's possible and how to start?Maxim Salnikov
56 views38 slides
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel... by
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...Maxim Salnikov
32 views23 slides
Prompt Engineering - an Art, a Science, or your next Job Title? by
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Maxim Salnikov
261 views28 slides
ChatGPT and not only: How to use the power of GPT-X models at scale by
ChatGPT and not only: How to use the power of GPT-X models at scaleChatGPT and not only: How to use the power of GPT-X models at scale
ChatGPT and not only: How to use the power of GPT-X models at scaleMaxim Salnikov
87 views32 slides

More Related Content

More from Maxim Salnikov

The Status of Angular v13 by
The Status of Angular v13The Status of Angular v13
The Status of Angular v13Maxim Salnikov
101 views35 slides
Azure cloud for the web frontend developers by
Azure cloud for the web frontend developersAzure cloud for the web frontend developers
Azure cloud for the web frontend developersMaxim Salnikov
75 views13 slides
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего... by
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...Maxim Salnikov
309 views166 slides
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт by
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опытMaxim Salnikov
224 views81 slides
Securing Connected Cars Requires Digital Identity by
Securing Connected Cars Requires Digital IdentitySecuring Connected Cars Requires Digital Identity
Securing Connected Cars Requires Digital IdentityMaxim Salnikov
189 views40 slides
How to Make Your IoT Devices Secure, Act Autonomously & Trusted Subjects by
How to Make Your IoT Devices Secure, Act Autonomously & Trusted SubjectsHow to Make Your IoT Devices Secure, Act Autonomously & Trusted Subjects
How to Make Your IoT Devices Secure, Act Autonomously & Trusted SubjectsMaxim Salnikov
139 views26 slides

More from Maxim Salnikov(6)

Azure cloud for the web frontend developers by Maxim Salnikov
Azure cloud for the web frontend developersAzure cloud for the web frontend developers
Azure cloud for the web frontend developers
Maxim Salnikov75 views
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего... by Maxim Salnikov
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...
[Russian] Сервис-воркеры: используем накопленные знания для светлого будущего...
Maxim Salnikov309 views
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт by Maxim Salnikov
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт
[Russian] Прогрессивные веб-приложения: по-настоящему кросс-платформенный опыт
Maxim Salnikov224 views
Securing Connected Cars Requires Digital Identity by Maxim Salnikov
Securing Connected Cars Requires Digital IdentitySecuring Connected Cars Requires Digital Identity
Securing Connected Cars Requires Digital Identity
Maxim Salnikov189 views
How to Make Your IoT Devices Secure, Act Autonomously & Trusted Subjects by Maxim Salnikov
How to Make Your IoT Devices Secure, Act Autonomously & Trusted SubjectsHow to Make Your IoT Devices Secure, Act Autonomously & Trusted Subjects
How to Make Your IoT Devices Secure, Act Autonomously & Trusted Subjects
Maxim Salnikov139 views

Recently uploaded

AI and Ml presentation .pptx by
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptxFayazAli87
11 views15 slides
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsRa'Fat Al-Msie'deen
5 views49 slides
Fleet Management Software in India by
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
11 views1 slide
Headless JS UG Presentation.pptx by
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptxJack Spektor
7 views24 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
5 views46 slides
Agile 101 by
Agile 101Agile 101
Agile 101John Valentino
7 views20 slides

Recently uploaded(20)

AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik5 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin95 views
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares7 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
Tridens DevOps by Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 views
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... by Deltares
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
Deltares5 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy13 views

Web Push Notifications done right

  • 2. What is web push and how to start using it the right way
  • 3. Maxim Salnikov • Developer Engagement Lead at Microsoft • Web Platform tech speaker, writer, trainer TWITTER: @WEBMAXRU GITHUB: @WEBMAXRU SETTINGS webmax.ru Icon Title Body Actions Image
  • 4. Why Push Notifications? • Delivered regardless of app/browser state • High opt-in (79.5%) and direct open (5%) rates* • Delivery channel is free and reliable • Rich format capabilities for better engagement • Easy and fast to set up and start sending *Data: Airship 2023 Push Notification Benchmarks, median for Android
  • 5. Milestones 2000 Push Service in Blackberry – instant notification about a new email received 2009 Apple Push Notification Service on iOS 3.0 Google’s Android Cloud To Device Messaging 2013 Google Cloud Messaging for Chrome Apps and Extensions APNS for Safari on OS X 10.9 2015 Web Push API in Chrome 42 Web Push API in Firefox 44 Windows Notification Service extended 2023 In production on all major platforms – after iOS 16.4 and Safari on macOS 13 joined.
  • 7. Web Push prerequisites • Notifications API and Web Push API are available • Service Worker is registered and active • Valid code for the “push” event • Notifications are allowed for the origin and browser • On iOS: app is added to the Home Screen • Device is online
  • 8. Subscription User’s device Backend 2. pushManager.subscribe() 3. pushSubscription {} "pushSubscription": { "endpoint": "https://...", "keys": { "p256dh": "BKfnjyWE...", "auth": "iklyQDz..." } } web.push.apple.com fcm.googleapis.com push.services.mozilla.com notify.windows.com Messaging service VAPID public key VAPID private key
  • 9. Sending notification User’s device Backend Messaging service 2. “push” event to SW + payload addEventListener('push', (event) => { showNotification(payload); }); npm install web-push 'notificationclick' 'notificationclose'
  • 10. LET’S SUBSCRIBE Notification permission request -> Subscribing -> Saving subscription 9/3/20XX
  • 11. Politeness is a must • Consider alternatives first • Initiate subscription flow only after explicit user action • Show pre-request UI with a content and frequency explained • Confirm by UI that unsubscribing is possible at any time • Separate notification permission request and subscription
  • 12. Requesting permission Notification.requestPermission().then((result) => { if (result !== 'granted') { // Plan B on convincing user needed } else { // OK to proceed with subscription } });
  • 13. Subscribing navigator.serviceWorker.getRegistration().then((registration) => { registration.pushManager .subscribe({ userVisibleOnly: true, applicationServerKey: VAPID_PUBLIC_KEY, }) .then((pushSubscription) => { // Send pushSubscription to the backend. Add context. }); });
  • 14. TIME TO PUSH! Call messaging service -> Process “push” event -> Process actions 9/3/20XX
  • 15. Notification object { "title": "Push.Foo Notification Title", "actions": [ { "action": "open_project_repo", "title": "Show source code" } ], "body": "Test notification body", "image": "https://push.foo/images/social.png", "icon": "https://push.foo/images/logo.jpg", "badge": "https://push.foo/images/logo-mask.png", "requireInteraction": "true", "tag": "tag" }
  • 16. Your best notification • Transactional, not promotional • Timely, personal, relevant • Contains information itself, not just “click to see” • Contains call-to-action • Does not repeat itself • Use emoji🤷 Your OSL->LHR flight✈️ Click here to check-in fooairline.com FooAirline ltd. Online check-in is available fooairline.com
  • 17. You can use “push” event to • Fetch extra data from the backend to use in the notification • Message a client – for example, to update app UI or icon via Badging API • Gather analytics • Call self.registration.showNotification() – it’s the only required action
  • 18. In the service worker self.addEventListener('push', (event) => { notification = event.data.json(); const showNotificationPromise = self.registration.showNotification( notificationData.title, notificationData ); const promiseChain = Promise.allSettled([ messageClientPromise, showNotificationPromise, ]); event.waitUntil(promiseChain); });
  • 19. Use “notificationclick” to • Open a browser or installed app • Focus an existing tab with the app • Use feature detection to check if multiple actions are available if ('actions' in window.Notification?.prototype) {} • Attach analytics code
  • 20. Summary • Web Push feature is very powerful for the businesses and convenient for the users • Currently available on all major platforms • To keep it relevant, it’s important to avoid misusing • Services like OneSignal, Pusher, Airship etc. can help with a backend component (and not only) IMAGE: PUSH NOTIFICATIONS UI KIT BY ONESIGNAL
  • 21. Instant Web Push notification test - Playground for the Web Push API - Entire flow from requesting permission to sending the notification - Sending to multiple devices - Specifications, API references, guides + this deck HTTPS://PUSH.FOO
  • 22. LET’S CONNECT AND CHAT Maxim Salnikov salnikov@gmail.com @webmaxru