This module provides an API for the usage of the Selligent SDK in React Native.
- Android
- iOS
IMPORTANT: Since version 2.6.0 of this module we require your app to use the Android Gradle Plugin version 4.2.0 or higher in order to build on Android. This is the default Android Gradle Plugin version since React Native version 0.64.0 but can be manually increased in older versions of React Native.
IMPORTANT Since version 2.10.0 of this module, we support React Native v0.70, but NOT REACT NATIVE'S NEW ARCHITECTURE! The following library contains React native modules, that are tailored to and can only be used in React Native's legacy architecture, that will be deprecated in the future when the new architecture will be stable.
This module uses the native Selligent SDKs:
SDK | Version |
---|---|
Android | 4.0.1 |
iOS | 2.7.7 |
-
Install the module
npm install @selligent-marketing-cloud/selligent-react-native --save
-
Create a
selligent.json
file (name is case sensitive) in the root of the React Native project with the following content:{ "url": "someMobilePushUrl", "clientId": "someClientId", "privateKey": "somePrivateKey", "fullyQualifiedNotificationActivityClassName": "com.some.project.MainActivity" }
Note: The values should be relevant to your configuration. There are parameters that can only be used on a specific platform, but can be passed to either and will be ignored when possible.
Detailed overview:
Property | Type | Required | Platform |
---|---|---|---|
url | string | Yes | Both |
clientId | string | Yes | Both |
privateKey | string | Yes | Both |
clearCacheIntervalValue | enum Selligent.ClearCacheIntervalValue | No | Both |
configureLocationServices | boolean | No | Both |
inAppMessageRefreshType | enum Selligent.InAppMessageRefreshType | No | Both |
addInAppMessageFromPushToInAppMessageList | boolean | No | Both |
remoteMessageDisplayType | enum Selligent.RemoteMessagesDisplayType | No | Both |
appGroupId | string | No | iOS Only |
shouldClearBadge | boolean | No | iOS Only |
shouldDisplayRemoteNotification | boolean | No | iOS Only |
shouldPerformBackgroundFetch | boolean | No | iOS Only |
doNotListenToThePush | boolean | No | Android Only |
doNotFetchTheToken | boolean | No | Android Only |
loadCacheAsynchronously | boolean | No | Android Only |
fullyQualifiedNotificationActivityClassName | string | No | Android Only |
notificationIconColor | string | No | Android Only |
notificationChannelId | string | No | Android Only |
notificationChannelName | string | No | Android Only |
notificationChannelDescription | string | No | Android Only |
​
In order to use this module on Huawei devices (without Goggle Play services), you should add the following dependencies in the
build.gradle
files of the Android project in your React Native project:In your Android project's root
build.gradle
file:buildscript { repositories { maven { url 'https://developer.huawei.com/repo/' } } dependencies { classpath 'com.huawei.agconnect:agcp:1.6.0.300' } } allProjects: { repositories: { maven { url 'https://developer.huawei.com/repo/' } } }In your app module's
build.gradle
file:apply plugin: 'com.huawei.agconnect' dependencies { api 'com.huawei.hms:base:6.2.0.300' api 'com.huawei.hms:push:6.1.0.300' api 'com.huawei.hms:maps:6.2.0.301' }
Without autolinking (RN 0.59 and below)
-
Create a Google application following the section Creating a Google application of the Android - Using the SDK pdf, and place the
google-services.json
file in the./android/app
folder. -
Add the following lines at the end of the
android/settings.gradle
file:include ':selligent-react-native' project(':selligent-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@selligent-marketing-cloud/selligent-react-native/android')
-
Add the following in the
android/build.gradle
file, and make sure the the the Gradle version inandroid/gradle/wrapper/gradle-wrapper.properties
is >= 6.7.1:// android/build.gradle buildscript { ... dependencies { ... // Make sure your Gradle plugin version is >= 4.2.0 classpath("com.android.tools.build:gradle:4.2.0") // Add the following: classpath 'com.google.gms:google-services:4.3.3' } } allprojects { repositories { ... // Add the following: flatDir { dirs "$rootDir/../node_modules/@selligent-marketing-cloud/selligent-react-native/android/libs" } // Add the following: maven { url 'https://maven-repo.plotprojects.com' } } }
// android/gradle/wrapper/gradle-wrapper.properties ... distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip ...
-
Add the following in the
android/app/build.gradle
file:dependencies { // Add the following: compile project(path: ':selligent-react-native') ... } ... // Add the following: apply plugin: 'com.google.gms.google-services'
-
Add the following in the
android/app/src/../MainApplication.java
file:// Add the following import statements: import com.selligent.RNSelligent; import com.selligent.RNSelligentPackage; ... public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ... @Override protected List<ReactPackage> getPackages() { List<ReactPackage> packages = new PackageList(this).getPackages(); // Add the following: packages.add(new RNSelligentPackage()); return packages; } ... }; ... @Override public void onCreate() { super.onCreate(); ... // Add the following: RNSelligent.configure(this); } }
With autolinking (RN 0.60 and above)
-
Create a Google application following the section Creating a Google application of the Android - Using the SDK pdf, and place the
google-services.json
file in the./android/app
folder. -
Add the following lines at the end of the
android/settings.gradle
file:include ':selligent-react-native' project(':selligent-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@selligent-marketing-cloud/selligent-react-native/android')
-
Add the following in the
android/build.gradle
file, and make sure the the the Gradle version inandroid/gradle/wrapper/gradle-wrapper.properties
is >= 6.7.1:// android/build.gradle buildscript { ... dependencies { ... // Make sure your Gradle plugin version is >= 4.2.0 classpath("com.android.tools.build:gradle:4.2.0") // Add the following: classpath 'com.google.gms:google-services:4.3.3' } } allprojects { repositories { ... // Add the following: flatDir { dirs "$rootDir/../node_modules/@selligent-marketing-cloud/selligent-react-native/android/libs" } // Add the following: maven { url 'https://maven-repo.plotprojects.com' } } }
// android/gradle/wrapper/gradle-wrapper.properties ... distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip ...
-
Add the following in the
android/app/build.gradle
file:// Add the following: apply plugin: 'com.google.gms.google-services'
-
Add the following in the
android/app/src/../MainApplication.java
file:// Add the following import statements: import com.selligent.RNSelligent; import com.selligent.RNSelligentPackage; ... public class MainApplication extends Application implements ReactApplication { ... @Override public void onCreate() { super.onCreate(); ... // Add the following: RNSelligent.configure(this); } }
Add the following properties to the selligent.json
file:
"notificationSmallIcon": "ic_notification",
"notificationLargeIcon": "ic_notification"
Note: only parse the name of the icon, without the path. The icon should reside in the res/drawable folder of the Android project, as explained in Android's official guide.
Without autolinking (RN 0.59 and below)
-
Copy the
node_modules/@selligent-marketing-cloud/selligent-react-native/ios/SelligentReactNative.xcodeproj
file to the Xcode project. Drop it under theLibraries
Folder. This will link the module to the iOS project. (See the image in the next step) -
Drag and drop the
selligent.json
you created from the root folder to the Xcode project inside theCopy Bundle Resources
inBuild phases
of your target:Note: do not check the "copy if needed" option to make sure you only have to manage one selligent.json file
-
Drag and drop the
libRNSelligent.a
to yourLinked Frameworks and Libraries
: -
Add Selligent to
Header Search Paths
inBuild Settings
of your target:$(SRCROOT)/../node_modules/@selligent-marketing-cloud/selligent-react-native/ios/
-
Create a
Podfile
(if there isn't one already) in the/ios
folder and add the following:
IMPORTANT: Since v2.7.5 of the iOS SDK, the minimum PlotPlugin version is 3.5.0!
target 'REPLACEWITHYOURTARGETNAME'
pod 'PlotPlugin', '3.5.0'
-
Execute
pod install
in the/ios
folder -
From now on open the
.xcworkspace
file to make changes in Xcode -
Bootstrap the SDK in the
application:didFinishLaunchingWithOptions:
of theAppDelegate.mm
#import <RNSelligent.h> [RNSelligent configureWithLaunchOptions:launchOptions];
With autolinking (RN 0.60 and above)
-
Drag and drop the
selligent.json
you created from the root folder to the Xcode project inside theCopy Bundle Resources
inBuild phases
of your target:Note: do not check the "copy if needed" option to make sure you only have to manage one selligent.json file
-
Execute
pod install
in the/ios
folder -
Bootstrap the SDK in the
application:didFinishLaunchingWithOptions:
of theAppDelegate.mm
#import <RNSelligent.h> [RNSelligent configureWithLaunchOptions:launchOptions];
-
For push notifications you need to delegate some of the
AppDelegate.mm
methods to the SDK:#import "AppDelegate.h" #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import <React/RCTAppSetupUtils.h> #import <RNSelligent.h> #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 @import UserNotifications; @interface AppDelegate () <UNUserNotificationCenterDelegate> @end #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self _prepareForPushNotifications]; [RNSelligent configureWithLaunchOptions:launchOptions]; // ... //react native setup code // ... return YES; } - (void)_prepareForPushNotifications { #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; #endif } - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNSelligent performIAMFetchWithCompletionHandler:completionHandler]; } - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { [RNSelligent didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication*)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RNSelligent didRegisterUserNotificationSettings:notificationSettings]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNSelligent didFailToRegisterForRemoteNotificationsWithError:error]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [RNSelligent didReceiveRemoteNotification:userInfo]; } #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { [RNSelligent willPresentNotification:notification withCompletionHandler:completionHandler]; } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler { [RNSelligent didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; } #endif @end
-
Follow section Create an APNS Key, of the native documentation.
-
If you want rich push notifications, follow section 6.9 Notification Extensions as well.
Make sure you add yourappGroupId
to theselligent.json
.IMPORTANT! make sure your
appGroupId
has the following structure or it will not work:group.{MAIN_APP_BUNDLE_ID}
IMPORTANT! Since v2.9.0,
-(void)didReceiveNotification:(UNNotification *)notification
ofSMManager+RemoteNotification
has become deprecated. You will need to invoke-(void)didReceiveNotification:(UNNotification *)notification withContext
instead. Consult the iOS documentation for more details. -
Starting from iOS 13, Apple split up the application lifecycle logic between
AppDelegate
andSceneDelegate
.
This was done in order to enable multi-window support that was introduced in iPad-OS. TheAppDelegate
is responsible for application lifecycle handling and setup of services, whileSceneDelegate
is responsible for updating the UI (windows and scenes).However, this split in responsibilites has given rise to issues with Sellgent's default push notification behavior since iOS 15, which shows an alert containing the notification's content, or its associated in-app content. Starting from iOS 15, you should add a separate
SceneDelegate
, that you connect to yourAppDelegate
, which handles the UI updating logic:// SceneDelegate.h #ifndef SceneDelegate_h #define SceneDelegate_h #import <UIKit/UIKit.h> #import <React/RCTBridgeDelegate.h> @interface SceneDelegate : UIResponder <UIWindowSceneDelegate, RCTBridgeDelegate> @end #endif /* SceneDelegate_h */
// SceneDelegate.mm #import "SceneDelegate.h" #import <React/RCTBridge.h> #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import <React/RCTAppSetupUtils.h> @implementation SceneDelegate #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 @synthesize window = _window; - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){ RCTAppSetupPrepareApp([ UIApplication sharedApplication]); // ... // other react native setup code // ... } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } #endif @end
// AppDelegate.mm // Other imports... #import "SceneDelegate.h" @implementation AppDelegate #if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)){ UISceneConfiguration *configuration = [[UISceneConfiguration alloc] init]; configuration.delegateClass = SceneDelegate.class; return configuration; } #endif - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { [self _prepareForPushNotifications]; [RNSelligent configureWithLaunchOptions:launchOptions]; // if (@available(iOS 13.0, *)) { return YES; } // ... //react native setup code // ... return YES; } // Other AppDelegate methods, as defined above... @end
For geolocation services, follow section Geolocation, of the native documentation. You also need to configure several permissions described here.
You can catch the deeplinks 2 ways:
- Native in AppDelegate.mm, add the following (example code that logs the URL)
-(BOOL)application:(UIApplication*) application openURL:(NSURL*) url sourceApplication:(NSString*) sourceApplication annotation:(id) annotation
{
NSLog(@"%@", [url absoluteString]);
return YES;
}
- In your React Native codebase, https://facebook.github.io/react-native/docs/linking
-
In the
App.js
file:-
Add the
Button
import statement:import { Platform, StyleSheet, Text, View, Button } from "react-native"; // Add Button import
-
Add the
Selligent
import statement:import Selligent from "@selligent-marketing-cloud/selligent-react-native"; // Add Selligent import
-
Add a function to call the
Selligent.getVersionLib
function:export default class App extends Component<Props> { ... // Add example function _getVersionLib() { Selligent.getVersionLib((versionLib) => { alert(versionLib); }) } ... }
-
Add a
Button
component in therender()
function calling the function of the previous step:render() { return ( <View style={styles.container}> ... // Add button <Button onPress={this._getVersionLib} title='getVersionLib' /> </View> ); }
-
Your
App.js
file should look something like this:import React, { Component } from "react"; import { Platform, StyleSheet, Text, View, Button } from "react-native"; // Add Button import import Selligent from "@selligent-marketing-cloud/selligent-react-native"; // Add Selligent import const instructions = Platform.select({ ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu", android: "Double tap R on your keyboard to reload,\n" + "Shake or press menu button for dev menu", }); type Props = {}; export default class App extends Component<Props> { // Add example function _getVersionLib() { Selligent.getVersionLib((versionLib) => { alert(versionLib); }); } render() { return ( <View style={styles.container}> <Text style={styles.welcome}>Welcome to React Native!</Text> <Text style={styles.instructions}> To get started, edit App.js </Text> <Text style={styles.instructions}>{instructions}</Text> // Add button <Button onPress={this._getVersionLib} title="getVersionLib" /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF", }, welcome: { fontSize: 20, textAlign: "center", margin: 10, }, instructions: { textAlign: "center", color: "#333333", marginBottom: 5, }, });
-
-
- Selligent.getVersionLib(successCallback)
- Selligent.enableGeolocation(successCallback, errorCallback, enabled)
- Selligent.isGeolocationEnabled(successCallback)
- Selligent.getDeviceId(successCallback)
- Selligent.enableNotifications(successCallback, errorCallback, enabled)
- Selligent.displayLastReceivedRemotePushNotification(successCallback)
- Selligent.getLastRemotePushNotification(successCallback)
- Selligent.enableInAppMessages(successCallback, errorCallback, enabled)
- Selligent.getInAppMessages(successCallback)
- Selligent.setInAppMessageAsSeen(successCallback, errorCallback, messageId)
- Selligent.executeButtonAction(successCallback, errorCallback, buttonId, messageId)
- Selligent.sendEvent(successCallback, errorCallback, event)
- Selligent.subscribeToEvents(successCallback, errorCallback, eventCallback)
-
- Selligent.subscribeToEvent(eventCallback, eventName)
- Selligent.areInAppMessagesEnabled(successCallback)
- Selligent.enableAndroidLogging(successCallback, errorCallback, enabled)
- Selligent.displayMessage(successCallback, errorCallback, messageId)
- Selligent.areNotificationsEnabled(successCallback)
- Selligent.setNotificationSmallIcon(successCallback, errorCallback, iconName)
- Selligent.setNotificationLargeIcon(successCallback, errorCallback, iconName)
- Selligent.setNotificationIconColor(successCallback, errorCallback, color)
- Selligent.getGCMToken(successCallback)
- Selligent.getRemoteMessagesDisplayType(successCallback, errorCallback)
- Selligent.setFirebaseToken(successCallback, errorCallback, token)
-
- Selligent.enableiOSLogging(successCallback, errorCallback, logLevels)
- Selligent.displayNotification(successCallback, errorCallback, notificationId)
- Selligent.registerForProvisionalRemoteNotification(successCallback)
- Selligent.registerRemoteNotificationFetchCompletionHandler(successCallback, errorCallback)
- Selligent.forceRemoteNotificationBackgroundFetchResult(successCallback, errorCallback, iOSBackgroundFetchResult)
-
- SelligentConstants.ClearCacheIntervalValue
- SelligentConstants.InAppMessageType
- SelligentConstants.InAppMessageRefreshType
- SelligentConstants.RemoteMessagesDisplayType
- SelligentConstants.iOSLogLevel
- SelligentConstants.iOSBackgroundFetchResult
- SelligentConstants.iOSLocationAuthorisationStatus
- SelligentConstants.iOSLocationAuthorisationType
- SelligentConstants.EventType
- SelligentConstants.iOSNotificationButtonType
- SelligentConstants.BroadcastEventType
Returns the version of the installed Selligent SDK.
The response of the success callback is a string containing the version of the SDK.
Selligent.getVersionLib((versionLib) => {
// success callback
alert(versionLib);
});
Enable or disable geolocation services.
The enabled
parameter is a required boolean to enable or disable geolocation services.
Selligent.enableGeolocation(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
true
);
Check if geolocation services are enabled or disabled.
The response of the success callback is a boolean stating geolocation services are enabled or disabled.
Selligent.isGeolocationEnabled(
(response) => { // success callback
...
}
);
Returns the device id.
The response of the success callback is a string containing the device id.
Selligent.getDeviceId((deviceId) => {
// success callback
alert(deviceId);
});
Enable or disable the usage of notifications.
The enabled
parameter is a required boolean to enable or disable notifications.
Selligent.enableNotifications(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
true
);
Display the last received remote notification.
Selligent.displayLastReceivedRemotePushNotification(
(response) => { // success callback
...
}
);
Get the id and the title of the last received remote push notification.
The response of the success callback is an object containing the information about the last received remote push notification, or null
if there is no last received remote push notification.
Detailed overview:
Property | Type | Description |
---|---|---|
id | string | Id of the last remote push notification |
title | string | Title of the last remote push notification |
Selligent.getLastRemotePushNotification(
(response) => { // success callback
...
}
);
This method enables or disables the management of in-app messages.
The enabled
parameter can be a boolean or a constant of the InAppMessageRefreshType enum.
Note: on iOS the enabled
parameter must be a boolean.
In the case of a boolean set to false
, the in-app messages will be disabled.
When the passed enabled
parameter is an InAppMessageRefreshType constant, the in-app messages will be enabled and the refresh frequency will be set to the provided value.
The method will return an error if the parsed boolean is set to true
, as to enable the in-app messages a refresh type is expected.
// to enable in-app messages
Selligent.enableInAppMessages(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
Selligent.InAppMessageRefreshType.DAY
);
// to disable in-app messages
Selligent.enableInAppMessages(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
false
);
This method returns all the in app messages send to you.
The response of the success callback is an array of objects which contain the in app message(s) information.
Detailed overview:
Property | Type | Description | Platform |
---|---|---|---|
id | string | Id of the in app message | Both |
title | string | Title of the in app message | Both |
body | string | Body of the in app message | Both |
type | enum SelligentConstants.InAppMessageType | Type of the in app message | Both |
creationDate | number | Creation date of the in app message in unix time | Both |
expirationDate | number | Expiration date of the in app message in unix time | Both |
receptionDate | number | Reception date of the in app message in unix time | Both |
hasBeenSeen | boolean | Indication if the in app message is seen | Both |
buttons | array of objects | Contains the buttons that are linked to the in app message | Both |
The buttons
property is an array of button-objects which contain the information of a button linked to the in app message:
Property | Type | Description | Platform |
---|---|---|---|
id | string | Id of the button of the in app message | Both |
label | string | Label of the button of the in app message | Both |
value | string | Value of the button of the in app message | Both |
type | number | Type of the button of the in app message | Both |
action | number | Action of the button of the in app message | Android only |
// Get all in app messages
Selligent.getInAppMessages(
(response) => { // success callback
...
}
);
Possibility to mark an in app message as seen.
This method requires beside the callbacks another property to indicate the current in app message. To accomplish this behavior, messageId
is required.
Selligent.setInAppMessageAsSeen(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"id-of-message"
);
Execute the action linked to the button.
This method requires beside the callbacks another property to execute the action behind the button of the in app message. To accomplish this behavior, buttonId
and messageId
are required.
Selligent.executeButtonAction(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"id-of-button",
"id-of-message"
);
This method provides the functionality to send a specific or custom event.
The method accepts an event
object which requires certain properties, depending on the type of the event.
Detailed overview:
Property | Type | Required | Platform | Default value |
---|---|---|---|---|
type | enum EventType | Yes | Both | N/A |
string | Yes if event type is specific, ignored if custom | Both | N/A | |
data | object | Yes if event type is custom, optional if specific | Both | N/A |
shouldCache | boolean | No | iOS Only | true |
The type
property is used to define the event as custom or specific event, using the EventType constants.
To define it as a custom event, one should use the SelligentConstants.EventType.CUSTOM
constant. All other event types can be used to define the event as something specific.
When an event is a specific event type, the event
object requires an email
property containing a string, and has an optional property data
which is an object that can contain other information.
When an event is a custom event type, the event
object requires a data
property containing an object which contains other information, and ignores the email
property.
iOS specific:
On iOS the event
object can contain an additional optional shouldCache
property, which is a boolean that can be used to cache and retry sending events in situations where the event could not be delivered.
By default it is set to true
, setting it to false
will disable it.
// send specific event
Selligent.sendEvent(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
{
type: SelligentConstants.EventType.BUTTON_CLICKED // specific event
data: { // optional
id: 1337,
randomFlag: true,
description: "this is some extra information concerning this event"
}
email: "[email protected]" // required
},
shouldCache: false // iOS only, optional
);
// send custom event
Selligent.sendEvent(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
{
type: SelligentConstants.EventType.CUSTOM // custom event
data: { // required
id: 1337,
someFlag: true,
description: "this is some extra information concerning this event"
}
email: "[email protected]" // ignored
}
);
This method is used to subscribe to events.
The response of the success callback is an object which contains information on the type of broadcast event and the data attached to it.
Detailed overview:
Property | Type | Description |
---|---|---|
broadcastEventType | enum BroadcastEventType | The type of broadcast event |
data | object | Contains more information specific to the type of broadcast event |
The data
property is an object itself containing more information specific to the type of the broadcast event:
In case of a broadcast event type ButtonClicked the detailed overview for the data
is as such:
Property | Type | Description |
---|---|---|
type | iOS: enum iOSNotificationButtonType | The type of notification button clicked |
Android: integer | ||
value | string | A certain value the broadcof ast event |
id | string | A certain id of the event |
label | string | A certain label of the event |
data | object | Specific additional data of the event |
action | integer | Specific action of the event |
In case of a broadcast event type ReceivedInAppMessage the detailed overview for the data
is as such:
Property | Type | Description |
---|---|---|
messages | array | List of messages |
And the detailed overview for items in the messages
array is as such:
Property | Type | Description |
---|---|---|
id | string | Id of a message |
title | string | Title of a message |
In case of a broadcast event type ReceivedDeviceId the detailed overview for the data
is as such:
Property | Type | Description |
---|---|---|
deviceId | string | The device id |
In case of a broadcast event type ReceivedGCMToken the detailed overview for the data
is as such:
Property | Type | Description |
---|---|---|
token | string | The token attached to the event |
In case of a broadcast event type ReceivedRemoteNotification the detailed overview for the data
is as such:
Property | Type | Description |
---|---|---|
pushId | string | The id of the remote push notification |
name | string | The name attached to the push notification |
In case of a broadcast event type WillDisplayNotification or WillDismissNotification the data
prop is null
.
Android specific:
On the Android platform you can subscribe to custom events, by parsing an array of strings of these custom events. See the example for more information.
Selligent.subscribeToEvents(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
(eventCallback) => {
...
}
["some custom event x", "navigated to page y", "accepted request z"] // optional, android only
);
This method is used to subscribe to a single event on Android.
The response of the event callback is an object which contains information on the type of broadcast event and the data attached to it.
Selligent.subscribeToEvents(
(event) => { // event callback
...
},
"some custom event x" // custom event name
);
Check if in-app messages are enabled or disabled.
The response of the success callback returns a boolean stating the in-app messages are enabled or disabled.
Selligent.areInAppMessagesEnabled(
(response) => { // success callback
...
}
);
Display different actions and information logged by the SDK in the Android Studio logcat.
The enabled
parameter is a boolean to effectively enable or disable logging.
Selligent.enableAndroidLogging(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
true
);
Display a specific in-app message.
The method accepts a parameter messageId
which is a string containing the id of the in-app message to display.
Selligent.displayMessage(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"some in-app message id"
);
Check if notifications are enabled or disabled.
The response of the success callback returns a boolean stating the notifications are enabled or disabled.
Selligent.areNotificationsEnabled(
(response) => { // success callback
...
}
);
Set the small icon of a notification on Android.
The method accepts an iconName
parameter which is a string containing the name of the small icon. When the application is closed it will default back to the icons specified in selligent.json
.
Note: only parse the name of the icon, without the path. The icon should reside in the res/drawable folder of the Android project, as explained in Android's official guide.
Selligent.setNotificationSmallIcon(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"smallNotificationIcon"
);
Set the large icon of a notification on Android.
The method accepts an iconName
parameter which is a string containing the name of the large icon. When the application is closed it will default back to the icons specified in selligent.json
.
Note: only parse the name of the icon, without the path. The icon should reside in the res/drawable folder of the Android project, as explained in Android's official guide.
Selligent.setNotificationLargeIcon(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"largeNotificationIcon"
);
Set the icon color of a notification on Android.
The method accepts a color
parameter which is a string containing the hex value of color.
The notification color can also be set by setting the notificationIconColor parameter in
selligent.json
to the hex color value
Selligent.setNotificationIconColor(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"#00b8fb"
);
Get the GCM token being used.
The response of the success callback is a string containing the GCM token.
Selligent.getGCMToken(
(response) => { // success callback
...
}
);
Get the type of the remote messages that are being displayed.
The response of the success callback is a number corresponding with a constant of the AndroidRemoteMessagesDisplayType enum.
Selligent.getRemoteMessagesDisplayType(
(response) => { // success callback
...
},
(error) => { // error callback
...
}
);
Set the firebase token manually.
window.Selligent.setFirebaseToken(
function (response) { // success callback
...
},
function (error) { // error callback
...
},
'123xyz'
);
Display different actions and information logged by the SDK.
The logLevels
parameter is an array of logging levels that you want to enable, using the Selligent.iOSLogLevel enum.
To disable a certain level, the existing array of the enabled logging level(s), minus the one you want to disable, should be passed to the method. To disable all log levels you need to use the iOSLogLevel.NONE constant. To enable all log levels use the iOSLogLevel.ALL constant.
// to enable logging of info, warning and error statements
Selligent.enableiOSLogging(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
[Selligent.iOSLogLevel.INFO, Selligent.iOSLogLevel.WARNING, Selligent.iOSLogLevel.ERROR]
);
// to disable all logging
Selligent.enableiOSLogging(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
[Selligent.iOSLogLevel.NONE]
);
Display a notification based on its id, which is a string that needs to be parsed in the method with the notificationId
parameter.
Selligent.displayNotification(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
"some notification id"
);
You can decide to first ask for the Provisional push authorization (which will provide a valid push token but will not show any prompt to the user) if you want to contact users that did not decide about the Push permission yet (you can call enableNotifications
later and it will still display the push permission prompt to the user).
Selligent.registerForProvisionalRemoteNotification(
() => { // success callback
...
}
);
Register a completion handler for successfully fetching remote notifications.
The success callback is completion handler to be set.
Selligent.registerRemoteNotificationFetchCompletionHandler(
(response) => { // success callback
...
},
(error) => { // error callback
...
}
);
Selligent.forceRemoteNotificationBackgroundFetchResult(successCallback, errorCallback, iOSBackgroundFetchResult)
Force the result of a remote notification fetch to be a specific value.
Selligent.forceRemoteNotificationBackgroundFetchResult(
(response) => { // success callback
...
},
(error) => { // error callback
...
},
Selligent.iOSBackgroundFetchResult.NEW_DATA
);
Defines the interval value to clear the cache.
Name | Type | Value | Description |
---|---|---|---|
AUTO | number | 1 | Clear cache automatically (on startup?) |
NONE | number | 2 | Don't clear cache |
Android.DAY | number | 3 | Clear cache daily, only available on Android |
WEEK | number | 4 | Clear cache weekly |
MONTH | number | 5 | Clear cache monthly |
QUARTER | number | 6 | Clear cache quarterly |
Note: ClearCacheIntervalValue.Android.DAY
is only used on Android and can not be used on iOS.
Defines the type of the in-app messages.
Name | Type | Value | Description |
---|---|---|---|
UNKNOWN | number | -2 | In App message of unknown type |
HIDDEN | number | -1 | In App message of hidden type |
ALERT | number | 0 | In App message of alert type |
HTML | number | 1 | In App message of html type |
URL | number | 2 | In App message of url type |
IMAGE | number | 3 | In App message of image type |
MAP | number | 4 | In App message of map type |
PASSBOOK | number | 5 | In App message of passbook type |
Defines how often the SDK must retrieve the in-app messages.
Name | Type | Value | Description |
---|---|---|---|
NONE | number | 10 | Don't refresh the in-app messages |
Android.MINUTE | number | 11 | Refresh minutely (only on Android) |
HOUR | number | 12 | Refresh hourly |
DAY | number | 13 | Refresh weekly |
Note: InAppMessageRefreshType.Android.MINUTE
is only used on Android and can not be used on iOS.
Defines if and how remote messages can be displayed on Android.
Name | Type | Value | Description |
---|---|---|---|
AUTOMATIC | number | 20 | Display remote messages automatically |
NONE | number | 21 | Don't display remote messages |
NOTIFICATION | number | 22 | Display remote messages as notification |
Defines the level of output of logging messages on iOS.
Name | Type | Value | Description |
---|---|---|---|
NONE | number | 50 | Output nothing |
INFO | number | 51 | Output info |
WARNING | number | 52 | Output warning |
ERROR | number | 52 | Output error |
HTTP_CALL | number | 52 | Output http calls |
LOCATION | number | 52 | Output location |
ALL | number | 52 | Output all |
Description of the possible results of a background fetch on iOS.
Name | Type | Value | Description |
---|---|---|---|
NEW_DATA | number | 60 | Background fetch resulted in new data |
NO_DATA | number | 61 | Background fetch resulted in no new data |
FAILED | number | 62 | Background fetch failed |
Description of the possible status of use of location services on a device.
Name | Type | Value | Description |
---|---|---|---|
UNKNOWN | number | 70 | Status of use of location services is unknown |
REFUSED | number | 71 | Use of location services is refused |
GRANTED_IN_USE | number | 72 | Use of location services is granted when in use |
GRANTED_ALWAYS | number | 72 | Use of location services is always granted |
Defines the level of request for the authorisation of usage of location services on a device.
Name | Type | Value | Description |
---|---|---|---|
IN_USE | number | 80 | Request authorisation when location services are in use |
ALWAYS | number | 81 | Always request the authorisation of the location services |
Defines the type of an event.
Name | Type | Value | Description |
---|---|---|---|
USER_REGISTER | number | 90 | User registered |
USER_UNREGISTER | number | 91 | User unregistered |
USER_LOGIN | number | 92 | User logged in |
USER_LOGOUT | number | 93 | User logged out |
CUSTOM | number | 94 | Custom event |
Defines the type of button for notifications on iOS.
Name | Type | Value | Description |
---|---|---|---|
UNKNOWN | number | 100 | Unknown button type |
SIMPLE_OPEN_PHONE_CALL | number | 101 | Simple open phone call button type |
OPEN_SMS | number | 102 | Open sms button type |
OPEN_MAIL | number | 103 | Open mail button type |
OPEN_BROWSER | number | 104 | Open browser button type |
OPEN_APPLICATION | number | 105 | Open application button type |
RATE_APPLICATION | number | 105 | Rate application button type |
CUSTOM_ACTION_BROADCAST_EVENT | number | 105 | Custom action broadcast event button type |
RETURN_TEXT | number | 105 | Return text button type |
RETURN_PHOTO | number | 105 | Return photo button type |
RETURN_TEXT_AND_PHOTO | number | 105 | Return text and photo button type |
PASSBOOK | number | 105 | Passbook button type |
Defines the type of a broadcast event.
Name | Type | Value | Description |
---|---|---|---|
BUTTON_CLICKED | string | "ButtonClicked" | A button was clicked |
RECEIVED_IN_APP_MESSAGE | string | "ReceivedInAppMessage" | An in-app message has been received |
WILL_DISPLAY_NOTIFICATION | string | "WillDisplayNotification" | A notification will be displayed |
WILL_DISMISS_NOTIFICATION | string | "WillDismissNotification" | A notification will be dismissed |
RECEIVED_DEVICE_ID | string | "ReceivedDeviceId" | A device id has been received |
Android.RECEIVED_GCM_TOKEN | string | "ReceivedGCMToken" | A GCM token has been received (only on Android) |
iOS.RECEIVED_REMOTE_NOTIFICATION | string | "ReceivedRemoteNotification" | A remote notification has been received (only on iOS) |
Notes: BroadcastEventType.Android.RECEIVED_GCM_TOKEN
is only used on Android and can not be used on iOS. BroadcastEventType.iOS.RECEIVED_REMOTE_NOTIFICATION
is only used on iOS and can not be used on Android.