// 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.
// returns Promise<UserLinkingResult>
const userLinkingResult = await SentianceCore.linkUser(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;
}
);
Enabling detections on the SDK
// returns Promise<EnableDetectionsResult>
const enableDetectionsResult = await SentianceCore.enableDetections();
console.log('SDK detection status is now ' + enableDetectionsResult.detectionStatus);
You can also enable detections while also setting a future expiry date for the detections to stop automatically:
const expiryDate = Date.now() + 60 * 60 * 1000; // 1 hour from now
const enableDetectionsResult = await SentianceCore.enableDetectionsWithExpiryDate(expiryDate);
console.log('SDK detection status is now ' + enableDetectionsResult.detectionStatus);
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).
The SDK can signal SDK status updates to JavaScript without being invoked directly. You can subscribe to these status updates:
const subscription = SentianceCore.addSdkStatusUpdateListener(sdkStatus => {
// Access sdkStatus
});
// Don't forget to unsubscribe, typically in componentWillUnmount
subscription.remove();
Get the SDK version
// returns Promise<string>
const version = await SentianceCore.getVersion();
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.
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.
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).
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.
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.
try {
// returns Promise<void>
await SentianceCore.submitDetections();
} catch (err) {
// Something went wrong with submitting data, for more information, see the error variable
}
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.
You can subscribe to receive user activity updates:
const subscription = SentianceCore.addSdkUserActivityUpdateListener(userActivity => {
// Handle user activity
});
// Don't forget to unsubscribe, typically in componentWillUnmount
subscription.remove();
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.
// returns Promise<void>
await SentianceCore.updateSdkNotification("RN SDK Sample", "SDK is running");
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.
try {
// returns Promise<ResetResult>
await SentianceCore.reset();
// The SDK was successfully cleared and reset
} catch (err) {
// Resetting the SDK failed
// err.name has three values:
// SDK_INIT_IN_PROGRESS, SDK_RESET_IN_PROGRESS, SDK_RESET_UNKNOWN_ERROR
}
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.