Skip to main content

Web Push SDK Methods

tip

For more details on setting up Web Push campaigns on the platform and installing the SDK on your website, refer to this section.

This article describes the Web Push SDK methods and their possible parameters. Each method is also accompanied by a usage example.

initSubscription

This method initializes a subscription. It is used to record client data in a profile and perform a search among existing profiles.

Parameters

ParameterTypeRequiredDescription
matchobjectYesDefines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource.
updateobjectNoContains data to be added to a new or existing profile.

Usage Example

const akPush = new AKPush();
akPush.initSubscription(
{
db: 1
email: 'example@email.com'
}, // Searching for a profile by email. If no match is found, it will be recorded in the profile.

{
_fname: 'Anatoly',
_lname: 'Wasserman'
} // Recording the subscriber's first and last name in the profile
)

updateSubscription

This method updates profile data and modifies the status of push subscriptions.

Parameters

ParameterTypeRequiredDescription
matchobjectYesDefines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource.
updateobjectNoContains data to be added to a new or existing profile.
inexclusivebooleanNoIf the inexclusive flag is not provided or set to false:

1. If no database filter is specified, each database of the resource will have only one profile with one subscription for the current token with the status "Subscribed".
2. If a filter is specified, each specified database will have only one profile with one subscription for the current token with the "Subscribed" status. In other databases, all matching subscriptions to the resource for all profiles will be suspended.

If the inexclusive flag is set to true, the call is equivalent to AKPush.initSubscription, meaning the profile data will be updated and the subscription status changed to "Subscribed".

Usage Example

const akPush = new AKPush();
akPush.updateSubscription(
{
db: [15,20]
email: 'example@email.com'
},

{
_fname: 'Anatoly',
_lname: 'Wasserman'
}, // Recording the subscriber's first and last name in the profile
false // Whether to suspend all subscriptions to the resource with the current browser token for other profiles (default)
)

AKPush.events.on

This method subscribes to events related to push notifications.

Parameters

ParameterTypeRequiredDescription
subscribe
update_subscription
suspend_subscription
stringYesName of the triggered event.
callbackfunctionYes

Function that will be called when the event occurs. For subscribe, the returned parameters will be:

{
browser: "<subscriber's browser>"
provider: "<push provider>"
token: "<subscriber's token>"
}


For update_subscription and suspend_subscription, the returned parameters will be:

{
browser: "<subscriber's browser>"
provider: "<push provider>"
token: "<subscriber's token>"
tokenCached: "<cached subscriber's token>"
}

Usage Example

AKPush.events.on('subscribe', (data) => { // Subscribe to the subscribe event
console.log(data);
});
AKPush.events.on('update_subscription', (data) => { // Subscribe to the update_subscription event
console.log(data);
});

suspendSubscription

This method suspends a user's push notification subscription. The subscription can be resumed using the same method.

Parameters

ParameterTypeRequiredDescription
matchobjectYesDefines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource.
updateobjectNoContains data to be added to a new or existing profile.

Usage Example

AKPush.suspendSubscription(
{
db: 1
email: 'example@email.com'
},
{
_status: 'inactive'
} // Updating the subscriber's profile status
)

AKPush.removeToken

This method removes a device token from the cache. It is used, for example, when a user changes on the device. No parameters are required for this method.

Usage Example

AKPush.removeToken()