Android-Kotlin SDK reference

This reference documents every public export of com.amplitude:analytics-android that you use to instrument an app, and every configuration option, verified against version 1.36.0. Classes that the SDK marks "Not intended for public use", such as its storage and timeline classes, aren't listed. For options, go to Configuration options. To find the release that added or changed a feature, go to Android-Kotlin SDK release notes.

kotlin
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
import com.amplitude.android.ConfigurationBuilder

The SDK exposes com.amplitude:analytics-core as an API dependency, so core types such as com.amplitude.core.events.Identify and com.amplitude.core.ServerZone are on your classpath. com.amplitude.android.events re-exports BaseEvent, EventOptions, Identify, IdentifyEvent, GroupIdentifyEvent, Revenue, RevenueEvent, Plan, and IngestionMetadata. Every method on this page is a method of the Amplitude instance. Most return the instance, so calls chain.

Setup

Amplitude

Creates an instance and starts setup in the background.

kotlin
// Kotlin DSL (top-level function)
fun Amplitude(apiKey: String, context: Context, configs: ConfigurationBuilder.() -> Unit): Amplitude

// Constructor
Amplitude(configuration: Configuration)
val amplitude = Amplitude("YOUR_API_KEY", applicationContext) {
    flushQueueSize = 20
}

ConfigurationBuilder requires 1.27.0 or later. In Java, use it instead of new Configuration(apiKey, context): only the deprecated Configuration constructor has Java overloads, and it can't set autocapture, interactionsOptions, httpClient, enableDiagnostics, enableRequestBodyCompression, or enableAutocaptureRemoteConfig. Java can also call the DSL as AmplitudeKt.Amplitude(...).

Creating an instance with the same instanceName as a live instance retires the older one. The older instance logs Amplitude instance '<name>' was replaced by a newer instance with the same name and is now inactive. and drops new events. Requires 1.30.1 or later.

isBuilt

Completes when setup finishes: storage, stored identity, legacy data migration, and plugins.

kotlin
val isBuilt: Deferred<Boolean>
kotlin
amplitude.isBuilt.await() // inside a coroutine

add

Registers a plugin. If a plugin with the same non-null name is already registered, the SDK keeps one.

kotlin
fun add(plugin: Plugin): Amplitude
fun add(plugin: UniversalPlugin): Amplitude

remove

Removes a plugin you added. Pass the same instance.

kotlin
fun remove(plugin: Plugin): Amplitude
fun remove(plugin: UniversalPlugin): Amplitude

findPlugin, plugin, and plugins

Look up registered plugins.

kotlin
inline fun <reified T : Plugin> findPlugin(): T?
fun plugin(name: String): UniversalPlugin?
fun <T> plugins(clazz: Class<T>): List<T>

flush

Uploads queued events now. Returns right away; the upload runs in the background after setup finishes.

kotlin
fun flush()

logger

The instance logger. Default: Logcat with the tag Amplitude, level INFO.

kotlin
val logger: Logger
kotlin
amplitude.logger.logMode = Logger.LogMode.DEBUG

Logger.LogMode values: DEBUG, INFO, WARN, ERROR, OFF.

Tracking

track

Queues an event for upload.

kotlin
@JvmOverloads
fun track(eventType: String, eventProperties: Map<String, Any?>? = null, options: EventOptions? = null): Amplitude

@JvmOverloads
fun track(event: BaseEvent, options: EventOptions? = null, callback: EventCallBack? = null): Amplitude
kotlin
amplitude.track("Song Played", mapOf("title" to "Happy Birthday"))

logEvent(event: BaseEvent) is deprecated. Use track.

identify

Sends user property operations as an $identify event.

kotlin
@JvmOverloads
fun identify(identify: Identify, options: EventOptions? = null): Amplitude

@JvmOverloads
fun identify(userProperties: Map<String, Any?>?, options: EventOptions? = null): Amplitude

The Map form sets each property. It drops entries whose value is null, so it can't unset a property; use Identify().unset(). When options sets userId or deviceId, the SDK applies them to the instance's identity along with the properties.

kotlin
amplitude.identify(Identify().set("plan", "premium").add("login_count", 1))

The SDK merges identify events that contain only set operations and sends them after identifyBatchIntervalMillis, or before the next other event. Requires 1.7.0 or later.

setGroup

Assigns the user to a group, and sets groupType as a user property.

kotlin
@JvmOverloads
fun setGroup(groupType: String, groupName: String, options: EventOptions? = null): Amplitude

@JvmOverloads
fun setGroup(groupType: String, groupName: Array<String>, options: EventOptions? = null): Amplitude
kotlin
amplitude.setGroup("orgId", "15")
amplitude.setGroup("sport", arrayOf("tennis", "soccer"))

groupIdentify

Sets properties on a group with a $groupidentify event.

kotlin
@JvmOverloads
fun groupIdentify(groupType: String, groupName: String, identify: Identify, options: EventOptions? = null): Amplitude

@JvmOverloads
fun groupIdentify(groupType: String, groupName: String, groupProperties: Map<String, Any?>?, options: EventOptions? = null): Amplitude
kotlin
amplitude.groupIdentify("plan", "enterprise", Identify().set("seats", 50))

revenue

Tracks a revenue_amount event.

kotlin
@JvmOverloads
fun revenue(revenue: Revenue, options: EventOptions? = null): Amplitude
fun revenue(event: RevenueEvent): Amplitude

The SDK drops a Revenue without price and logs Invalid revenue object, missing required fields. Go to Revenue. logRevenue(revenue: Revenue) is deprecated. Use revenue.

Identity

getUserId and setUserId

kotlin
fun getUserId(): String?
fun setUserId(userId: String?): Amplitude

null clears the user ID. Setting the current value again does nothing.

getDeviceId and setDeviceId

kotlin
fun getDeviceId(): String?
fun setDeviceId(deviceId: String): Amplitude

getDeviceId() can return null until isBuilt completes. For how the SDK picks a device ID, go to How the SDK chooses identifiers on startup.

reset

Clears the user ID and the local user properties from setIdentity, then picks a device ID again. Doesn't start a new session.

kotlin
fun reset(): Amplitude

reset() skips only the stored device ID. It keeps the same device ID when you set the deviceId configuration option, useAdvertisingIdForDeviceId, or useAppSetIdForDeviceId. To get a new device ID, call setDeviceId() after reset().

identity and setIdentity

Reads or replaces the user ID, device ID, and local user properties in one step.

kotlin
val identity: AnalyticsIdentity

fun setIdentity(identity: AnalyticsIdentity): Amplitude

@JvmOverloads
fun setIdentity(userId: String?, deviceId: String?, userProperties: Map<String, Any?> = emptyMap()): Amplitude

AnalyticsIdentity has userId, deviceId, and userProperties. The user properties live in memory for the current process and aren't stored. When setIdentity changes them to a non-empty map, the SDK sends one $identify event that sets them. Removing a property from the map doesn't unset it in Amplitude. Passing deviceId = null clears the device ID, and omitting userProperties clears the local map. While opted out, the SDK updates the local identity but sends nothing.

kotlin
amplitude.isBuilt.await()
amplitude.setIdentity("user-123", amplitude.getDeviceId(), mapOf("plan" to "paid"))

identity requires 1.30.0 or later. setIdentity and identity.userProperties require 1.36.0 or later.

Sessions

sessionId

The current session ID, a timestamp in milliseconds, or -1 before the first session starts.

kotlin
val sessionId: Long // Java: getSessionId()

Amplitude.START_SESSION_EVENT is "session_start" and Amplitude.END_SESSION_EVENT is "session_end".

onEnterForeground(timestamp) and onExitForeground(timestamp) are public but guarded with @GuardedAmplitudeFeature for SDK developers. The SDK detects foreground from the process lifecycle, so don't call them.

Privacy

optOut

Turns tracking off or on at runtime. While true, the SDK drops every event with Skip event for opt out config.

kotlin
var optOut: Boolean // Java: getOptOut() / setOptOut(boolean)

Identify

com.amplitude.core.events.Identify. Every method returns the Identify, so calls chain.

An Identify ignores an operation with an empty property name or a null value, a second operation on the same property, and any operation after clearAll(). It prints a warning to standard output, not Logcat.

Revenue class

com.amplitude.core.events.Revenue.

setReceipt(receipt: String, receiptSignature: String): Revenue sets receipt and receiptSig together. isValid() returns true when price is set.

Events

BaseEvent

com.amplitude.core.events.BaseEvent extends EventOptions and adds:

The SDK serializes at most 1024 keys in a property map and truncates strings to 1024 characters. A map with more keys throws IllegalArgumentException("Too many properties (more than 1024) in JSON") during upload. IdentifyEvent ($identify), GroupIdentifyEvent ($groupidentify), and RevenueEvent (revenue_amount) extend BaseEvent.

EventOptions

com.amplitude.core.events.EventOptions. Every field is a nullable var. A value you set overrides what the SDK would fill in.

EventCallBack

kotlin
typealias EventCallBack = (event: BaseEvent, status: Int, message: String) -> Unit

The SDK calls the callback when it finishes with an event: 200 and Event sent success. when Amplitude accepts the event, or the HTTP status and server error when the SDK drops it. The SDK doesn't call the callback for responses it retries. Go to Read the upload result.

Plan and IngestionMetadata

kotlin
Plan(branch: String? = null, source: String? = null, version: String? = null, versionId: String? = null)
IngestionMetadata(sourceName: String? = null, sourceVersion: String? = null)

Both have @JvmOverloads constructors. The SDK copies the configured plan and ingestionMetadata onto each event that doesn't have its own.

Plugin

com.amplitude.core.platform.Plugin.

The SDK runs Before, then Enrichment, then Destination plugins for each event. Utility and Observe plugins don't receive events.

NetworkTrackingPlugin

com.amplitude.android.network.NetworkTrackingPlugin is an OkHttp interceptor and a plugin. It tracks [Amplitude] Network Request events for requests through the OkHttp clients you add it to. Requires 1.21.0 or later, and OkHttp on your classpath. The com.amplitude.core.network classes with the same names are deprecated.

kotlin
NetworkTrackingPlugin(options: NetworkTrackingOptions = NetworkTrackingOptions.DEFAULT)

NetworkTrackingOptions

NetworkTrackingOptions.DEFAULT captures every host except Amplitude with status codes 500 to 599. The constructor has @JvmOverloads.

CaptureRule

Two constructors: by host, or by URL.

CaptureHeader(allowlist: List<String> = [], captureSafeHeaders: Boolean = true) captures the headers you list, case-insensitive, plus a built-in set of non-sensitive headers. It never captures authorization, cookie, or proxy-authorization. CaptureBody(allowlist: List<String>, excludelist: List<String> = []) captures JSON fields by path; * matches one level and ** matches any number of levels.

Utilities

FrustrationAnalyticsUtils

Excludes elements from rage and dead click detection. Requires 1.22.0 or later.

kotlin
FrustrationAnalyticsUtils.ignoreFrustrationAnalytics(view: View, rageClick: Boolean = true, deadClick: Boolean = true)
FrustrationAnalyticsUtils.unignoreView(view: View)
FrustrationAnalyticsUtils.isViewIgnored(view: View): Boolean
FrustrationAnalyticsUtils.isRageClickIgnored(view: View): Boolean
FrustrationAnalyticsUtils.isDeadClickIgnored(view: View): Boolean

// Jetpack Compose
fun Modifier.ignoreFrustrationAnalytics(rageClick: Boolean = true, deadClick: Boolean = true): Modifier

In Java, call the object through FrustrationAnalyticsUtils.INSTANCE.

Constants

com.amplitude.android.Constants.EventTypes and com.amplitude.android.Constants.EventProperties hold the autocapture event and property names, such as EventTypes.SCREEN_VIEWED ([Amplitude] Screen Viewed). The copies in com.amplitude.core.Constants and DefaultEventUtils are deprecated.

Configuration options

Set these in the Amplitude(apiKey, context) { } block, on a ConfigurationBuilder, or as named arguments to Configuration(...). Options that also have a runtime equivalent on the instance name it in the description.

Identity and session

Data collection

TrackingOptions

com.amplitude.android.TrackingOptions. Each disable method returns the object, so calls chain.

Delivery

Remote configuration and diagnostics

The SDK fetches remote configuration on every start, at most every 5 minutes, from sr-client-cfg.amplitude.com (EU: sr-client-cfg.eu.amplitude.com), even when both options are false. serverUrl doesn't apply to that request.

Autocapture options

AutocaptureOption

AutocaptureOption.ALL contains every value. Requires 1.22.4 or later. In Kotlin, build a set with autocaptureOptions { +sessions; +screenViews }; addAll() adds every value. For event properties, go to Autocapture.

InteractionsOptions

kotlin
InteractionsOptions(
    rageClick: RageClickOptions = RageClickOptions(enabled = true),
    deadClick: DeadClickOptions = DeadClickOptions(enabled = true),
)

Was this helpful?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

On this page