Web Push Notifications
Push notification functionality is implemented according to the HTTP Push RFC8030 standard, which is supported by all modern web browsers, including the latest version of Safari.
Integrating Push Notifications with Bird Web SDK into your website consists of the following steps:
-
Add <script> tag associated with your Bird Application by the data-config-url at your website:Contoh kode
<script src="https://embeddables.p.mbirdcdn.net/sdk/v0/bird-sdk.js" data-config-url="{applications_key_url}" ></script> -
Add /service-worker.js file with the following content:Contoh kode
importScripts('https://embeddables.p.mbirdcdn.net/sdk/v0/bird-push-sw.js');
It must be hosted at your website domain like https://yourwebsite.domain/service-worker.js
Note: you also could set another filename in the Bird Applications setting if you need to.
- Once Bird SDK init we can subscribe to Push Notifications by Bird.pushNotifications.subscribe()
You must have your users interact with your site before you are allowed to ask for notification permissions.
-
Add the subscribe call for example with a button click:Contoh kode
subscribeButton.addEventListener('click', async () => { await Bird.pushNotifications.subscribe(); });