Flush API in Kotlin SDK Alpha

Manually flush your stored events by leveraging the flush API.

This guide walks you through the flush API and the different event flushing policies supported by RudderStack.

Overview

The Kotlin SDK provides a flush API that lets you manually flush any stored events irrespective of the configured flush policies.

You can trigger a flush API call as follows:

analytics.flush()
warning
If you have added a mobile device mode integration plugin, then a flush API call will also trigger the integration’s flush API, if it is supported.

Flush policies

RudderStack supports three configurable flush policies. By default, all three policies are enabled.

Count flush policy

The CountFlushPolicy triggers a flush call when a predefined threshold for the event count is reached.

Flush policiesData typeNotes
flushAtIntegerThe value of this parameter must be within the range of 1 to 100 - the default value is 30.

Frequency flush policy

The FrequencyFlushPolicy automatically triggers a flush at the specified intervals.

Flush policiesData typeDescription
flushIntervalInMillisLongMinimum allowed value is1 millisecond - the default value is 10 seconds.

Startup flush policy

The StartupFlushPolicy automatically triggers a one-time flush API call after the Kotlin SDK is initialized.

Set a flush policy

You can select and set a flush policy depending on your use case.

The following example highlights how you can set the FrequencyFlushPolicy:

warning
Selecting a flush policy from the provided list overrides the default flush policy.
  1. Import the flush policy as shown:
import com.rudderstack.sdk.kotlin.core.internals.policies.FrequencyFlushPolicy
  1. Add FrequencyFlushPolicy during the SDK initialization, as shown below. Replace the WRITE_KEY and DATA_PLANE_URL parameters in the below snippet with the Kotlin source write key and your data plane URL.
analytics = Analytics(
    configuration = Configuration(
        writeKey = BuildConfig.WRITE_KEY,
        application = application,
        dataPlaneUrl = BuildConfig.DATA_PLANE_URL,
        flushPolicies = listOf(
            FrequencyFlushPolicy()
        )
    )
)

Questions? Contact us by email or on Slack