4. Initialization
This document refers to deprecated parts of the platform and has been left intact to help customers with legacy integrations. In order to access the latest platform features and documentation, please go to https://docs.sentiance.com.
Initializing the Sentiance SDK creates the native components necessary to do proper detections. The first SDK initialization additionally creates a unique Sentiance user on the device, identified by a Sentiance user ID. During the initialization process, this Sentiance user can be linked to your app-specific user on the Sentiance platform, making sure that you can properly track your users across both platforms. Additionally, linking allows your users to migrate to new devices, or reinstall your app without losing any historical data. Check our comprehensive user linking guide to find out more about how this works.
To make user linking possible, we provide a React Native method to initialize the SDK in your javascript code. However, since the Sentiance SDK can run in the background without any user interaction, we also require that you initialize the SDK natively during app startup.
Native Initialization
In order for SDK detections to work in the background, you must initialize the Sentiance SDK natively during app startup. Doing so ensures that Sentiance can properly detect the user's activity even when the user does not have your app open.
We initialize the SDK natively only after a previous React Native initialization was successfully complete. This makes sure that our first SDK initialization happens in React Native, allowing us to perform user linking.
iOS
The correct way to natively initialize on iOS is to do it inside the didFinishLaunchingWithOptions
method of the AppDelegate
class.
Android
The correct way to natively initialize on Android is to do it inside the onCreate()
method of the Application
class.
React Native Initialization
Having implemented the native SDK initialization, we're now ready to implement the React Native SDK initialization.
Initializing the SDK in React Native should normally happen only once, when the Sentiance SDK will be initialized for the first time. This first initialization creates a Sentiance user on the device, and allows you to link your app-specific user to this Sentiance user.
Notice that we enable the native SDK initialization after we successfully initialize the SDK, by calling RNSentiance.enableNativeInitialization()
. This will result in the isNativeInitializationEnabled
check we added in the native code to succeed next time.
When you reset the Sentiance SDK, native initalization will be automatically disabled, so you don't need to manually call RNSentiance.disableNativeInitialization().
In the above snippet, while initWithUserLinkingEnabled
executes, the Sentiance SDK will publish an SDKUserLink
event allowing you to perform user linking.
The RNSentiance.userLinkCallback(boolean)
call is important. Without it, the Sentiance SDK will not complete the initialization. If linking succeeds, this SDKUserLink
event does not get emitted during subsequent SDK initializations, unless the SDK gets reset.
Last updated