Skip to main content

React Native DataSapien

info

This documentation is for React Native SDK 2.1.x

DataSapien is the main entry point of the SDK and is exported as the package's default export. Use it to initialize the SDK, run the post-initialization setup, and obtain the service instances.

Functions​

initialize​

static initialize(config: DataSapienConfig): Promise<boolean>

Initializes the SDK with the given configuration.

Parameters:

setup​

static setup(): Promise<boolean>

Runs post-initialization setup and synchronizes SDK data (MeData definitions, journeys, rules, managed APIs, segment subscriptions, managed AI models, and audiences).

Parameters: None.

syncAll​

static syncAll(): Promise<boolean>

Re-synchronizes all backend-driven data: MeData definitions, natively collected MeData, journeys, rules, managed APIs, segment subscriptions, managed AI models, and audiences. Use it to refresh SDK data while the app is running, for example on pull-to-refresh.

Parameters: None.

deleteAllData​

static deleteAllData(): Promise<boolean>

Deletes all data stored by the SDK on the device.

Parameters: None.

getMeDataService​

static getMeDataService(): MeDataService

Returns the MeData Service instance.

Parameters: None.

getJourneyService​

static getJourneyService(): JourneyService

Returns the Journey Service instance.

Parameters: None.

getAudienceService​

static getAudienceService(): AudienceService

Returns the Audience Service instance.

Parameters: None.

getIntelligenceService​

static getIntelligenceService(): IntelligenceService

Returns the Intelligence Service instance.

Parameters: None.

getManagedAPIService​

static getManagedAPIService(): ManagedAPIService

Returns the Managed API Service instance.

Parameters: None.

getBackupService​

static getBackupService(): BackupService

Returns the Backup Service instance.

Parameters: None.

Classes​

DataSapienConfig​

Configuration for SDK initialization. Instances are created via the nested Builder.

DataSapienConfig.Builder​

class Builder {
setAuth(auth: {
authUrl: string;
authClientId: string;
authClientSecret: string;
authScope: string;
}): Builder;

setHostUrl(hostUrl: string): Builder;
setMediaUrl(mediaUrl: string): Builder;
setMainColor(mainColor: string): Builder;
setLogLevel(levels: LogLevel[]): Builder;
setDebugViewEnabled(enabled: boolean): Builder;
build(): DataSapienConfig;
}
  • setAuth — OAuth token endpoint URL, client ID, client secret, and scope. Required.
  • setHostUrl — Base URL for the DataSapien API. Required.
  • setMediaUrl — Base URL for the DataSapien media API. Required.
  • setMainColor — Main hex color used for UI styling (e.g. "#F37102"). Optional.
  • setLogLevel — Sets which log levels the SDK emits (see LogLevel). Optional; an empty array (the default) disables all SDK logging.
  • setDebugViewEnabled — Enables the Journey in-app debug view. Optional, defaults to false.
  • build — Builds the configuration. Throws an Error if any required value is missing.

Example:

import DataSapien, { DataSapienConfig, LogLevel } from 'react-native-datasapien';

const config = new DataSapienConfig.Builder()
.setAuth({
authUrl: '<YOUR_AUTH_URL>',
authClientId: '<YOUR_CLIENT_ID>',
authClientSecret: '<YOUR_CLIENT_SECRET>',
authScope: '<YOUR_AUTH_SCOPE>',
})
.setHostUrl('<YOUR_HOST_URL>')
.setMediaUrl('<YOUR_MEDIA_URL>')
.setLogLevel([LogLevel.WARNING, LogLevel.ERROR])
.setDebugViewEnabled(true)
.build();

await DataSapien.initialize(config);

LogLevel​

enum LogLevel {
DEBUG = 'DEBUG',
INFO = 'INFO',
WARNING = 'WARNING',
ERROR = 'ERROR',
}