React Native SDK Reference
React Native SDK Reference
| |
Prompts user to subscribe to push notifications. | |
Unsubscribes user from push notifications. | |
Tells whether user is subscribed to push notifications. | |
| |
Sends an event with a name and payload of your choice. | |
Adds one or more tags to this installation. | |
Removes one or more tags from this installation. | |
Removes all tags from this installation. | |
Tests whether a given tag is attached to this installation. | |
Returns all the tags attached of this installation. | |
Returns the value of a given property associated to this installation. | |
Returns an immutable list of the values of a given property associated to this installation. | |
Adds the value to a given property associated to this installation. | |
Removes the value from a given property associated to this installation. | |
Sets the value to a given property associated to this installation. | |
Removes the value of a given property associated to this installation. | |
Associates the provided name/value pairs to this installation. | |
Returns all the name/value pairs associated to this installation using putProperties. | |
Returns the user's country. | |
Overrides the user's country. | |
Returns the user's currency. | |
Overrides the user's currency. | |
Returns the user's locale. | |
Overrides the user's locale. | |
Returns the user's time zone. | |
Overrides the user's time zone. | |
| |
Assigns your own user ID to an installation. | |
Returns the user ID you've assigned to this installation if any. | |
| |
Returns the installationId identifying this installation in your application. | |
Returns the push token (also called registration id by FCM). | |
| |
Provides privacy consent. | |
Sets whether user consent is required before the SDK is allowed to work. | |
Disables the collection of the user's geolocation. | |
Enables collection of the geolocation. | |
Overrides the user's current geolocation. | |
Clears all events recorded using trackEvent. | |
Clears all the name/value pairs associated to this installation using putProperties. | |
Deletes any event, installation and potential user objects associated with all installations present on the device. | |
Initiates the download of all the WonderPush data related to the current installation, in JSON format. | |
| |
Returns a | |
| |
Enables or disables verbose logging of WonderPush. |
Subscribing users
subscribeToNotifications
subscribeToNotificationsSubscribes 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
unsubscribeFromNotificationsUnsubscribes from push notifications. Returns a promise to await for completion. This method marks the user as soft opt-out.
await WonderPush.unsubscribeFromNotifications();isSubscribedToNotifications
isSubscribedToNotificationsReturns 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
trackEventTracks 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
addTagAdds 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
removeTagRemoves 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
removeAllTagsRemoves all tags from the current installation. Returns a promise to await for completion.
Example
await WonderPush.removeAllTags();hasTag
hasTagTests whether a given tag is attached to the current installation.
| Parameter | Type | Description |
|---|---|---|
tag | String | The tag to test. |
| Returns | Promise<boolean> | 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
getTagsReturns a promise resolving with all the tags attached to the current installation as an array of strings.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<Array<string>> | array of strings |
Example
const tags = await WonderPush.getTags();
console.log("User tags:", tags.join(', '));getPropertyValue
getPropertyValueReturns 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
getPropertyValuesReturns 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
addPropertyAdds 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
removePropertyRemoves 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
setPropertySets 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
unsetPropertyRemoves 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
putPropertiesUpdates 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
getPropertiesReturns a promise resolving with an object containing the properties of the current installation.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<Object> | The object containing the properties. |
Example
const properties = await WonderPush.getProperties();
console.log("Properties:", properties);getCountry
getCountryReturns 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<string> | The user's country. |
Example
const country = await WonderPush.getCountry();
console.log("Country:", currency);setCountry
setCountryOverrides 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
getCurrencyReturns a promise resolving with the user's currency, either as previously stored, or as guessed from the system.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string> | The user's currency. |
Example
const currency = await WonderPush.getCurrency();
console.log("Currency:", currency);setCurrency
setCurrencyOverrides 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
getLocaleReturns a promise resolving with the user's locale, either as previously stored, or as guessed from the system.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string> | The user's locale. |
Example
const locale = await WonderPush.getLocale();
console.log("Locale:", locale);setLocale
setLocaleOverrides 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
getTimeZoneReturns a promise resolving with the user's time zone, either as previously stored, or as guessed from the system.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string> | The user's time zone. |
Example
const timeZone = await WonderPush.getTimeZone();
console.log("Time zone:", timeZone);setTimeZone
setTimeZoneOverrides 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
setUserIdAssigns 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
getUserIdReturns a promise resolving with the userId you've assigned to this installation, or null by default.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string | null> |
Example
const userId = await WonderPush.getUserId();
console.log("UserId:", userId);Installation info
getInstallationId
getInstallationIdReturns a promise resolved with the Installation ID, or null if it is not available yet.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string | null> |
Note: The Installation ID is obtained asynchronously after the WonderPush SDK is initialized and has contacted the WonderPush servers. Changing the User ID will make the SDK use a new installation and this asynchronous process starts anew. Once the SDK has obtained an Installation ID, it will remember it for subsequent use and it will be available right away.
Example
const installationId = await WonderPush.getInstallationId();
console.log("InstallationId:", installationId);getPushToken
getPushTokenReturns a promise resolving with the push token of this installation, or null.
| Parameter | Type | Description |
|---|---|---|
| Returns | Promise<string | null> |
Example
const pushToken = await WonderPush.getPushToken();
console.log("Push token:", pushToken);Privacy
setUserConsent
setUserConsentSets 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
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
disableGeolocationDisables 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
enableGeolocationEnables 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
setGeolocationOverrides 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
clearEventsHistoryInstructs 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
clearPreferencesInstructs 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
clearAllDataInstructs 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
downloadAllDataInitiates the download of all the WonderPush data relative to the current installation, as JSON.
Example
await WonderPush.downloadAllData();Deep linking
getInitialURL
getInitialURLReturns 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
setLoggingEnables 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 27 days ago
