The WonderPushSDK exposed to plugins, that contain a few additional methods.
Extends
Namespaces
Methods
-
<static> checkTriggers(config, passCallback, rejectCallback)
-
Helper function to find out if a user meets a set of criteria before starting a subscription process.
Your plugin should check this before adding any visually intrusive elements to the browsed page. for prompting the user for subscription.
Giving no criterion makes the check pass. Note that the snoozing default value will apply. If the user manually unsubscribed, the check always rejects.
Unless configured otherwise, the WonderPushPluginSDK.resetTriggers function is automatically called when the check passes.
Parameters:
Name Type Description config
WonderPushPluginSDK.TriggersConfig Configures the various checks and behaviors that should be checked to trigger a subscription.
passCallback
function A callback function called with no arguments when the user meets the criteria. Its responsibility is to start the subscription process.
This function is called asynchronously, after the desired delay.
rejectCallback
function A callback function called with no arguments if the user does not meet the criteria.
This function is called asynchronously, with no specific delay.
-
<static> currentURLPassesFilters(urlFilters)
-
Checks if the current URL passes the provided WonderPushPluginSDK.URLFilters. The current URL is window.location. Returns true if there is no window object (in service worker context for instance).
Parameters:
Name Type Description urlFilters
WonderPushPluginSDK.URLFilters Returns:
- Type
- boolean
-
<static> loadStylesheet(relativePath)
-
Load stylesheets.
A check enforces the resource to lie under the same directory as the plugin, or any sub-directory.
Parameters:
Name Type Argument Description relativePath
string <repeatable>
The path of the stylesheet to load, relative to the plugin script file.
-
<static> log(args)
-
Logs a statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.log()
. -
<static> logDebug(args)
-
Logs a debug statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.debug()
. -
<static> logError(args)
-
Logs an error statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.error()
. -
<static> logInfo(args)
-
Logs an info statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.info()
. -
<static> logTrace(args)
-
Logs a trace statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.trace()
. -
<static> logWarn(args)
-
Logs a warn statement, with automatic tagging.
Parameters:
Name Type Argument Description args
args <repeatable>
The arguments to give to
console.warn()
. -
<static> resetTriggers()
-
Resets the information used by triggers in WonderPushPluginSDK.checkTriggers, because the user was prompted.
Notes the current triggers counters and statistics to serve as a new starting point for checking triggers before prompting the user for subscription. This permits waiting for some time or a given number of visits before having the triggers checks pass and prompting the user again.
Unless explicitly configured otherwise, WonderPushPluginSDK.checkTriggers calls this method automatically as a mean to ease plugin development. See that function's documentation to disable it and call this function manually.
Returns:
- Type
- Promise
-
<static> snoozeTriggers(value)
-
Forces the triggers of WonderPushPluginSDK.checkTriggers to not pass for some time.
The SDK already applies a softer and dynamically updatable snooze working without any user action, that aims at preventing to prompt the user at each page load. This functions however lets you decide of a more appropriate snooze duration depending on a user's action, like waiting for a week or a month depending on whether the "X" or the "Remind me later" button was clicked.
Parameters:
Name Type Description value
boolean | number Give a number of milliseconds to wait for that duration. Use
true
to snooze the triggers indefinitely. Usefalse
to stop snoozing.Returns:
- Type
- Promise
-
<static> waitTriggers(config)
-
Helper function to wait for the user to meet a set of criteria before starting a subscription process.
This works like WonderPushPluginSDK.checkTriggers excepts that instead of calling the reject callback, it continues to wait until the test passes, and then resolves the returned promise.
This along with WonderPush#addPageView allows to support Single Page Application by waiting for the right number of page views.
Parameters:
Name Type Description config
WonderPushPluginSDK.TriggersConfig Configures the various checks and behaviors that should be checked to trigger a subscription.
Returns:
Resolves once the check passes, not before.
- Type
- Promise.<void>
Type Definitions
-
TriggersConfig
-
Configures the various checks and behaviors that should be checked to trigger a subscription.
Using
undefined
,null
orfalse
will make the check reject.Using
true
will make the check unconditionally pass (no snoozing).Type:
- Object | undefined | null | boolean
Properties:
Name Type Argument Default Description minVisits
number <optional>
How many visits should the user have performed before triggering automatic subscription.
Visits are reported with the
@APP_OPEN
event in the user timeline on your dashboard.minVisitsSinceReset
number <optional>
How many visits should the user have performed since the last time this check passed.
minPages
number <optional>
How many pages should the user have viewed before triggering automatic subscription.
Depending on your website type, you may adjust this number. Unlike
minVisitPages
, this counts page views across visits. An alternative is to use theminVisits
criterion, that will count browsing sessions.The SDK can only count the pages it is included in.
minPagesSinceReset
number <optional>
How many page should the user have viewed since the last time this check passed.
minVisitPages
number <optional>
How many pages should the user have viewed within its current visit before triggering automatic subscription.
Depending on your website type, you may adjust this number. Unlike
minPages
, this counter automatically resets after each visit.The SDK can only count the pages it is included in.
delay
number <optional>
0 How long in milliseconds to delay the user subscription prompt. This way the user can be prompted 10 seconds after landing on the page.
minScrollPercent
number <optional>
An integer between 0 and 100 that is the minimum percent amount of scroll performed on the page or any other element.
minScrollPixels
number <optional>
An integer that is the minimum amount of pixels scrolled on the page or any other element.
snooze
number | false <optional>
43200000 How long to wait before automatically prompting the user for subscription again, in milliseconds. Or
false
to never try again.manual
boolean <optional>
false Setting this value to
true
will ensure that the check never succeeds. This is intended at disabling automatic triggers and letting the developer trigger the plugin manually.urlFilters
WonderPushPluginSDK.URLFilters <optional>
null Setting this value allows you to control which URLs are allowed to trigger.
autoReset
boolean <optional>
true By default when the check passes, WonderPushPluginSDK.resetTriggers is called. Plugins with more advanced needs may control when they call it by setting this option to
false
.waitForUserActivation
boolean <optional>
false When this is set to true, we'll wait for navigator.userActivation.isActive to be true before resolving.
-
URLFilters
-
Type:
- Object | undefined | null | URLFilters
Properties:
Name Type Description whiteList
Array.<string> | undefined A list of strings. At least one of those be contained in the URL for the URL to match.
blackList
Array.<string> | undefined A list of strings. None of those must be contained in the URL for the URL to match.