The WonderPush Developer Hub

Welcome to the WonderPush developer hub. You'll find comprehensive guides and documentation to help you start working with WonderPush as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

React Native SDK Reference

React Native SDK Reference

Subscribing users

subscribeToNotifications

Prompts user to subscribe to web push notifications.

unsubscribeFromNotifications

Unsubscribes user from web push notifications.

isSubscribedToNotifications

Tells whether user is subscribed to web push notifications.

Segmentation

trackEvent

Sends an event with a name and payload of your choice.

addTag

Adds one or more tags to this installation.

removeTag

Removes one or more tags from this installation.

removeAllTags

Removes all tags from this installation.

hasTag

Tests whether a given tag is attached to this installation.

getTags

Returns all the tags attached of this installation.

getPropertyValue

Returns the value of a given property associated to this installation.

getPropertyValues

Returns an immutable list of the values of a given property associated to this installation.

addProperty

Adds the value to a given property associated to this installation.

removeProperty

Removes the value from a given property associated to this installation.

setProperty

Sets the value to a given property associated to this installation.

unsetProperty

Removes the value of a given property associated to this installation.

putProperties

Associates the provided name/value pairs to this installation.

getProperties

Returns all the name/value pairs associated to this installation using putProperties.

getCountry

Returns the user's country.

setCountry

Overrides the user's country.

getCurrency

Returns the user's currency.

setCurrency

Overrides the user's currency.

getLocale

Returns the user's locale.

setLocale

Overrides the user's locale.

getTimeZone

Returns the user's time zone.

setTimeZone

Overrides the user's time zone.

User IDs

setUserId

Assigns your own user ID to an installation.

getUserId

Returns the user ID you've assigned to this installation if any.

Installation info

getInstallationId

Returns the installationId identifying this installation in your application.

getPushToken

Returns the push token (also called registration id by FCM).

Privacy

setUserConsent

Provides privacy consent.

setRequiresUserConsent

Sets whether user consent is required before the SDK is allowed to work.

disableGeolocation

Disables the collection of the user's geolocation.

enableGeolocation

Enables collection of the geolocation.

setGeolocation

Overrides the user's current geolocation.

clearEventsHistory

Clears all events recorded using trackEvent.

clearPreferences

Clears all the name/value pairs associated to this installation using putProperties.

clearAllData

Deletes any event, installation and potential user objects associated with all installations present on the device.

downloadAllData

Initiates the download of all the WonderPush data related to the current installation, in JSON format.

Debug

setLogging

Enables or disables verbose logging of WonderPush.

Subscribing users

subscribeToNotifications

Subscribes to push notifications. Returns a promise to await for completion.

await WonderPush.subscribeToNotifications();

unsubscribeFromNotifications

Unsubscribes from push notifications. Returns a promise to await for completion.
This method marks the user as soft opt-out.

await WonderPush.unsubscribeFromNotifications();

isSubscribedToNotifications

Returns a promise resolving with a boolean, true meaning that the user is subscribed to notifications, false if user hasn't subscribed, has unsubscribed or if consent is required and not granted.

if (await WonderPush.isSubscribedToNotifications()) {
  console.log("User is subscribed");
} else {
  console.log("User is not subscribed");
}

Segmentation

Segmentation functions allow you to mark installations so they can be added to segments and you can send them targeted notifications later.

There are many ways of performing segmentation:

Tags are like labels you can stick on users. Use tags to create segments in your dashboard and send targeted push notifications. Example: all users that have the "customer" tag.

Events have a date, a type of your choice and attributes. Use events to create segments in your dashboard and send targeted push notifications. Example: all users that purchased in the last hour is a typical event-based segment.

Installation properties represent traits of the user. That's a good place to store age, gender and other data traditionally used for segmentation. Create property-based segments in your dashboard. Example: all users above 18 is a typical property-based segment.

trackEvent

Tracks a custom event of your choice. E.g. purchase.
Returns a promise to await for completion.

Parameter

Type

Description

type

String

Required The type of the event to track. Event names starting with @ are reserved for internal use and cannot be used here.

attributes

Object

Optional. Attributes associated with this event. See format of property names for detailed syntax.

Example

await WonderPush.trackEvent("purchase", {
  string_product: "Some product",
  float_price: 1.99,
});

addTag

Adds one or more tags to the current installation.
Returns a promise to await for completion.

Parameter

Type

Description

tag

String or Array of strings

A single tag, or an array of tags to be added.

Example

// One tag at a time
await WonderPush.addTag("customer");

// Multiple tags at once
await WonderPush.addTag(["economics", "sport", "politics"]);

removeTag

Removes one or more tags from the current installation.
Returns a promise to await for completion.

Parameter

Type

Description

tag

String or Array of strings

A tag, or list of tags, to be removed.

Example

// One tag at a time
await WonderPush.removeTag("customer");

// Multiple tags at once
await WonderPush.removeTag(["economics", "sport", "politics"]);

removeAllTags

Removes all tags from the current installation.
Returns a promise to await for completion.

Example

await WonderPush.removeAllTags();

hasTag

Tests whether a given tag is attached to the current installation.

Parameter

Type

Description

tag

String

The tag to test.

Returns

Promise

true if tag is attached, false if tag is not attached.

Example

const hasTag = await WonderPush.hasTag("customer");
console.log(hasTag ? "User is a customer" : "User is not a customer");

getTags

Returns a promise resolving with all the tags attached to the current installation as an array of strings.

Parameter

Type

Description

Returns

Promise<Array>

array of strings

Example

const tags = await WonderPush.getTags();
console.log("User tags:", tags.join(', '));

getPropertyValue

Returns a promise that resolves with the value of the given property associated to the current installation.

If the property stores an array, only the first value is returned. This way you don't have to deal with potential arrays if that property is not supposed to hold one. Resolves with null if the property is absent or has an empty array value.

Parameter

Type

Description

property

String

The name of the property whose value we'll retrieve

Returns

Promise

A single value or null if it is absent or has an empty array value.

Example

const value = await WonderPush.getPropertyValue("string_lastname");
console.log("Last name is", value);

getPropertyValues

Returns a promise that resolves with a list of the values of a given property associated to the current installation.

If the property does not store an array, an array is returned nevertheless. This way you don't have to deal with potential scalar values if that property is supposed to hold an array. Returns an empty array instead null if the property is absent. Returns an array wrapping any scalar value held by the property.

const values = await WonderPush.getPropertyValues("string_favoritePlayers");
console.log("Favorite players:", values.join(", "));

addProperty

Adds the value to a given property associated to the current installation.
Returns a promise to await for completion.

The stored value is made an array if not already one. If the given value is an array, all its values are added. If a value is already present in the stored value, it won't be added.

See format of property names for detailed syntax.

Parameter

Type

Description

name

String

The name of the property.

value

Scalar or Array

The value to add

// One value at a time
await WonderPush.addProperty("string_interests", "sports");

// Multiple values at once
await WonderPush.addProperty("string_interests", "sports", "entertainment"]);

removeProperty

Removes the value from a given property associated to the current installation.
Returns a promise to await for completion.

The stored value is made an array if not already one. If the given value is an array, all the given values are removed, even if it is present multiple times.

Parameter

Type

Description

name

String

The name of the property

value

Scalar or Array

The value to remove

Example

// One value at a time
await WonderPush.removeProperty("string_interests", "sports");

// Multiple values at once
await WonderPush.removeProperty("string_interests",["sports", "entertainment"]);

setProperty

Sets the value to a given property associated to the current installation.
Returns a promise to await for completion.

The previous value is replaced entirely. The value can be a String, Boolean, Number, Object, Array (which has the same effect as unsetProperty).

See format of property names for detailed syntax.

Parameter

Type

Description

name

String

The name of the property

value

Scalar or Array

The value to set

Example

// You can add a single value
await WonderPush.setProperty("bool_isCustomer", true);

// You can remove a field using null
await WonderPush.setProperty("int_age", null);

// You can add an array of values
await WonderPush.setProperty("string_interests",["sports", "entertainment"]);

unsetProperty

Removes the value of a given property associated to the current installation.
Returns a promise to await for completion.

The previous value is replaced with null.

Parameter

Type

Description

name

String

The property to unset.

Example

await WonderPush.unsetProperty("string_favoritePlayers");

putProperties

Updates the properties of the current installation. Omitting a previously set property leaves it untouched. To remove a property, you must pass it explicitly with a value of null.
Returns a promise to await for completion.

Parameter

Type

Description

properties

Object

Properties to add or update. See format of property names for detailed syntax.

Example

await WonderPush.putProperties({
  int_age: 34,
  string_name: "John Doe",
});

getProperties

Returns a promise resolving with an object containing the properties of the current installation.

Parameter

Type

Description

Returns

Promise

The object containing the properties.

Example

const properties = await WonderPush.getProperties();
console.log("Properties:", properties);

getCountry

Returns a promise resolving with the user's country as a string, either as previously stored, or as guessed from the system.

Parameter

Type

Description

Returns

Promise

The user's country.

Example

const country = await WonderPush.getCountry();
console.log("Country:", currency);

setCountry

Overrides the user's country.
Defaults to getting the country code from the system default locale.
Returns a promise to await for completion.

You should use an ISO 3166-1 alpha-2 country code, eg: US, FR, GB.
Use null to disable the override.

Parameter

Type

Desciption

country

String

Valid country for e.g. US

Example

await WonderPush.setCountry("US");

getCurrency

Returns a promise resolving with the user's currency, either as previously stored, or as guessed from the system.

Parameter

Type

Description

Returns

Promise

The user's currency.

Example

const currency = await WonderPush.getCurrency();
console.log("Currency:", currency);

setCurrency

Overrides the user's currency.
Defaults to getting the currency code from the system default locale.
Returns a promise to await for completion.

You should use an ISO 4217 currency code, eg: USD, EUR, GBP.
Use null to disable the override.

Parameter

Type

Description

currency

String

Valid currency for e.g. USD

Example

await WonderPush.setCurrency("USD");

getLocale

Returns a promise resolving with the user's locale, either as previously stored, or as guessed from the system.

Parameter

Type

Description

Returns

Promise

The user's locale.

Example

const locale = await WonderPush.getLocale();
console.log("Locale:", locale);

setLocale

Overrides the user's locale.
Defaults to getting the language and country codes from the system default locale.
Returns a promise to await for completion.

You should use an xx-XX form of RFC 1766, composed of a lowercase ISO 639-1 language code, an underscore or a dash, and an uppercase ISO 3166-1 alpha-2 country code.
Use null to disable the override.

Parameter

Type

Description

locale

String

Valid locale for e.g. en_US

Example

await WonderPush.setLocale("en_US");

getTimeZone

Returns a promise resolving with the user's time zone, either as previously stored, or as guessed from the system.

Parameter

Type

Description

Returns

Promise

The user's time zone.

Example

const timeZone = await WonderPush.getTimeZone();
console.log("Time zone:", timeZone);

setTimeZone

Overrides the user's time zone.
Defaults to getting the time zone code from the system default locale.
Returns a promise to await for completion.

You should use an IANA time zone database codes, Continent/Country style preferably like Europe/Paris, or abbreviations like CET, PST, UTC, which have the drawback of changing on daylight saving transitions.
Use null to disable the override.

Parameter

Type

Description

timeZone

String

Valid time zone for e.g. Europe/Paris

Example

await WonderPush.setTimeZone("Europe/Paris");

User IDs

setUserId

Assigns your own user ID to an installation. See User IDs.
Returns a promise to await for completion.

Parameter

Type

Description

userId

String

The user ID.

Example:

await WonderPush.setUserId("YOUR_OWN_USER_ID");

getUserId

Returns a promise resolving with the userId you've assigned to this installation, or null by default.

Parameter

Type

Description

Returns

Promise<string|null>

The userId used, or null.

Example

const userId = await WonderPush.getUserId();
console.log("UserId:", userId);

Installation info

getInstallationId

Returns a promise resolved with the installationId, or null if the WonderPush servers have not been contacted just yet.

Parameter

Type

Description

Returns

Promise<string|null>

The installationId, or null.

Example

const installationId = await WonderPush.getInstallationId();
console.log("InstallationId:", installationId);

getPushToken

Returns a promise resolving with the push token of this installation, or null.

Parameter

Type

Description

Returns

Promise<string|null>

The push token, or null.

Example

const pushToken = await WonderPush.getPushToken();
console.log("Push token:", pushToken);

Privacy

setUserConsent

Sets user privacy consent.
Returns a promise to await for completion.

Works in conjunction with the REQUIRES_USER_CONSENT configuration option.

If user consent is required, the SDK takes no action until user consent it provided by calling setUserConsent(true). Calling setUserConsent(false) blocks the SDK again.

Parameter

Type

Description

consent

Boolean

Whether the user gave his/her consent.

Example

await WonderPush.setUserConsent(true);

setRequiresUserConsent

Sets whether user consent is required before the SDK takes any action.
Returns a promise to await for completion.

Calling this method with true is only useful if you do not use the automatic initialization, otherwise you should rather use the Requires user consent configuration option. You can also set the latter to true and later call this function with false if your application detects that this restriction is not necessary.

If you do not use the automatic initialization, call this method before initializing the SDK.

By default, user consent is not required.
Note that the value is not remembered between runs, it is rather a mode that you enable.

Parameter

Type

Description

consent

Boolean

Whether the user gave his/her consent.

Example

await WonderPush.setRequiresUserConsent(true);

disableGeolocation

Disables the collection of the user's geolocation.
Returns a promise to await for completion.

You can call this method before initializing the SDK.

Example

await WonderPush.disableGeolocation();

enableGeolocation

Enables the collection of the user's geolocation.
Returns a promise to await for completion.

You can call this method before initializing the SDK.

You still need the appropriate geolocation permissions in your AndroidManifest.xml for Android and Info.plist for iOS to be able to read the user's location.

Example

await WonderPush.enableGeolocation();

setGeolocation

Overrides the user's geolocation.
Returns a promise to await for completion.

You can call this method before initializing the SDK.

Using this method you can have the user's location be set to wherever you want.
This may be useful to use a pre-recorded location.

Note that the value is not persisted.

Calling this method with null has the same effect as calling disableGeolocation().

Example

await WonderPush.setGeolocation(37.0902, 95.7129);

clearEventsHistory

Instructs to delete any event associated with the all installations present on the device, locally and on WonderPush servers.
Returns a promise to await for completion.

Example

await WonderPush.clearEventsHistory();

clearPreferences

Instructs to delete any custom data (including installation properties) associated with the all installations present on the device, locally and on WonderPush servers.
Returns a promise to await for completion.

Example

await WonderPush.clearPreferences();

clearAllData

Instructs to delete any event, installation and potential user objects associated with all installations present on the device, locally and on WonderPush servers.
Returns a promise to await for completion.

Example

await WonderPush.clearAllData();

downloadAllData

Initiates the download of all the WonderPush data relative to the current installation, as JSON.

Example

await WonderPush.downloadAllData();

Debug

setLogging

Enables or disables verbose logging of WonderPush.
Returns a promise to await for completion.

Parameter

Type

Description

enable

Boolean

Whether to enable verbose logging of the WonderPush SDK.

Example

await WonderPush.setLogging(true);

Updated 3 months ago

React Native SDK Reference


React Native SDK Reference

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.