Mobile - Android

Installation, Implementation, and Updates.

📷

UserLeap is now Sprig

We might have changed our name, but you don't have to change a thing!
All of your surveys, integrations, and code will continue to function properly with no action required.

Installation

Official Android SDK for Sprig/UserLeap (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="http://schemas.android.com/apk/res/android"
  package="com.myapp"
    xmlns:tools="http://schemas.android.com/tools">

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

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

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Sprig.configure(context, "ENVIRONMENT_ID")
}

Gradle

You can install the Sprig SDK via maven central.

dependencies {
    implementation 'com.userleap:userleap-android-sdk:2.3.0'
}

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"
  }
}

Dependencies

Permissions

These permissions are automatically merged into your app Manifest.

  • INTERNET - send and receive events and surveys

App size impact

The Sprig SDK AAR size is 373 KB.

The impact to an Android App Bundle is 1.2 MB. 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.

Implementation

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.

Verifying your SDK Installation

You can verify you’ve set up the installation and environment ID correctly by adding the following line:

Sprig.presentDebugSurvey(activity)

This survey always displays a debug survey 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 survey 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:

Sprig.setUserIdentifier("USER_ID")

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.

️ Warning

Sprig enforces resurvey windows and survey 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 resurvey 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 surveys but is required to enable Email-based surveys.

Sprig.setEmailAddress("EMAIL_ADDRESS")

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 surveys to users with certain attributes.

Sprig.setVisitorAttribute("KEY", "VALUE")

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

Sprig can track events inside your mobile app by calling the track() function and passing the event name as an argument.

️ Info

Your engineering team will want to place track() code after any action or context, denoting to Sprig that the event has occurred. 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.

Sprig.track("EVENT_NAME")

These events can be used as part of your filters for triggering a survey, but will not display a survey to your users.

Displaying surveys to users

Instead of strictly tracking when user events occur, we can send events to Sprig and also display a survey, should the user qualify for one. We can do this by modifying the prior track() call, and adding in a when statement as follows:

Sprig.track("EVENT_NAME") { surveyState ->
    when (surveyState) {
        SurveyState.READY -> {
            // We received a survey for the event, present it to the user
            Sprig.presentSurvey(activity)
        }
        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.

Example MicrosurveyExample Microsurvey

Example Microsurvey

Verifying your Event-based Surveys

We have checks in place to make sure we show surveys at the right time (See Survey Eligibility). To test that your surveys 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 re-survey window.

📘

Info

While surveys can be configured to trigger and display from multiple events, only one of those events needs to occur to display a survey (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.

Sprig.logout()

Updates

We adhere to Semver for versioning our SDKs so upgrading between major versions (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.