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
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. Since 0.3.1 the user is saved on the device and restored on the next launch. From 0.4.0, the first identify for an anonymous ID always sends that event, even without traits, so what the app did before sign-in is linked to the user. An empty userId is ignored. See Identify users.
track
fun track(name: String, properties: Map<String, Any?> = emptyMap())fun track(name: String, properties: Map<String, Any?> = emptyMap(), category: String?) // 0.4.0+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.
category (0.4.0+) is lifecycle, navigation, interaction, identity or conversion, for example Codeskop.track("login_failed", props, category = "identity"). Any other value is logged and dropped, and the server works one out from the name. Names starting with $ are reserved for the SDK's own events and are dropped. In Swift: Codeskop.shared.track(name:properties:category:).
screen
fun screen(name: String, properties: Map<String, Any?> = emptyMap())Product analytics: records a screen view. Activities, and from 0.4.0 Fragments and iOS view controllers, are recorded automatically (captureScreens). For Compose, use trackNavigation below. The SDK adds previous_screen. Added in 0.3.0.
trackNavigation
fun Codeskop.trackNavigation(navController: NavController) // import com.codeskop.sdk.android.trackNavigationRecords a screen for every destination the NavController shows, named by route (with the package and query dropped), else by label, else by id. Call it once per controller; repeat calls are ignored. Works for Compose and fragment navigation, and needs androidx.navigation in your app (the SDK doesn't add it). Added in 0.4.0.
reset
fun reset()Clears the current user, for example on logout. The install ID is kept. From 0.4.0 it also starts a new anonymous ID, so the next person on a shared device isn't linked to this one.
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.
Since 0.3.1, attributes are sent with the event: scalars and lists of scalars, with nested objects dropped.
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(): BooleanUploads 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.
| Option | Type | Default | Description |
|---|---|---|---|
| method | String | required | HTTP method, such as GET or POST. |
| url | String | required | Full URL. Only the host and path are stored; the query string is dropped. |
| status | Int? | null | Response status. Leave null if the call failed before a response. |
| errorKind | String? | null | A short failure label, such as timeout or network_error. |
| requestBytes | Long | 0 | Request body size. |
| responseBytes | Long | 0 | Response body size. |
| timing | ApiTiming? | null | Phase timings in ms: dnsMs, connectMs, tlsMs, ttfbMs, totalMs (each optional). |
| headers | Map<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, captureHeartbeat, captureAppForeground and captureAppBackground. They're public only for technical reasons. Don't call them from your app; use CodeskopAndroid.init to start the SDK.CodeskopConfig
data class CodeskopConfig( val apiKey: String, val endpoint: String = "https://api.codeskop.com", val environment: String = "production", // sent as context.app.environment (0.3.1+) val sampleRates: Map<String, Double> = emptyMap(), val captureNetwork: Boolean = true, // 0.3.1+ val captureHeaders: Boolean = true, // 0.3.1+ val captureBodies: Boolean = false, // reserved: bodies are never captured val redactHeaders: Set<String> = setOf("authorization", "cookie", "set-cookie"), val redactQueryKeys: Set<String> = setOf("token", "apikey", "password", "secret"), // reserved val maxQueueMb: Int = 10, val heartbeatEnabled: Boolean = true, // 0.3.1+ val flushBatchSize: Int = 50, val captureExceptionMessages: Boolean = false, // 0.2.0+ val captureScreens: Boolean = true, // 0.3.0+)Full descriptions are on the Configuration page.
OkHttp adapter
| Option | Type | Description |
|---|---|---|
| OkHttpClient.Builder.codeskop() | OkHttpClient.Builder | Registers both of the pieces below in one call (0.2.0+). Import com.codeskop.sdk.okhttp.codeskop. |
| CodeskopOkHttpInterceptor() | okhttp3.Interceptor | Records failed calls (4xx, 5xx, timeouts, connection errors). Register with addInterceptor. |
| CodeskopEventListener.factory() | EventListener.Factory | Records timing for every completed call. Register with eventListenerFactory. |
Manifest keys
| Option | Type | Default | Description |
|---|---|---|---|
| codeskop.api_key | string | Not set | Public ingest key. Turns on auto-init. |
| codeskop.endpoint | string | https://api.codeskop.com | Ingest URL. |
| codeskop.capture_exception_messages | boolean | false | Send exception messages instead of [REDACTED] (0.2.0+). |
Automatic events
From 0.4.0 the SDK sends lifecycle events by itself, on every plan and never counted toward the analytics meter: $app_opened (cold on the first foreground of the process, warm on every return), $app_foregrounded, $app_backgrounded, $session_started, $session_ended and $app_updated. Every event carries a session_id and seq, and the session is saved on the device, so a restart within 30 minutes continues it. Taps aren't recorded automatically. See the event model.
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.