The public API of the SDK.
Namespaces
Members
-
<readonly> SessionState :integer
-
List of Session States
Type:
- integer
Properties:
Name Type Default Description INIT_FAILED
integer -1 Session initialization failed
INIT_UNSTARTED
integer 0 Session initialization is not started
INIT_INPROGRESS
integer 1 Session initialization is in progress
INIT_SUCCESS
integer 2 Session initilialization is successful
-
<readonly> SubscriptionState :integer
-
List of Subscription States
Type:
- integer
Properties:
Name Type Default Description DENIED
integer -3 The client has denied push notification permission.
UNSUPPORTED
integer -2 The client does not support native push notifications.
UNSUBSCRIBED
integer -1 The client has manually unsubscribed from native push notifications.
UNDETERMINED
integer 0 The real subscription state is not yet available.
NOT_SUBSCRIBED
integer 1 The client is not yet subscribed to native push notifications.
SUBSCRIBED
integer 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:
undefined
if 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:
null
if 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
hashchange
event 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
,hashchange
andbeforeunload
events. -
putInstallationCustomProperties(customData)
-
Updates the installation custom properties.
Parameters:
Name Type Description customData
object Returns:
- Type
- Promise
-
setNotificationEnabled(enabled [, event])
-
Subscribes or unsubscribes to push notifications.
Parameters:
Name Type Argument Description enabled
boolean Whether to subscribe or unsubscribe to push notifications.
event
Event <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 type
string The type of the event to track.
customData
object <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.unload
listener, not recommended otherwise.Uses
navigator.sendBeacon()
to send the event.Parameters:
Name Type Argument Description type
string The type of the event to track.
customData
object <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 pageViews
number The number of page viewed by the user.
visitCount
number The number of time the user visited the website.
Events
-
WonderPushCallMethodEvent
-
WonderPushEvent to indicate a method call.
Properties:
Name Type Description type
string "method"
method
string The method name
arg
string 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 type
string "notificationOpened"
event
Object The browser "notificationclick" event
WonderPushSDK
WonderPushSDK The SDK instance
-
WonderPushSessionEvent
-
WonderPushEvent to indicate SDK initialization state.
- See:
Properties:
Name Type Description type
string "session"
state
WonderPushSDK.SessionState The session initialization state
WonderPushSDK
WonderPushSDK The SDK instance
-
WonderPushSubscriptionEvent
-
WonderPushEvent to indicate push notification subscription state.
- See:
Properties:
Name Type Description type
string "subscription"
state
WonderPushSDK.SubscriptionState The push notification subscription state
WonderPushSDK
WonderPushSDK The SDK instance
-
WonderPushTrackEventEvent
-
WonderPushEvent to indicate a that WonderPush.trackEvent was called
Properties:
Name Type Description type
string "trackEvent"
event
Object The data passed to trackEvent
Properties
Name Type Description type
string The type of trackEvent
custom
Object The custom properties passed to trackEvent
occurrences
Object A dictionary of occurrences with keys "allTime", "last1days", etc.
WonderPushSDK
WonderPushSDK The SDK instance