The feature "connectif.subscribeToPushNotifications" is used to request subscriptions to web push notifications from the store or web via JavaScript. This feature can be used within Connectif web content to request a Push subscription.
How to use it
The "connectif.subscribeToPushNotifications" feature makes a request for permission, if the contact has not previously granted it, to subscribe to Web Push notifications.
It works asynchronously, so you can pass a "callback", function, which will execute the object of type "Subscription" as a result of the subscription.
Example
Once the feature is included, it will look like this:
connectif.subscribeToPushNotifications(function (error, subscription){ if(error){ return console.error(error); } if(subscription){ console.log('The contact has been subscribed successfully'); }else{ console.log('The contact has not been subscribed'); } });
A "Subscription" type object will have the following structure:
{ endpoint : 'https://fcm.googleapis.com/fcm/send/cCQFUMtzMf4hdph0-h5kYOWSik5sj990D', expirationTime : null, keys : { auth : "Lhjk-p4B8977fdeYMDAKi2A==", p256dh : "Hjkjyh79m-kjlH_bz5_bxD2Vk6Zx1ACsmiqHAtW6UrU=" } }
Keep learning!
To make the most of your Connectif account, we recommend reading these articles next:
- Web push notification editor, to design the content of your web push notifications.
- Push subscription with browser notification, to trigger the browser web push subscription notification without sending web content.
-
Ask for subscription to web push notifications with a popup, to create a strategy that subscribes contacts by means of a popup.
-
Push subscription with slide-in, to create a strategy that subscribes contacts by means of a slide in.