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 are analytics, not verified store transactions or a promise of partner delivery. Avoid unnecessary personal or sensitive data in event properties.
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(
"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 has not completed or collection is disabled.
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.
When the queue reaches maxQueueSize (default: 100), new events are dropped; queued and in-flight events are retained. Event IDs and payloads persist across retries. A batch is cleared only after its full count is acknowledged.
Threading
SDK collection work is serialized on its executor. Public calls can be made from the main thread; argument validation can throw synchronously. Privacy and evidence completion callbacks run on the main thread.
Collection controls
Track, identify, revenue and flush calls do not collect or send while collection is disabled. Disabling discards pending events and local user/session state; already-started requests may finish. Re-enabling accepts new events rather than replaying discarded ones. See privacy controls.