Skip to content
Codeskop

API Reference: Android

Everything your app calls, in one place. Version 0.3.0. Packages: com.codeskop.sdk.android, com.codeskop.sdk.core and com.codeskop.sdk.okhttp.

Guarantees

  • Never throws. Every method is guarded. Failures inside the SDK are swallowed, never passed to your app.
  • Safe before init. Calls made before the SDK has started do nothing.
  • Non-blocking. No method does network or heavy disk work on the calling thread.
  • Thread-safe. Call from any thread.

CodeskopAndroid.init

com.codeskop.sdk.android
fun CodeskopAndroid.init(context: Context, config: CodeskopConfig)

Starts the SDK. Call once, from Application.onCreate. It returns immediately and does its setup in the background. Repeated calls are ignored. If the key isn't a public Codeskop key, the SDK stays off. Not needed if you use manifest auto-init.

The Codeskop object

com.codeskop.sdk.core.Codeskop is the entry point for everything after startup.

identify

fun identify(userId: String, traits: Map<String, Any?> = emptyMap())

Attaches later events to a user. Pass a stable ID from your own system, never an email. With product analytics (Growth and Scale, 0.3.0+), traits are also sent once as an identify event for the user's profile and segments. The user is held in memory, so call identify again when the app restarts with a signed-in user. See Identify users.

track

fun track(name: String, properties: Map<String, Any?> = emptyMap())

Product analytics: records a custom event. Property values may be text, numbers, booleans, null or lists of those. Added in 0.3.0. See Track events & screens.

screen

fun screen(name: String, properties: Map<String, Any?> = emptyMap())

Product analytics: records a screen view. Activities are recorded automatically (captureScreens); call this for Compose destinations and fragments. Added in 0.3.0.

reset

fun reset()

Clears the current user, for example on logout. The anonymous install ID is kept.

recordException

fun recordException(throwable: Throwable, attributes: Map<String, Any?> = emptyMap())

Reports an exception you caught yourself, as a handled exception event with its stack trace. The message is redacted unless captureExceptionMessages is on.

attributes in 0.2.0

The attributes parameter is accepted but not yet sent with the event.

setEnabled

fun setEnabled(enabled: Boolean)

Pauses (false) or resumes (true) capture on this device, for the current process. Has no effect before the SDK has finished starting. To keep capture off for a user who opted out, don't call init for them.

flush

suspend fun flush(): Boolean

Uploads queued events now, instead of waiting for the next scheduled sync. Returns true if a sync ran. Call it from a coroutine, for example lifecycleScope.launch { Codeskop.flush() }. You rarely need it; sync is automatic.

captureApiError / captureApiTiming

fun captureApiError(call: ApiCall)fun captureApiTiming(call: ApiCall)

Report an HTTP call yourself, for clients other than OkHttp. The OkHttp adapter calls these for you.

OptionTypeDefaultDescription
methodStringrequiredHTTP method, such as GET or POST.
urlStringrequiredFull URL. Only the host and path are stored; the query string is dropped.
statusInt?nullResponse status. Leave null if the call failed before a response.
errorKindString?nullA short failure label, such as timeout or network_error.
requestBytesLong0Request body size.
responseBytesLong0Response body size.
timingApiTiming?nullPhase timings in ms: dnsMs, connectMs, tlsMs, ttfbMs, totalMs (each optional).
headersMap<String, String>emptyMap()Headers to include. Anything in redactHeaders is masked.

Methods not to call

Codeskop also exposes methods the SDK uses internally, such as init(config), attachRuntime, sync, refreshConfig, captureAnr and captureHeartbeat. They're public only for technical reasons. Don't call them from your app; use CodeskopAndroid.init to start the SDK.

CodeskopConfig

com.codeskop.sdk.core
data class CodeskopConfig(    val apiKey: String,    val endpoint: String = "https://api.codeskop.com",    val sampleRates: Map<String, Double> = emptyMap(),    val redactHeaders: Set<String> = setOf("authorization", "cookie", "set-cookie"),    val maxQueueMb: Int = 10,    val flushBatchSize: Int = 50,    val captureExceptionMessages: Boolean = false,   // 0.2.0+    // Accepted, no effect in 0.3.0:    // environment, captureNetwork, captureHeaders, captureBodies,    // redactQueryKeys, heartbeatEnabled)

Full descriptions are on the Configuration page.

OkHttp adapter

OptionTypeDescription
OkHttpClient.Builder.codeskop()OkHttpClient.BuilderRegisters both of the pieces below in one call (0.2.0+). Import com.codeskop.sdk.okhttp.codeskop.
CodeskopOkHttpInterceptor()okhttp3.InterceptorRecords failed calls (4xx, 5xx, timeouts, connection errors). Register with addInterceptor.
CodeskopEventListener.factory()EventListener.FactoryRecords timing for every completed call. Register with eventListenerFactory.

Manifest keys

OptionTypeDefaultDescription
codeskop.api_keystringNot setPublic ingest key. Turns on auto-init.
codeskop.endpointstringhttps://api.codeskop.comIngest URL.
codeskop.capture_exception_messagesbooleanfalseSend exception messages instead of [REDACTED] (0.2.0+).

Event types

The names used as sampleRates keys: crash, crash_native, anr, exception, api_error, api_timing, heartbeat. Crash and ANR types are never sampled.