Skip to main content

Android DataSapien

info

This documentation is for Android SDK 2.1.x

DataSapien is the main entry point of the SDK. It is a Kotlin singleton (object), so all members are effectively static. Use it to initialize the SDK, run the post-initialization setup, and obtain the service instances.

Functions​

initialize​

fun initialize(
context: Context,
config: DataSapienConfig
): Unit

Initializes the SDK with the given configuration. Never throws: on failure the SDK stays uninitialized, the error is logged, and every subsequent service call reports the failure through its Result/onError channel.

Parameters:

  • context: Context — Application context.
  • config: DataSapienConfig — Configuration built via DataSapienConfig.Builder.

setup​

suspend fun setup(context: Context): Result<Unit>

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

Parameters:

  • context: Context — Application context.

setup​

fun setup(
context: Context,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

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

Parameters:

  • context: Context — Application context.
  • onSuccess: () -> Unit — Called when setup completes successfully.
  • onError: ((Throwable) -> Unit)? — Called when an error occurs during setup.

syncAll​

suspend fun syncAll(context: Context): Result<Unit>

Re-synchronizes all backend-driven data: MeData definitions, natively collected MeData, journeys, rules, managed APIs, segment subscriptions, managed AI models, and audiences. Runs the same pipeline as setup but without the migration steps, so use it to refresh SDK data while the app is running (for example on pull-to-refresh). Fails if the MeData definition sync or the native collection fails; every other sync logs its own error and does not abort the rest.

Parameters:

  • context: Context — Application context.

syncAll​

fun syncAll(
context: Context,
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

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:

  • context: Context — Application context.
  • onSuccess: () -> Unit — Called when synchronization completes successfully.
  • onError: ((Throwable) -> Unit)? — Called when an error occurs during synchronization.

deleteAllData​

suspend fun deleteAllData(): Result<Unit>

Deletes all data stored by the SDK on the device.

Parameters: None.

deleteAllData​

fun deleteAllData(
onSuccess: () -> Unit,
onError: ((Throwable) -> Unit)? = null
): Unit

Deletes all data stored by the SDK on the device.

Parameters:

  • onSuccess: () -> Unit — Called when deletion completes successfully.
  • onError: ((Throwable) -> Unit)? — Called when an error occurs during deletion.

getMeDataService​

fun getMeDataService(): MeDataService

Returns the MeData Service instance.

Parameters: None.

getJourneyService​

fun getJourneyService(): JourneyService

Returns the Journey Service instance.

Parameters: None.

getAudienceService​

fun getAudienceService(): AudienceService

Returns the Audience Service instance.

Parameters: None.

getIntelligenceService​

fun getIntelligenceService(): IntelligenceService

Returns the Intelligence Service instance.

Parameters: None.

getManagedAPIService​

fun getManagedAPIService(): ManagedAPIService

Returns the Managed API Service instance.

Parameters: None.

getBackupService​

fun getBackupService(): BackupService

Returns the Backup Service instance.

Parameters: None.

getHostService​

fun getHostService(): HostService

Returns the Host Service instance.

Parameters: None.

Classes​

DataSapienConfig​

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

DataSapienConfig.Builder​

class Builder {
fun setAuth(
authUrl: String,
authClientId: String,
authScope: String,
authClientSecret: String
): Builder

fun setHostUrl(hostUrl: String): Builder
fun setMediaUrl(mediaUrl: String): Builder
fun setMainColor(mainColor: String): Builder
fun setLogLevel(levels: List<LogLevel>): Builder
fun setDebugViewEnabled(enabled: Boolean): Builder
fun build(): DataSapienConfig
}
  • setAuth — OAuth token endpoint URL, client ID, scope, and client secret. 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. Optional, defaults to "#F37102".
  • setLogLevel — Sets which log levels the SDK emits (see LogLevel). Optional; an empty list (the default) disables all SDK logging.
  • setDebugViewEnabled — Enables the Journey in-app debug view. Optional, defaults to false.
  • build — Builds the configuration. Throws DataSapienException if any required value is missing.

Example:

val config = DataSapienConfig.Builder()
.setAuth(
authUrl = "<YOUR_AUTH_URL>",
authClientId = "<YOUR_CLIENT_ID>",
authScope = "<YOUR_AUTH_SCOPE>",
authClientSecret = "<YOUR_CLIENT_SECRET>"
)
.setHostUrl("<YOUR_HOST_URL>")
.setMediaUrl("<YOUR_MEDIA_URL>")
.setLogLevel(listOf(LogLevel.WARNING, LogLevel.ERROR))
.setDebugViewEnabled(true)
.build()

DataSapien.initialize(context, config)

LogLevel​

enum class LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
}