Once you add Sprig as a destination in the RudderStack dashboard, follow these steps to add it to your mobile project depending on your integration platform:
Follow the steps in this section to add Sprig to your Android project using the new Android (Kotlin) SDK:
1. Add dependencies
In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the following dependencies:
Sprig presents in-app surveys on a FragmentActivity instance. For surveys to render, you need to tell the integration which activity is currently in the foreground, from the activity’s lifecycle callbacks:
If no activity is set, the integration falls back to Sprig.track and the survey is not presented — the event is still delivered to Sprig.
Follow the steps in this section to add Sprig to your iOS project using the iOS (Swift) SDK. Note that the integration supports both Swift and Objective-C consumers.
1. Add the package
Add the Sprig integration using the Swift Package Manager:
In Xcode, select File > Add Package Dependencies….
Create a shared AnalyticsManager that owns the Analytics instance and the SprigIntegration. Keep a reference to sprigIntegration — it is needed to present the in-app surveys (explained in Step 3):
The Sprig SDK requires a UIViewController to present in-app surveys. Hand the integration the active view controller via setViewController(_:). The most common pattern is set-on-appear/clear-on-disappear:
The integration holds the view controller weakly, so the explicit nil clear is optional. If no view controller is set, the integration calls Sprig.track instead of Sprig.trackAndPresent and the event is still delivered.
Follow these steps to add the Sprig integration to your React Native project.
The React Native integration tracks the foreground Activity (Android) and the key window’s root UIViewController (iOS) automatically and forwards it to the Sprig SDK, so Sprig.trackAndPresent is invoked whenever a foreground host is available. No additional code is needed in your React Native components or in the host native code.
If no foreground host is available at the moment an event is tracked (for example, during cold-start before the first screen renders), the integration falls back to Sprig.track and the event is still delivered to Sprig — only the in-app survey UI is skipped for that event.
Sprig requires this step to display the survey. You can also set it as null to clear the values.
classMainActivity:AppCompatActivity(){overridefunonStart(){super.onStart()// pass the FragmentActivity instance, it is required by Sprig to display the survey.
SprigIntegrationFactory.FACTORY.setFragmentActivity(this@MainActivity)}}
Pass the instance of ViewController to RudderSprigFactory as shown:
Sprig requires this step to display the survey. You can also set it as nil to clear the values.
classViewController:UIViewController{overridefuncviewDidLoad(){super.viewDidLoad()// Do any additional setup after loading the view.// Pass ViewController instance to RudderSprigFactory. As Sprig SDK requires this to display the survey.RudderSprigFactory.instance.setViewController(self)}}
Identify
You can use the identify call to identify a user in Sprig.
If you send a track event called Signed Out, then RudderStack automatically maps it to the logoutUser event before sending it to Sprig. Otherwise, it maps the following event/properties to the corresponding Sprig fields:
RudderStack property
Sprig property
event Required
eventName
userId
userId
properties
properties
Sprig expects the event name to be present in the eventName key. Hence, if you send a track event named Product Added, RudderStack maps it to Sprig’s eventName key before sending it across to Sprig.
To display the survey, you must pass the ViewController instance for iOS and the FragmentActivity instance for Android, otherwise the survey won’t be displayed.
If you do not want to display the survey, you can skip setting FragmentActivity or ViewController. RudderStack then forwards the call to the Sprig.track API instead of Sprig.trackAndPresent.
Reset
The reset method resets the previously identified user and related information.
A sample reset call is shown:
analytics.reset()
analytics.reset()
RudderClient.getInstance()?.reset()
RSClient.getInstance().reset()
Logging
Both the Android (Kotlin) and iOS (Swift) SDK integrations forward the Sprig SDK’s internal log messages to the RudderStack logger, so they appear alongside the rest of your SDK output.
Android (Kotlin)
The Sprig Android SDK emits log messages with a severity (DEBUG, INFO, WARNING, ERROR, CRITICAL). The integration forwards each message to the RudderStack logger at the mapped severity, so Sprig output honours the log level you configure on the SDK.
Set the log level in Configuration when you initialize the SDK:
When the log level is Logger.LogLevel.NONE, the integration skips listener registration entirely and no Sprig output is forwarded.
iOS (Swift)
The Sprig iOS SDK emits log messages without a severity (its loggingEvent callback only carries a message string), so the integration forwards every Sprig message at the verbose level.
To see Sprig output, set the RudderStack log level to anything other than .none:
LoggerAnalytics.logLevel=.verbose
When the log level is set to .none, the integration skips listener registration entirely and no Sprig output is forwarded.
Questions? We're here to help.
Join the RudderStack Slack community or email us for support
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.