Web Push SDK Methods
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
Parameter | Type | Required | Description |
---|---|---|---|
match | object | Yes | Defines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource. |
update | object | No | Contains 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
Parameter | Type | Required | Description |
---|---|---|---|
match | object | Yes | Defines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource. |
update | object | No | Contains data to be added to a new or existing profile. |
inexclusive | boolean | No | If 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
Parameter | Type | Required | Description |
---|---|---|---|
subscribe update_subscription suspend_subscription | string | Yes | Name of the triggered event. |
callback | function | Yes | Function that will be called when the event occurs. For
|
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
Parameter | Type | Required | Description |
---|---|---|---|
match | object | Yes | Defines profile matching. If no profile database is provided for the search, the platform will search within the databases linked to the resource. |
update | object | No | Contains 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()