You can register callback functions which will get executed once the user gets successfully subscribed/fails to get subscribed to push notifications. The same is pushed into the global _pcq queue. Refer to the syntax below:

Successful Subscription CallBack

Parameters:

  1. subscriptionSuccessCallback: Command to register the callback function to be executed when the user gets successfully subscribed to push notifications.
  2. callbackFunctionName: This is the name of the callback function. We will return the subscriberId as a parameter to this callback function and another object with two parameters:

i) status: String with value as 'SUBSCRIBED' or 'ALREADYSUBSCRIBED'
ii) message: String which denotes whether user is a new subscriber or whether user was already previously subscribed.

Refer to the syntax below:

_pcq.push(['subscriptionSuccessCallback', callbackFunctionName]);

window._pcq = window._pcq || [];
_pcq.push(['subscriptionSuccessCallback',callbackFunctionOnSuccessfulSubscription]); //registers callback function to be called when user gets successfully subscribed

function callbackFunctionOnSuccessfulSubscription(subscriberId, values) {
    console.log('User got successfully subscribed.');

    console.log(subscriberId); //will output the user's subscriberId

    console.log(values.status); // SUBSCRIBED or ALREADYSUBSCRIBED

    console.log(values.message) // 'User has subscribed to push notifications.' or 'User is already subscribed to push notifications.'

    console.log('Now you may run code which should be executed once user gets successfully subscribed.');
}

Subscription Failure CallBack

Parameters:

  1. subscriptionFailureCallback: Command to register the callback function to be executed when the subscription fails.
  2. callbackFunctionName: This is the name of the callback function. We will return an object with two parameters.

i) status: String with value as 'BLOCKED', 'UNSUBSCRIBED' or 'CANCELLED'
ii) message as to why the subscription failed.

Refer to the syntax below:

_pcq.push(['subscriptionFailureCallback', callbackFunctionName]);

window._pcq = window._pcq || [];
_pcq.push(['subscriptionFailureCallback',callbackFunctionOnFailedSubscription]); //registers callback function to be called when user gets successfully subscribed

function callbackFunctionOnFailedSubscription(values) {
    console.log('User could not get subscribed to push notifications');

    console.log(values.status); // BLOCKED , UNSUBSCRIBED or CANCELLED

    console.log(values.message) // 'User has blocked push notifications.', 'User has unsubscribed from push notifications', 'No change in subscription. Child window was closed.' or 'User has closed the notifications opt-in.'

    console.log('Now you may run code which should be executed once user subscription fails');
}