Skip to main content

Android SDK Functions

Complete reference for the Told Android SDK API.

init

Initialize the SDK. Must be called before any other function, typically in your Application.onCreate().

Told.init(
configuration = ToldConfiguration(
sourceId = "YOUR_SOURCE_ID",
applicationId = applicationContext.packageName,
appVersion = "${BuildConfig.VERSION_NAME}_${BuildConfig.VERSION_CODE}",
environment = ToldEnvironment.Production,
),
completion = { success ->
Log.d("Told", "Init: $success")
}
)
ParameterTypeDescription
configurationToldConfigurationSDK configuration (see below)
completion((Boolean) -> Unit)?Callback receiving true on success (optional)

ToldConfiguration

ParameterTypeDescription
sourceIdStringYour source ID from the Told dashboard
applicationIdStringYour app's package name
appVersionStringYour app version
environmentToldEnvironmentToldEnvironment.Production or ToldEnvironment.Development
languageString?Override device language (optional, auto-detected if null)
previewBooleanEnable preview mode (optional, defaults to false)

ToldEnvironment

EnvironmentServer URLWidget URL
ToldEnvironment.Productionhttps://api.told.club/graphqlhttps://widget.told.club
ToldEnvironment.Developmenthttps://testapi.told.club/graphqlhttps://testwidget.told.club

identify

Update the current user's information. Call this when the user logs in or when their profile changes.

Told.identify(properties: Map<String, Any>)

Example:

Told.identify(mapOf(
"id" to "user_123",
"name" to "Jane Doe",
"email" to "[email protected]"
))

Set language

Override automatic language detection by passing language in the properties:

Told.identify(mapOf("language" to "en"))

trackEvent

Send a custom event for triggering surveys:

Told.trackEvent(eventName: String, properties: Map<String, Any> = emptyMap())
ParameterTypeDescription
eventNameStringName of the event
propertiesMap<String, Any>Additional event properties (optional, defaults to emptyMap())

Example:

Told.trackEvent("purchase_completed", mapOf("amount" to 49.99))

registerNavController

Register a Jetpack Navigation controller to automatically track screen changes. Use this for Compose or Fragment-based navigation.

val navController: NavHostController = rememberNavController()
LaunchedEffect(key1 = navController) {
Told.registerNavController(navController = navController)
}
ParameterTypeDescription
navControllerNavControllerThe Jetpack Navigation controller to monitor

The destination name sent to Told is the fully qualified name of your destination (e.g., com.myapp.MyDestination). This name must match the trigger configuration in the Told dashboard.


registerActivityCallback

For activity-based navigation (no NavController), register to listen for activity changes:

Told.registerActivityCallback()

Call this once during your application's lifecycle. If you use NavController, prefer registerNavController instead.


unregisterActivityCallback

Manually unregister the activity callback:

Told.unregisterActivityCallback()

Useful if you switch between NavController and activity-based navigation.


start

Manually start a specific survey by ID:

Told.start(surveyId: String, withDelay: Duration = 0.seconds)
ParameterTypeDescription
surveyIdStringThe survey ID from the Told dashboard
withDelayDurationDelay before showing the survey (optional, defaults to 0.seconds)

Example:

import kotlin.time.Duration.Companion.seconds

Told.start(surveyId = "SURVEY_ID", withDelay = 2.seconds)

reset

Reset the user to anonymous state. Call this when the user logs out. This is a suspend function.

suspend fun reset(newConfiguration: ToldConfiguration? = null): Boolean
ParameterTypeDescription
newConfigurationToldConfiguration?Optionally apply a new configuration after reset (optional)

Returns: Booleantrue if the reset succeeded.

Example:

lifecycleScope.launch {
val success = Told.reset()
}

setPreview

Toggle preview/test mode. This is a suspend function.

suspend fun setPreview(preview: Boolean)
ParameterTypeDescription
previewBooleantrue to enable preview mode, false to disable

Example:

lifecycleScope.launch {
Told.setPreview(true)
}

debugWidget

Log diagnostic information about your source and surveys to Logcat (tag: Told):

Told.debugWidget()