React Native SDK Reference

React Native SDK Reference

### Subscribing users
subscribeToNotificationsPrompts user to subscribe to push notifications.
unsubscribeFromNotificationsUnsubscribes user from push notifications.
isSubscribedToNotificationsTells whether user is subscribed to push notifications.
### Segmentation
trackEventSends an event with a name and payload of your choice.
addTagAdds one or more tags to this installation.
removeTagRemoves one or more tags from this installation.
removeAllTagsRemoves all tags from this installation.
hasTagTests whether a given tag is attached to this installation.
getTagsReturns all the tags attached of this installation.
getPropertyValueReturns the value of a given property associated to this installation.
getPropertyValuesReturns an immutable list of the values of a given property associated to this installation.
addPropertyAdds the value to a given property associated to this installation.
removePropertyRemoves the value from a given property associated to this installation.
setPropertySets the value to a given property associated to this installation.
unsetPropertyRemoves the value of a given property associated to this installation.
putPropertiesAssociates the provided name/value pairs to this installation.
getPropertiesReturns all the name/value pairs associated to this installation using putProperties.
getCountryReturns the user's country.
setCountryOverrides the user's country.
getCurrencyReturns the user's currency.
setCurrencyOverrides the user's currency.
getLocaleReturns the user's locale.
setLocaleOverrides the user's locale.
getTimeZoneReturns the user's time zone.
setTimeZoneOverrides the user's time zone.
### User IDs
setUserIdAssigns your own user ID to an installation.
getUserIdReturns the user ID you've assigned to this installation if any.
### Installation info
getInstallationIdReturns the installationId identifying this installation in your application.
getPushTokenReturns the push token (also called registration id by FCM).
### Privacy
setUserConsentProvides privacy consent.
setRequiresUserConsentSets whether user consent is required before the SDK is allowed to work.
disableGeolocationDisables the collection of the user's geolocation.
enableGeolocationEnables collection of the geolocation.
setGeolocationOverrides the user's current geolocation.
clearEventsHistoryClears all events recorded using trackEvent.
clearPreferencesClears all the name/value pairs associated to this installation using putProperties.
clearAllDataDeletes any event, installation and potential user objects associated with all installations present on the device.
downloadAllDataInitiates the download of all the WonderPush data related to the current installation, in JSON format.
### Deep linking
getInitialURLReturns a Promise to the URL of the deep link clicked in a push notification that launched the app.
### Debug
setLoggingEnables or disables verbose logging of WonderPush.

Subscribing users

subscribeToNotifications

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

await WonderPush.subscribeToNotifications();

// You can also use this variation that will show an alert dialog
// to Android users who have repeatedly denied the permission, taking them to the settings
// of your app where they can flip the permission switch:
await WonderPush.subscribeToNotifications(true);

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.

ParameterTypeDescription
typeStringRequired The type of the event to track. Event names starting with @ are reserved for internal use and cannot be used here.
attributesObjectOptional. 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.

ParameterTypeDescription
tagString or Array of stringsA 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.

ParameterTypeDescription
tagString or Array of stringsA 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.

ParameterTypeDescription
tagStringThe tag to test.
ReturnsPromisetrue 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.

ParameterTypeDescription
ReturnsPromise<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.

ParameterTypeDescription
propertyStringThe name of the property whose value we'll retrieve
ReturnsPromiseA 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.

ParameterTypeDescription
nameStringThe name of the property.
valueScalar or ArrayThe 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.

ParameterTypeDescription
nameStringThe name of the property
valueScalar or ArrayThe 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.

ParameterTypeDescription
nameStringThe name of the property
valueScalar or ArrayThe 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.

ParameterTypeDescription
nameStringThe 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.

ParameterTypeDescription
propertiesObjectProperties 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.

ParameterTypeDescription
ReturnsPromiseThe 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.

ParameterTypeDescription
ReturnsPromiseThe 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.

ParameterTypeDesciption
countryStringValid 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.

ParameterTypeDescription
ReturnsPromiseThe 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.

ParameterTypeDescription
currencyStringValid 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.

ParameterTypeDescription
ReturnsPromiseThe 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.

ParameterTypeDescription
localeStringValid 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.

ParameterTypeDescription
ReturnsPromiseThe 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.

ParameterTypeDescription
timeZoneStringValid 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.

ParameterTypeDescription
userIdStringThe 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.

ParameterTypeDescription
ReturnsPromise<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.

ParameterTypeDescription
ReturnsPromise<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.

ParameterTypeDescription
ReturnsPromise<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.

ParameterTypeDescription
consentBooleanWhether 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.

ParameterTypeDescription
consentBooleanWhether 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();

Deep linking

getInitialURL

Returns a Promise to the URL of the deep link clicked in a push notification that launched the app. See Setting up deep linking from push notifications in your ReactNative app.

const initialUrl = await Linking.getInitialURL() || await WonderPush.getInitialURL();

Debug

setLogging

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

ParameterTypeDescription
enableBooleanWhether to enable verbose logging of the WonderPush SDK.

Example

await WonderPush.setLogging(true);