Mobile - React Native Module

📷

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.

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.

📘

Info

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.

Installation

Add the module to your package.json dependencies.

yarn add [email protected]

️ Warning

If you are using Xcode 13 to build your app, you must specify the version of react-native-userleap to use: yarn add [email protected]

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'

UserLeap.configure('ENVIRONMENT_ID');

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.

Verifying your Module Installation

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

UserLeap.presentDebugSurvey();

This presents a test survey if everything has been configured correctly.

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 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:

UserLeap.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 customers log in to be safe.

Email

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.

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

Tracking user events

Sprig can track events inside your mobile app by calling the track() function and passing the event name as an argument. If your colleague, used the UI to add a Code event, you will need to name it identically. Navigate to the Events tab, select the Event then toggle between the SDKs to copy the snippet to your clipboard.

📘

Info

Your engineering team will want to place track() code after any action or context, denoting to Sprig that the event has occurred.

UserLeap.track(eventName: '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, you 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 switch statement as follows:

📘

Info

Sprig will automatically check if a user is eligible based on your survey's filter constraints, and determine survey 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:
      UserLeap.presentSurvey();
      break;
    case UserLeap.SurveyState.NO_SURVEY:
      break;
    case UserLeap.SurveyState.DISABLED:
      break;
  }
});
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

️ Warning

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

Logout

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.

UserLeap.logout();