Mobile - React Native Module

Getting Started

Refer to the Android Installation documentation for platform-specific requirements and resources.

Refer to the iOS Installation documentation for platform specific requirements and resources.



The module currently supports Android SDK Version 21 (Lollipop, OS 5.0) and above. Any calls to the Sprig module from Android OS below version 21 are no-op.


Add the module to your package.json dependencies.

yarn add react-native-userleap

When installing for iOS, you need to do pod install first. And if you are updating, it's best to remove the Podfile.lock and run pod repo update first. So from your app top-level directory, run the following commands:

cd ios
rm Podfile.lock
pod repo update
pod install

Initializing the Module

Usage is simple and revolves around a singleton, conveniently named UserLeap. The singleton must be configured before it can be used. The most obvious place for this is in your app's entry point, but do what's appropriate for your application.

import UserLeap from 'react-native-userleap'


The ENVIRONMENT_ID for your deployment can be found in the Connect tab

Note:configure will only accept 1 environment id, calling it multiple times with different IDs will have no effect.

Note: If an installation error occurs on incompatible react versions, you may need to use the --legacy-peer-deps option

npm i --legacy-peer-deps

Note: If this error occurs on Android

Attempt to invoke virtual method'boolean com.facebook.react.uimanager.FabricViewStateManager.hasStateWrappper()

You can either update your react-native dependency to version 0.68.2 or later,
or, you can add the following snippet to the dependencies in the build.gradle file under the app directory. The version block is necessary in the snippet.

implementation ("androidx.appcompat:appcompat:1.3.1") {
        version {
            strictly '1.3.1'

Identifying users

User ID

Sprig allows you to identify visitors by supplying a userId. While tracking USER_IDs 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 customers log in to be safe.


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 study filter options in the Sprig dashboard, and allow you to send studies to users that meet certain attributes and conditions.

UserLeap.setVisitorAttribute('KEY', 'VALUE');

Sprig automatically tracks and attaches the following attributes:

  • App version
  • iOS/Android version
  • SDK version
  • Device type
  • System Language

Some common attributes to set are

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

Displaying studies to users

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



Sprig will automatically check if a user is eligible based on your study's filter constraints, and determine study eligibility for you. Your team does not need to code additional logic that validates a user's attribute criteria, before sending events to us.

UserLeap.track('EVENT_NAME', (surveyState) => {
  switch(surveyState) {
    case UserLeap.SurveyState.READY:
    case UserLeap.SurveyState.NO_SURVEY:
    case UserLeap.SurveyState.DISABLED:

Example Survey

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).


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