Kotlin: Analytics and performance
Log events and screen views for active users, funnels and retention, and report app start, screen and network timings with the Kotlin SDK.
Log events and screen views for active users, funnels and retention, and report app start, screen and network timings. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.
#Types and members
SovariaAnalytics
Product analytics: sovaria.analytics.track("purchase", mapOf("amount" to 20)), screen, identify, and setEnabled (false when the user opts out: the server then drops their events on every device). Events are batched (every 10 s or 20 events), kept in the offline store while offline; the signed-in user comes from the request's token on the server, never from the event.
class SovariaAnalytics internal constructor(private val client: Sovaria)SovariaAnalytics.appVersion
A property.
var appVersion: String?SovariaAnalytics.platform
A property.
var platform: StringSovariaAnalytics.batchSize
A property.
var batchSize: IntSovariaAnalytics.flushIntervalMs
A property.
var flushIntervalMs: LongSovariaAnalytics.anonId
The device id sent as anon_id.
val anonId: String get()SovariaAnalytics.configure
Persist the queue, device id and opt-out across launches.
suspend fun configure(store: OfflineStore?, appVersion: String? = null, platform: String? = null)SovariaAnalytics.track
fun track(name: String, props: Map<String, Any?> = emptyMap()): BooleanSovariaAnalytics.screen
fun screen(name: String, props: Map<String, Any?> = emptyMap()): BooleanSovariaAnalytics.identify
fun identify(userProps: Map<String, Any?>): BooleanSovariaAnalytics.trackExposure
One $exposure per experiment and session (remote config calls this when you read an experiment's value).
fun trackExposure(experiment: String, variant: String)SovariaAnalytics.flush
Send what is queued now.
suspend fun flush()Network errors and throttling keep the events; a refused batch is dropped.
SovariaAnalytics.setEnabled
Analytics consent (DPDP / GDPR).
suspend fun setEnabled(on: Boolean, erase: Boolean = false)Off clears the queue and tells the server; erase also deletes what was stored.
SovariaAnalytics.isEnabled
A property.
val isEnabled: Boolean get()SovariaAnalytics.pending
A property.
val pending: Int get()SovariaRemoteConfig
Remote config and feature flags: setDefaults, fetchAndActivate, getBoolean/getString/getNumber/getJson and onUpdate (live after a publish when the plan has realtime config). Only this user's evaluated values come back (never the rules); unchanged config costs a 304; activated values persist for offline starts.
class SovariaRemoteConfig internal constructor(private val client: Sovaria)SovariaRemoteConfig.minimumFetchIntervalMs
A property.
var minimumFetchIntervalMs: LongSovariaRemoteConfig.attributes
A property.
var attributes: Map<String, Any?>SovariaRemoteConfig.appVersion
A property.
var appVersion: String?SovariaRemoteConfig.platform
A property.
var platform: StringSovariaRemoteConfig.language
A property.
var language: String?SovariaRemoteConfig.setDefaults
fun setDefaults(values: Map<String, Any?>)SovariaRemoteConfig.configure
Restore the last activated values (call early with a durable store).
suspend fun configure(store: OfflineStore?)SovariaRemoteConfig.fetchAndActivate
Fetch (respecting minimumFetchIntervalMs unless force) and activate.
suspend fun fetchAndActivate(force: Boolean = false): BooleanTrue when values changed.
SovariaRemoteConfig.onUpdate
Called with the changed keys whenever new values are activated.
fun onUpdate(cb: (List<String>) -> Unit): IntReturns an id for removeUpdateListener.
SovariaRemoteConfig.removeUpdateListener
fun removeUpdateListener(id: Int)SovariaRemoteConfig.getBoolean
fun getBoolean(key: String, default: Boolean = false): BooleanSovariaRemoteConfig.getString
fun getString(key: String, default: String = ""): StringSovariaRemoteConfig.getNumber
fun getNumber(key: String, default: Double = 0.0): DoubleSovariaRemoteConfig.getJson
fun getJson(key: String): Any?SovariaRemoteConfig.version
A property.
val version: Int get()SovariaPerf
Client performance monitoring (Observability › Performance in the console):
- App start — process start to markAppReady (call it from your first Activity's onResume / reportFullyDrawn, or let installAndroid do it at the first activity resume). - Screens — val t = sov.perf.screen("Checkout") … t.end(). - Network — every request the SDK makes (method, route, status, duration) with the traceparent it sent, so a slow call opens the server trace for the same request. - Custom traces — sov.perf.trace("sync") { … }.
Batched every 10 s (at most 100 per request); counts against obs.perf_events_month.
class SovariaPerf internal constructor(private val client: Sovaria)SovariaPerf.installed
A property.
@Volatile var installedSovariaPerf.install
fun install(release: String? = null, environment: String? = null, sampleRate: Double = 1.0, network: Boolean = true)SovariaPerf.installAndroid
Android: install, and the cold start is recorded at the first activity resume.
fun installAndroid(application: Any, release: String? = null, environment: String? = null, sampleRate: Double = 1.0)application is an android.app.Application.
SovariaPerf.uninstall
fun uninstall()SovariaPerf.markAppReady
The app is ready (first screen drawn): records the cold start once per launch.
fun markAppReady()SovariaPerf.screen
fun screen(name: String): PerfTraceSovariaPerf.trace
suspend fun <T> trace(name: String, attributes: Map<String, Any?> = emptyMap(), block: suspend () -> T): TSovariaPerf.record
Queue one measurement; false when not installed or not sampled.
fun record(kind: String, name: String, value: Double, route: String? = null, traceId: String? = null,
attributes: Map<String, Any?> = emptyMap()): BooleanSovariaPerf.flush
Send queued measurements now.
suspend fun flush()PerfTrace
A running screen or custom trace; end records it once.
class PerfTrace internal constructor(private val perf: SovariaPerf, private val kind: String, private val name: String,
private val attributes: Map<String, Any?> = emptyMap())PerfTrace.end
fun end()