Subscription to web push notifications feature

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.

  

This article is part of the guide to creating a custom integration.
If your integration is via a module, this tag will be added to your ecommerce site automatically.

 

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="
    }
}

 

 

Congratulations!
You’ve reached the end of the tutorial.

  

Do you have questions?
Don’t forget, our Connectif specialists are here to help you. To contact them, just open a Support ticket by clicking the blue “Help” button on your dashboard.


Keep learning!

To make the most of your Connectif account, we recommend reading these articles next:

Was this article helpful?
0 out of 0 found this helpful