AdvaitaADVAITA DOCS
GitHubGet started
Mobile SDKv1.0.0MIT License

Android SDK

com.acai:analytics-android is the native Android SDK written in Kotlin. It uses a plugin architecture and auto-tracks lifecycle events, sessions, deep links, and screen views.

Installation

Add to your app-level build.gradle:

Groovy
dependencies {
implementation("com.acai:analytics-android:1.0.0")
}

Initialise

Kotlin
import com.acai.android.Acai
import com.acai.android.Configuration
import com.acai.android.DefaultTrackingOptions
val acai = Acai(
Configuration(
apiKey = "YOUR_API_KEY",
context = applicationContext,
serverUrl = "https://events.yourdomain.com/2/httpapi",
defaultTracking = DefaultTrackingOptions(
sessions = true,
appLifecycles = true,
deepLinks = true,
screenViews = true,
),
)
)

Track events

Kotlin
acai.track("Button Clicked")
acai.track(
eventType = "Purchase Completed",
eventProperties = mapOf(
"product_id" to "prod_123",
"price" to 49.99,
"currency" to "USD",
)
)
acai.flush()

Identify users

Kotlin
import com.acai.android.Identify
acai.setUserId("user_abc123")
val identify = Identify().apply {
set("plan", "pro")
setOnce("signup_date", "2024-01-15")
add("session_count", 1)
append("tags", "power-user")
unset("trial_active")
}
acai.identify(identify)
acai.setGroup("company", "Acme Corp")
val groupIdentify = Identify().apply { set("tier", "enterprise") }
acai.groupIdentify("company", "Acme Corp", groupIdentify)
// Log out
acai.setUserId(null)
acai.reset()

Plugins

Kotlin
import com.acai.android.plugin.Plugin
class BuildInfoPlugin : Plugin {
override val type = Plugin.Type.Enrichment
override fun execute(event: BaseEvent): BaseEvent {
event.eventProperties = (event.eventProperties ?: mapOf()).toMutableMap().also {
it["app_build"] = BuildConfig.VERSION_CODE
it["app_version"] = BuildConfig.VERSION_NAME
}
return event
}
}
acai.add(BuildInfoPlugin())

Config reference

OptionTypeDefaultDescription
apiKeyStringrequiredYour project API key.
contextContextrequiredAndroid application context.
serverUrlStringUS endpointCustom collector endpoint.
flushQueueSizeInt30Events per batch before flush.
flushIntervalMillisLong30000Flush interval in ms.
logLevelLogLevelWARNDISABLE · ERROR · WARN · DEBUG
optOutBooleanfalseDisable all tracking.
defaultTrackingDefaultTrackingOptions—Auto-track sessions, appLifecycles, deepLinks, screenViews.
useBatchBooleanfalseUse the /batch endpoint.
minIdLengthInt?nullMinimum user/device ID length.