Mobile - Android

Installation, Implementation, and Updates.


Official Android SDK for Sprig (Releases)

This SDK is designed to work with Android SDK 21 (Android Lollipop, OS 5.0) and above.

If using minSdk below 21, you can override the library in your main AndroidManifest.

<manifest xmlns:android=""

    <uses-sdk tools:overrideLibrary="com.userleap" />

Make sure to check the OS system version before calling Sprig.

    Sprig.configure(context, "ENVIRONMENT_ID")


You can install the Sprig SDK via maven central.

dependencies {
    implementation 'com.userleap:userleap-android-sdk:2.6.9'

Add Java 8 support to your project (if not added already)

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  // For Kotlin projects
  kotlinOptions {
    jvmTarget = "1.8"

If you experience build issues like "Failed to find the generated class", please try adding this to your proguard rules

-keep class com.userleap.** { *; }
-keep class sprig.** { *; }

Software Dependencies

Maintain the same dependency versions in your app as follows:


These permissions are automatically merged into your app Manifest.

  • INTERNET - send and receive events and studies

App size impact

The Sprig SDK AAR size is 211 KB.

The impact to an Android App Bundle is around 650 KB. Note: The Sprig SDK uses the common dependencies listed above. The actual size impact will be smaller if these dependencies are already used by the app.

Methodology: Build a ProGuarded release Android App Bundle in Android Studio with an Empty Activity project. Then compare size after adding the Sprig SDK.


Initializing the SDK

In order to use the SDK, you need to configure the SDK for your app. Do this before calling any other Sprig functions. A convenient place to configure Sprig is in your class that extends Application.

Sprig.configure(context, "ENVIRONMENT_ID")

The ENVIRONMENT_ID for your deployment can be found in the Connect page of the Sprig Dashboard.

This study always displays a debug study and the results are submitted to Sprig.

Identifying users

User ID

Sprig allows you to identify users by supplying a userId. While tracking userIds is optional, it helps to provide a consistent experience across platforms and prevents users from seeing the same study multiple times.

The user identifier should be unique and mappable to your internal user id in some way.

Set the userId after configuring if they are already logged in or after the user logs in to your app:


This user identifier is stored locally and this method can be called multiple times safely. We recommend you set the user identifier every time you configure Sprig and anytime your customer's login to be safe.



Sprig enforces recontact windows and study eligibility based on the user ID associated with the current user, and tracks this user ID across multiple sessions and devices. If no user ID is provided, Sprig will only enforce recontact windows against the current anonymous visitor ID.

Email address

You can also provide Sprig with the user's email address. It is not required for Web and Mobile studies but is required to enable Email-based studies.


Segmenting your users with attributes

Sprig allows you to associate attributes to each user. These attributes are surfaced as survey filter options in the Sprig dashboard, and allow you to send studies to users with certain attributes.

Sprig.setVisitorAttributes(mapOf("key" to "value", "plan" to "enterprise"))

Sprig automatically tracks and attaches the following attributes:

  • App version
  • Android version
  • SDK version

Some common attributes you can set are:

  • Location
  • Referral channel
  • A/B test group
  • Network connectivity status
  • Battery level

Tracking user events to display studies

Sprig provides a convenient method for you to track an event and display a study if that event is a trigger for an active study and the visitor is eligible.

val payload = EventPayload(event = "EVENT_NAME", properties = mapOf("key" to "value"))
Sprig.trackAndPresent(payload, YOUR_FRAGMENT_ACTIVITY)



Sprig will automatically check if a user is eligible based on your study's filter constraints, and determine study eligibility for you.

Alternatively, if you want to know the state of the survey you can add in a when statement as follows:

val payload = EventPayload(event = "EVENT_NAME", properties = mapOf("key" to "value"))
Sprig.track(payload) { surveyState ->
    when (surveyState) {
        SurveyState.READY -> {
            // We received a survey for the event, present it to the user
        SurveyState.NO_SURVEY -> {
            // No survey available based on event
        SurveyState.DISABLED -> {
            // Sprig has been disabled remotely

After sending each tracking event, you can check if a new survey is ready for the user. If a survey is ready, you can decide to present the survey to the user. The survey is presented on a modal bottom sheet.

These events will also be available as filters for your studies. For example, you may want to restrict a study to users who performed the "checkout" event at most 3 times.



If your colleague used the UI to add a Code event, you will need to name the event identically. The snippet is also available from the clipboard to make for fast easy copy in the UI on the Events page for that event.

Tracking user events for filtering only (Not recommended)

You can call the track() method without providing a callback to use that event as only a filter. We don't recommend this because if your product needs change and you want this to be a trigger for a study, it will require developer time to update the callsite.

val payload = EventPayload(event = "EVENT_NAME", properties = mapOf("key" to "value"))

Example Study

Verifying your Event-based Studies

There are checks in place to make sure we show studies at the right time, see Recontact Waiting Period. To test that your studies show with the right attributes and events set, be sure to set up the SDK with your development ENVIRONMENT_ID. This will bypass throttling and the recontact window.



While studies can be configured to trigger and display from multiple events, only one of those events needs to occur to display a study (assuming a user also meets your survey's filter criteria).

User logout

When a user logs out of your app, make sure to log that user out of the Sprig SDK. This will prevent any new activity from being associated with the wrong user.


Set Locale

Sprig has the ability to set the locale of a study with the set.Local() function. The following locales are supported:

  • de
  • en
  • es-es
  • fr
  • hi
  • ja
  • ko
  • pt-br
  • ru
  • zh

To set the local to Switzerland, for Android:




Setting the locale will only set the static texts. This function does NOT exist in React Native, only iOS and Android.


We adhere to Semver for versioning our SDKs so upgrading between minor versions or patches (e.g. 1.0.1-> 1.1.0) should not present any breaking changes.

Note: 1.2.1 is the same as 2.0.0, we've bumped the major version to signify that versions below 1.2.1 will be disabled/deprecated by Feb 12, 2021

Upgrading from 1.x.x to 2.x.x

  • Sprig.visitorIdentifier which returns Int? will always return null for new visitors. Use the new Sprig.visitorIdentifierString which returns String?

The latest Sprig SDK release is shown here.