5. Usage

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.

Setup SDK events listeners

It is recommended to have SDK event listeners set up as soon as possible, so that you do not miss any important SDK events. The best place to do this is inside the top-level component's componentDidMount as follows.

import { Component } from "react";
import { NativeEventEmitter } from "react-native";

const rnSentianceEmitter = new NativeEventEmitter(RNSentiance);

class ReactApp extends Component {
  componentDidMount() {
    this.subscribeSDKEvents();
  }
  subscribeSDKEvents() {
    // Add a listener to handle user linking events.
    this.userLinkListener = rnSentianceEmitter.addListener(
      "SDKUserLink",
      id => {}
    );
    
    // Add a listener to handle SDK status updates, which let you know if 
    // SDK detections are properly running, and if not, why not.
    this.sdkStatusSubscription = rnSentianceEmitter.addListener(
      "SDKStatusUpdate",
      sdkStatus => {}
    );
    
    // Add a listener to handle user acitivty updates, which let you know if
    // the user is stationary or in a transport.
    this.sdkUserActivityUpdateSubscription = rnSentianceEmitter.addListener(
      "SDKUserActivityUpdate",
      userActivity => {}
    );
  }
}

Starting Detections

Detections will automatically start if you set the shouldStart parameter to true while initializing the SDK with initWithUserLinkingEnabled. If you set it to false, you can manually start the detections as follows.

import RNSentiance from "react-native-sentiance";

class ReactApp extends Component {
  async componentDidMount() {
    this.subscribeSDKEvents();
    const sdkStatus = await RNSentiance.start();
  }
}

Once the detections have started, you can callRNSentiance.listenUserActivityUpdates() to receive user activity updates in the listener you set in the previous step.

To learn more about Sentiance React Native bridge methods, see the typing definitions here.

Last updated