The public API of the SDK.
Namespaces
Members
-
<readonly> SessionState :integer
-
List of Session States
Type:
- integer
Properties:
Name Type Default Description INIT_FAILEDinteger -1 Session initialization failed
INIT_UNSTARTEDinteger 0 Session initialization is not started
INIT_INPROGRESSinteger 1 Session initialization is in progress
INIT_SUCCESSinteger 2 Session initilialization is successful
-
<readonly> SubscriptionState :integer
-
List of Subscription States
Type:
- integer
Properties:
Name Type Default Description DENIEDinteger -3 The client has denied push notification permission.
UNSUPPORTEDinteger -2 The client does not support native push notifications.
UNSUBSCRIBEDinteger -1 The client has manually unsubscribed from native push notifications.
UNDETERMINEDinteger 0 The real subscription state is not yet available.
NOT_SUBSCRIBEDinteger 1 The client is not yet subscribed to native push notifications.
SUBSCRIBEDinteger 2 The client is subscribed to native push notifications.
Methods
-
<static> getAttendance()
-
Return the user presence metrics.
Returns:
-
askNativePushNotificationPermission()
-
Ask the user for permission to receive push notifications. The user must grant the Notification permission in order to opt-in to push notifications.
- Deprecated:
-
- Yes
- See:
-
getDeviceId()
-
Returns the device id.
Returns:
- Type
- Promise.<string>
-
getInitializationPromise()
-
Get a promise which will be resolved at SDK initialization. This promise never rejects.
Returns:
- Type
- Promise
-
getInstallation()
-
Deprecated. Returns a synthetic installation object with some identifiers and the custom properties inside it.
Please use WonderPushSDK#getInstallationCustomProperties instead.
- Deprecated:
-
- Yes
Returns:
- Type
- Promise.<Object>
-
getInstallationCustomProperties()
-
Updates the installation custom properties.
Returns:
- Type
- Promise
-
getInstallationId()
-
Returns the installation id of the currently logged user.
Returns:
undefinedif the session is not initialized yet.- Type
- Promise.<string>
-
getNotificationEnabled()
-
Returns whether the user is subscribed to push notifications.
Returns:
enabled
- Type
- boolean
-
getNotificationIcon()
-
Returns the default notification icon.
Returns:
- Type
- string
-
getPushToken()
-
Returns the push token of the currently logged user.
Returns:
nullif the session is not initialized yet or the user is not subscribed.- Type
- Promise.<string>
-
getSessionState()
-
Get the session initialization state.
Returns:
-
isNativePushNotificationSupported()
-
Returns whether the current browser supports push notifications.
Returns:
- Type
- boolean
-
isOnRightDomain()
-
Returns whether the current script is executed on a domain valid for WonderPush push notifications.
Returns:
isOnRightDomain
- Type
- boolean
-
isRegistrationInProgress()
-
Returns whether a registration process is aleady taking place.
Returns:
- Type
- boolean
-
newPageLoaded()
-
Call this function whenever new page content is loaded, for instance using AJAX.
This increments the page views counter and may trigger automatic subscription, if configured this way.
Calling this function also helps the SDK to monitor the user activity.
If a
hashchangeevent is equivalent to a new page, then you'll want to bind a listener on this event and call this function. -
newUserInteraction()
-
Call this function whenever the user does any meaningful operation on the page, such as navigating to a new tab that does not trigger any AJAX calls or browsing events.
Calling this function also helps the SDK to monitor the user activity.
The SDK already monitors the
load,hashchangeandbeforeunloadevents. -
putInstallationCustomProperties(customData)
-
Updates the installation custom properties.
Parameters:
Name Type Description customDataobject Returns:
- Type
- Promise
-
setNotificationEnabled(enabled [, event])
-
Subscribes or unsubscribes to push notifications.
Parameters:
Name Type Argument Description enabledboolean Whether to subscribe or unsubscribe to push notifications.
eventEvent <optional>
If you call this function in response to a user event, give that event here. It will permit bypassing popup blockers to open any necessary popup to finalize the registration process, without requiring the user to click once again on a modal box.
-
trackEvent(type [, customData])
-
Tracks a custom event
Parameters:
Name Type Argument Description typestring The type of the event to track.
customDataobject <optional>
Optional custom properties associated to the event.
Returns:
- Type
- Promise
-
trackEventOnUnload(type [, customData])
-
Tracks a custom event.
Suitable for sending events from a
window.unloadlistener, not recommended otherwise.Uses
navigator.sendBeacon()to send the event.Parameters:
Name Type Argument Description typestring The type of the event to track.
customDataobject <optional>
Optional custom properties associated to the event.
-
unsubscribeFromPushNotification()
-
Unsubscribe the user from push notifications.
- Deprecated:
-
- Yes
- See:
Type Definitions
-
Attendance
-
Type:
- Object
Properties:
Name Type Description pageViewsnumber The number of page viewed by the user.
visitCountnumber The number of time the user visited the website.
Events
-
WonderPushCallMethodEvent
-
WonderPushEvent to indicate a method call.
Properties:
Name Type Description typestring "method"
methodstring The method name
argstring The method arg
-
WonderPushNotificationOpenedEvent
-
WonderPushEvent to indicate a click on a notification action of type "Let application code decide", e.g. a target URL of wonderpush://notificationOpen/broadcast
Properties:
Name Type Description typestring "notificationOpened"
eventObject The browser "notificationclick" event
WonderPushSDKWonderPushSDK The SDK instance
-
WonderPushSessionEvent
-
WonderPushEvent to indicate SDK initialization state.
- See:
Properties:
Name Type Description typestring "session"
stateWonderPushSDK.SessionState The session initialization state
WonderPushSDKWonderPushSDK The SDK instance
-
WonderPushSubscriptionEvent
-
WonderPushEvent to indicate push notification subscription state.
- See:
Properties:
Name Type Description typestring "subscription"
stateWonderPushSDK.SubscriptionState The push notification subscription state
WonderPushSDKWonderPushSDK The SDK instance
-
WonderPushTrackEventEvent
-
WonderPushEvent to indicate a that WonderPush.trackEvent was called
Properties:
Name Type Description typestring "trackEvent"
eventObject The data passed to trackEvent
Properties
Name Type Description typestring The type of trackEvent
customObject The custom properties passed to trackEvent
occurrencesObject A dictionary of occurrences with keys "allTime", "last1days", etc.
WonderPushSDKWonderPushSDK The SDK instance