Examples

import SentianceCore from "@sentiance-react-native/core";

You can find a reference to all the types mentioned on this page here.

Create a Sentiance user

Refer to this guide for documentation on user creation.

// returns Promise<CreateUserResult>
const createUserResult = await SentianceCore.createUser({authCode});

With User Linking

Refer to this guide for documentation on user linking.

// returns Promise<CreateUserResult>
const createUserResult = await SentianceCore.createUser({
    appId, 
    appSecret, 
    platformUrl,
    linker: async (installId) => {
        // request your backend to perform user linking
        await linkUser(installId);

        // return true to indicate to the SDK that user linking on your 
        // backend was successful. return false otherwise.
        return true;
  }
});

If your backend was unable to link the user to the Sentiance platform, then return false instead to notify the SDK that the linking failed.

Creates an unlinked (anonymous) Sentiance user.

Use this function to link an anonymous Sentiance user, which you've created by not specifying a user-linker, to your app's user.

Using a Linker

Enabling detections on the SDK

You can also enable detections while also setting a future expiry date for the detections to stop automatically:

Disabling detections on the SDK

While it's possible to "pause" the detections of the Sentiance SDK's, it's not recommended, as it can lead to missed detections (e.g. trips).

Init status

Checking if SDK is initialized

SDK status

Getting the status of the SDK:

The SDK can signal SDK status updates to JavaScript without being invoked directly. You can subscribe to these status updates:

Get the SDK version

Get the user ID

If the SDK is initialized, you can get the user ID as follows. This user ID will allow you to interact with the APIs from Sentiance. You need a token and a user ID to authorize requests and query the right data.

Check if user exists on device

Check if the current user is linked to a third party ID

Get the user access token

If the SDK is initialized, you can get a user access token as follows. This token will allow you to interact with the APIs from Sentiance. You need a token and a user ID to authorize requests and query the right data. If the token has expired, or will expire soon, the SDK will get a new bearer token before returning it. Generally, this operation will complete instantly by returning a cached bearer token, but if a new token has to be obtained from the Sentiance API, there is a possibility that it will fail.

Adding custom metadata

Custom metadata allows you to store text-based key-value user properties on the Sentiance platform, such as application related properties, which you can then obtain when processing data offloads (generated by Sentiance).

Remove custom metadata

You can remove previously added metadata fields by passing the metadata label to the removeUserMetadataField function.

Adding multiple custom metadata fields

You can add multiple custom metadata fields by passing an object to the addUserMetadataFields function.

Starting trip

When you call startTrip on the SDK, you override automatic SDK detections and force trip data collection, until you call stopTrip, or until the trip times out (only applicable to the triggered trip SDK flavor). startTrip accepts a metadata object and a transport mode hint (numeric) as parameters.

Transport mode hint:

Example:

Stopping trip

You can also receive trip timeout events:

Trip status

Checking an ongoing trip status:

Control sending data

If you want to override the default SDK data submission behavior, you can initiate a forced submission of detections. Ideally, you use this method only after explaining to the user that your app will consume more bandwidth in case the device is not connected to Wi-Fi.

Disk, mobile network and Wi-Fi quotas

The usage and limits of network and disk capacity in bytes can be obtained using the getWiFiQuotaUsage, getWiFiQuotaLimit and similar methods on the Sentiance SDK interface.

All quota functions:

  • getWiFiQuotaLimit

  • getWiFiQuotaUsage

  • getMobileQuotaLimit

  • getMobileQuotaUsage

  • getDiskQuotaLimit

  • getDiskQuotaUsage

User Activity

To get the user's current activity:

You can subscribe to receive user activity updates:

Handling user activity:

Update the SDK foreground notification (ANDROID ONLY)

Updates the title and text of SDK notification. After calling this method, any notification shown by the SDK will be updated.

Note that this change is valid only during the process's lifetime. After the app process restarts, the SDK will display the default notification.

Resetting the SDK

To delete the Sentiance user and its data from the device, you can reset the SDK by calling SentianceCore.reset(). This allows you to create a new Sentiance user afterwards.

Enable/Disable app session data collection

When the app is foregrounded, the SDK may collect various sensor data for analytics purposes. You can enables or disable this. By default, it's disabled.

Check app session data collection status

Disable battery optimization (Android)

Control Transmittable Data Types

Control which data types the SDK is allowed to upload to the Sentiance Cloud Platform.

Note that these rules are not applicable to log and diagnostic data that the SDK may upload (if enabled for your app).

Last updated