Android (Kotlin)
Installation, configuration, event tracking, and full API reference for the Android (Kotlin) SDK.
Requirements
- Android minSdk 24
- compileSdk 35
- Java 17+
1. Install
Local Gradle module
// settings.gradle.ktsinclude(":sdk")project(":sdk").projectDir = File(rootDir, "../appsprint-android/sdk")// app/build.gradle.ktsdependencies {implementation(project(":sdk"))}
Sync Gradle after adding the module.
2. Configure
import com.appsprint.sdk.AppSprintimport com.appsprint.sdk.AppSprintConfig// Call in Application.onCreate() or first Activityval appSprint = AppSprint.shared(applicationContext)appSprint.configure(AppSprintConfig(apiKey = "as_live_xxxxx"))
Thread-safe (@Synchronized). Automatically tracks the install, registers a lifecycle observer for background flushes, and retries any queued events.
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | String | — | Your live API key (starts with as_live_). |
| apiUrl | String | https://api.appsprint.app | Override the API base URL. |
| isDebug | Boolean | false | Enable debug logging (sets logLevel to DEBUG). |
| logLevel | Int | 2 (WARN) | 0 = DEBUG, 1 = INFO, 2 = WARN, 3 = ERROR. |
| customerUserId | String? | null | Set a customer user ID at initialization time. |
3. Track events
// Standard eventappSprint.sendEvent(AppSprintEventType.LOGIN)
// Revenue eventappSprint.sendEvent(AppSprintEventType.PURCHASE,params = mapOf("revenue" to 9.99, "currency" to "USD"))
// Custom event with parametersappSprint.sendEvent(AppSprintEventType.CUSTOM,name = "level_complete",params = mapOf("level" to 5, "score" to 1200))
Supported event types
loginsign_upregisterpurchasesubscribestart_trialadd_to_cartadd_to_wishlistinitiate_checkoutview_contentview_itemsearchsharetutorial_completelevel_startlevel_completecustomUse custom with a name parameter for any event not in this list.
4. Read attribution
After configure() completes, the SDK caches the attribution result from the install response. Access it synchronously:
val attr = appSprint.getAttribution()println(attr?.source) // "fingerprint" or "organic"println(attr?.confidence) // 0.0–1.0println(attr?.campaignName) // UTM campaign name if available
| Field | Description |
|---|---|
| source | "apple_ads", "fingerprint", or "organic" |
| confidence | Match confidence from 0.0 to 1.0 |
| campaignName | Campaign name (if attributed to an ad) |
| utmSource | UTM source from the tracking link |
| utmMedium | UTM medium from the tracking link |
| utmCampaign | UTM campaign from the tracking link |
API reference
configure(config)
Initialize the SDK. Auto-tracks install and registers lifecycle observer.
appSprint.configure(AppSprintConfig(apiKey = "…"))
sendEvent(type, name?, params?)
Send an event. Queued automatically if offline.
appSprint.sendEvent(AppSprintEventType.PURCHASE, params = mapOf("revenue" to 9.99))
flush()
Retry all queued events immediately.
appSprint.flush()
clearData()
Clear all cached state, queue, and disabled flag.
appSprint.clearData()
getAppSprintId()
→ String?Returns the install ID, or null before install completes.
val id = appSprint.getAppSprintId()
getAttribution()
→ AttributionResult?Returns cached attribution data from install.
val attr = appSprint.getAttribution()
isInitialized()
→ BooleanTrue once configure() has completed.
appSprint.isInitialized()
isSdkDisabled()
→ BooleanTrue if the API key was rejected (401/403).
appSprint.isSdkDisabled()
sendTestEvent()
→ TestEventResultSend a diagnostic event. Returns success/message.
val result = appSprint.sendTestEvent()
setCustomerUserId(id)
Attach your own user ID. Sent immediately or queued.
appSprint.setCustomerUserId("user-123")
Offline behavior
- Events that fail to send are automatically queued in native storage (up to 100 events).
- The queue persists across app restarts.
- Queued events are retried automatically when
configure()completes, when the app moves to the background, or when you callflush(). - If a queued event receives a 401/403, the SDK disables itself and clears the queue.
Platform notes
- Apple Search Ads attribution is not available on Android. The enableAppleAdsAttribution config option is ignored.
- IDFA/IDFV are iOS-only. Android device fingerprinting uses Build.MODEL, screen metrics, locale, timezone, and OS version.
- The SDK registers a DefaultLifecycleObserver on ProcessLifecycleOwner to flush events when the app moves to the background.
- configure() is @Synchronized — safe to call from any thread.
Integrations
Once the SDK is configured, connect revenue and ad-network integrations:
Troubleshooting
getAppSprintId() returns null
configure() fires the install request asynchronously. If you need the ID immediately, check isInitialized() or retry after a short delay.
Events not appearing in dashboard
Check that you are using a live API key (as_live_*). Call sendTestEvent() and inspect the result.
SDK disabled after 401/403
The SDK disables itself when the API key is rejected. Call clearData() and re-configure with a valid key.
Events lost on app kill
Events are persisted to SharedPreferences. They will be retried on next app launch after configure().
Connectivity test
val result = appSprint.sendTestEvent()println("${result.success} — ${result.message}")
Verification checklist
- Create a blank Android app and include the SDK module.
- Call configure() in Application.onCreate() or first Activity.
- Verify getAppSprintId() returns a value after first launch.
- Send login, purchase, and custom events — confirm in dashboard.
- Send an event offline, kill the app, relaunch with connectivity — verify the event appears.
- Call sendTestEvent() and confirm { success: true }.