Event Tracking
Custom Events
// Simple event
AttributeHQ.track("signup_completed")
// Event with properties
AttributeHQ.track("product_viewed", mapOf(
"product_id" to "sku_123",
"category" to "electronics",
"price" to 15000
))Revenue Events
// Basic revenue (defaults to NGN)
AttributeHQ.trackRevenue(5000.0)
// With currency
AttributeHQ.trackRevenue(25.99, "USD")
// With properties
AttributeHQ.trackRevenue(5000.0, "NGN", mapOf(
"product" to "premium_plan",
"payment_method" to "card"
))User Identification
AttributeHQ.identify("user_12345", mapOf(
"email" to "user@example.com",
"plan" to "premium"
))Get Attribution
val attribution = AttributeHQ.getAttribution()
attribution?.let {
println("Match type: ${it.matchType}")
println("Confidence: ${it.confidence}%")
println("Source: ${it.mediaSource ?: "organic"}")
println("Campaign: ${it.campaignId ?: "none"}")
}Returns null if install tracking hasn’t completed.
Flush Events
AttributeHQ.flush()Background Behavior
The SDK uses ProcessLifecycleOwner to detect app lifecycle:
- Foreground: Flush timer runs at configured interval
- Background: All queued events are flushed immediately
- Return to foreground: New session created if inactive for 30+ minutes
Offline Queue
Events are stored in SharedPreferences as JSON. If a flush fails (no network), events stay in the queue and are retried. The ConnectivityManager detects network changes to optimize flush timing.
If the queue exceeds maxQueueSize (default: 100), the oldest events are dropped.
Threading
All SDK operations (network requests, disk I/O, event processing) run on a dedicated background thread via ScheduledExecutorService. You can safely call any SDK method from the main thread.