Batch SDK - Web
    Preparing search index...

    Interface IPublicAPI

    interface IPublicAPI {
        doesExistingSubscriptionKeyMatchCurrent: () => Promise<boolean>;
        eventAttributeTypes: typeof TypedEventAttributeType;
        getConfiguration: () => ISDKConfiguration;
        getInstallationID: () => Promise<string>;
        getNotificationPermission: () => Promise<NotificationPermission>;
        getSubscription: () => Promise<unknown>;
        getSubscriptionState: () => Promise<ISubscriptionState>;
        getUserLanguage: () => Promise<string | null>;
        getUserRegion: () => Promise<string | null>;
        isSubscribed: () => Promise<boolean>;
        on: (eventCode: SDKEvent, callback: unknown) => void;
        refreshServiceWorkerRegistration: () => Promise<void>;
        setup: (config: ISDKConfiguration) => void;
        subscribe: () => Promise<boolean>;
        trackEvent: (name: string, eventDataParams?: EventDataParams) => void;
        tryToSubscribeFrom: (state: ISubscriptionState) => Promise<boolean>;
        ui: IUiAPI;
        unsubscribe: () => Promise<boolean>;
        userAttributeTypes: typeof UserAttributeType;
        clearInstallationData(): Promise<void>;
        getUserAttributes(): Promise<{ [key: string]: IUserAttribute }>;
        getUserTagCollections(): Promise<{ [key: string]: string[] }>;
        profile(): Promise<IProfile>;
    }
    Index
    doesExistingSubscriptionKeyMatchCurrent: () => Promise<boolean>

    Checks if the currently installed service worker's push subscription can be used with the VAPID public key (aka applicationServerKey) defined in the current Batch configuration.

    This method can be used to detect a VAPID public key change, which can happen:

    • If you already were using Batch but changed the key
    • If you are using Batch for the first time but another push provider was configured and held a registration

    If there is no worker or no push subscription, the promise resolves to true as a subscription would most likely succeed.

    eventAttributeTypes: typeof TypedEventAttributeType

    Event Attribute Types. See TypedEventAttributeType.

    getConfiguration: () => ISDKConfiguration

    Get the current configuration

    getInstallationID: () => Promise<string>

    Returns the installation identifier

    getNotificationPermission: () => Promise<NotificationPermission>

    Returns the permission state of notifications. Having the permission to display notifications doesn't mean that this installation is subscribed to push notifications.

    • granted : we have the permission
    • denied : we don't have the permission
    • default : we don't have, have to ask the user
    getSubscription: () => Promise<unknown>

    Returns the raw subscription associated to this installation. Having a subscription doesn't necessarily mean the installation is subscribed, the user may have unsubscribed or refused notification. Call #isSubscribed() or #getSubscriptionState() to know the exact state of this subscription.

    getSubscriptionState: () => Promise<ISubscriptionState>

    Returns the subscription state including :

    • permission : determines the notification permission
    • subscribed : determines whether the user is subscribed and the permission is granted
    getUserLanguage: () => Promise<string | null>

    Returns the user language associated to this installation

    getUserRegion: () => Promise<string | null>

    Returns the user region associated to this installation

    isSubscribed: () => Promise<boolean>

    Determines whether this installation is subscribed to push notifications and can receive notifications (browser notification permission granted, see #getNotificationPermission)

    on: (eventCode: SDKEvent, callback: unknown) => void

    Listen to api events

    SDKEvent enum.

    refreshServiceWorkerRegistration: () => Promise<void>

    Refresh the service worker registration. If you do anything to the service worker registration while Batch is running, please call this method, as the SDK caches it for performance.

    Note: depending on Batch's configuration, it might register the service worker as it would have on next page load.

    setup: (config: ISDKConfiguration) => void

    Configure the SDK with the given configuration map. Can only be called once.

    Note: while this is available on the API object, the supported way is to call this using the "short" syntax. Example: batchSDK("setup", {...})

    subscribe: () => Promise<boolean>

    Subscribe this installation to notification. Returns true if the installation is subscribed, false otherwise.

    trackEvent: (name: string, eventDataParams?: EventDataParams) => void

    Track an event.

    Type Declaration

      • (name: string, eventDataParams?: EventDataParams): void
      • Parameters

        • name: string

          The event name. Must be a string made of letters, underscores and numbers only (a-zA-Z0-9_). It also can't be longer than 30 characters.

        • OptionaleventDataParams: EventDataParams

          eventDataParams (optional). Parameter object, accepting label, attributes and tags, all optional.

          attributes: Must be an object. The key should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 30 characters.

          Attribute typing is optional. Supported types:

          • Date, the value must be a Date
          • URL, the value must be a string or URL
          • String, the value must be a string or number
          • Integer, the value must be a string or number
          • Double, the value must be a string or number
          • Boolean, the value must be a boolean or number
          • Array, the value must be an array of strings
          • Object, the value must be an object containing the above types

          Type auto-detection is possible.

          If you were previously using labeland tagsyou can specify in the attributesobject the reserved keys: $tags: Must be n array of string. Can't be longer than 64 characters, and can't be empty or null. $label: Must be a string when supplied. It also can't be longer than 200 characters.

        Returns void

    tryToSubscribeFrom: (state: ISubscriptionState) => Promise<boolean>

    Try to subscribe from the given subscription state. Force asking the permission even if the permission is granted

    #getSubscriptionState to get the "state" parameter value

    ui: IUiAPI

    UI related methods

    unsubscribe: () => Promise<boolean>

    Unsubscribe this installation from notification. Returns true if the installation is unsubscribed, false otherwise.

    userAttributeTypes: typeof UserAttributeType

    User Attribute Types. See UserAttributeType.

    • Clear the custom data of this installation.

      This mean removing all attributes attached to the user's installation but Profile's data will not be removed.

      Returns Promise<void>

    • Read the saved tag collections. Returns a Promise that resolves with the tag collections.

      Returns Promise<{ [key: string]: string[] }>