Kotlin SDK Configuration Options Reference

Complete reference for the configuration options available in the RudderStack Kotlin SDK.

The RudderStack Kotlin SDK provides various configuration options to customize its behavior according to your requirements. This guide covers all the available configuration options and their usage.

Configuration class

The Configuration class is used to initialize the RudderStack SDK in your Android application. It defines the required parameters and optional configuration settings to customize the SDK behavior.

SDK configuration options

ParameterTypeDescription
writeKey
Required
StringThe source write key obtained from the RudderStack dashboard used for authentication.
application
Required
ApplicationThe Android Application instance used to initialize the SDK. It is used for accessing Android-specific functionality and tracking lifecycle events.
dataPlaneUrl
Required
StringThe URL of your RudderStack data plane (backend) where the events are sent.
trackApplicationLifecycleEventsBooleanEnables automatic tracking of application lifecycle events (app start, background, and foreground transitions).

Default value: true
trackDeepLinksBooleanEnables automatic tracking of deep link events.

Default value: true
trackActivitiesBooleanEnables automatic tracking of the activity lifecycle, triggering screen events for each activity.

Default value: false
collectDeviceIdBooleanEnables automatic collection of the device’s unique ID.

Default value: true
sessionConfigurationSessionConfigurationConfiguration settings for managing user sessions.

  • See Session Tracking for more information on session management in the Kotlin SDK.
  • See Session configuration for more information on the session configuration options and their default values.
controlPlaneUrlStringURL for remote configuration management.

Default value: https://api.rudderlabs.com
flushPoliciesList of flush policiesSpecifies when and how events are sent to the RudderStack backend.

See Flush policies in Kotlin SDK for more information.

Default value: listOf(CountFlushPolicy(), FrequencyFlushPolicy(), StartupFlushPolicy())
gzipEnabledBooleanEnables or disables Gzip compression for network requests.

Default value: false

Session configuration

The SessionConfiguration class provides the following parameters to customize session management:

ParameterTypeDescription
automaticSessionTrackingBooleanEnables automatic session tracking.

Default value: true
sessionTimeoutInMillisLongSets the timeout duration for automatic session tracking in milliseconds. It is the time between the app closed or backgrounded to being foregrounded or relaunched again.

The SDK times out a session and starts a new session after this time has elapsed.

Default value: 300000 (5 minutes)

When you enable trackDeepLinks, the SDK automatically captures a Deep Link Opened event when the app is launched via a deep link. This event includes the following properties:

PropertyTypeDescription
urlStringThe deep link URL used to open the app.

For example, https://example.com/app.
referring_applicationStringThe application or source that triggered the deep link.

For example, https://test.com/app.
info
The SDK automatically adds any query parameters present in the deep link URL as the deep link event properties.

Device ID collection

When you enable collectDeviceId, the SDK retrieves a unique device ID using the Settings.Secure.ANDROID_ID API and includes it in the event payload under the device.id field in the event’s context object.

warning
If the SDK retrieves an empty or invalid value for the device ID, it will not include the device.id field in the event payload’s context.

Request compression

When you set gzipEnabled to true, all /batch requests sent by the SDK will have their payloads compressed using Gzip compression, thereby reducing the size of the network requests.

Sample SDK initialization

The following snippet demonstrates how to initialize the Kotlin SDK with the supported configuration options:

val analytics = Analytics(
    configuration = Configuration(
        // Required parameters
        application = application,
        writeKey = "YOUR_WRITE_KEY",
        dataPlaneUrl = "YOUR_DATA_PLANE_URL",
        
        // Optional parameters
        controlPlaneUrl = "YOUR_CONTROL_PLANE_URL",
        trackApplicationLifecycleEvents = true,
        trackDeepLinks = true,
        trackActivities = true,
        collectDeviceId = true,
        sessionConfiguration = SessionConfiguration(
            automaticSessionTracking = true,
            sessionTimeoutInMillis = 3000
        ),
        gzipEnabled = true,
        flushPolicies = listOf(CountFlushPolicy(flushAt = 10)) // Sets custom flush policies
    )
)

Questions? Contact us by email or on Slack