Segment is a Customer Data Platform (CDP) that collects and processes data from the users of your digital platforms and products. You can also use Segment to direct that data to other tools, making it a powerful tool for driving product experience insights with Sprig.
If your team is already leveraging Segment in your digital properties, you can use Segment to install the Sprig SDK as well as send the data Sprig needs to trigger and filter studies (like events and attributes).
This is an effective low-to-no-code option because it requires minimal code changes to deploy in-product Sprig studies. Even many of Sprig’s advanced features also require no changes to your codebase as long as you know what Segment functions your organization is already deploying.
Segment Actions vs Segment Classic
This install method leverages Segment Actions both to install the Sprig SDK and to send events and attributes to Sprig from Segment. In most cases, we recommend integrating Sprig with Segment Actions over Segment Classic, although certain use cases may require Segment Classic, such as passing data to Sprig from your product's backend. For more information, consult with your Segment administrator or our Segment Classic documentation.
- Join your teammates on Sprig (check with your Sprig admin whether team discovery is on, or simply have a team member invite you via your email address). This will give you access to your team’s environment IDs, as well as the interactive Installation Guide.
- You will either need to access your team’s Segment account, or work with your team’s Segment administrator.
- If you are planning to use Segment as a source for certain events and attributes, you may wish to consult with a developer on your team who has knowledge of how these events and attributes are expressed in the codebase.
- You have Segment's Swift library installed
If you are running Segment and wish to integrate your Segment instance with Sprig, you will first need to follow these steps to install the Sprig SDK.
Sprig provides two environments, Development and Production, each with its own corresponding ENVIRONMENT_ID (which can be found in Integrations > Segment iOS).
The Development environment is recommended for initially setting up and verifying your installation. Then, you can use the Production environment to deploy studies to real users.
In Segment, you will be connecting your app as a Source to Sprig as a Destination. This will enable the Segment SDK to pass data to the Sprig SDK.
To do this, follow these steps (or follow this video):
- In Segment, click Connections, then click Destinations.
- Search for “Sprig” and select the Sprig destination.
- Click Configure Sprig.
- Select your data source (e.g. your app).
- Enter an identifiable destination name and ensure Actions is selected.
- Copy your Environment ID from your Sprig Dashboard and paste it into the Environment ID field.
- Turn on Enable Destination and save your changes.
Next, you will need to install the Sprig plugin via SPM or via Package.swift.
Installing via SPM or via Package.swift
These are equivalent options — simply choose the installation method that you are more comfortable or familiar with.
- In Xcode > File > Add Packages, search for
https://github.com/UserLeap/analytics-swift-sprig(you can view or star the plugin repository on Github)
- Click Add Package
Open your Package.swift file and add the following to the dependencies section:
// ... other dependencies
If you have not migrated to Xcode 14 and need an Xcode 13 compatible version, you will need to use our legacy build:
// ... other dependencies
exact: Version(1, 2, 1, prereleaseIdentifiers: ["legacy"]) // the version number are in sequence: major, minor, patch, prereleaseIdentifier without '-'.
Then specify the name of the package:
.product(name: "SegmentSprig", package: "analytics-swift-sprig"),
Note the Sprig iOS SDK will also be installed as an additional dependency.
Go to your file that sets up your Segment Installation and add the following import:
import SegmentSprig // <-- Add this line
Add the following after you have initialized your
And that's it! All Users, Events, and Attributes that you send to the Segment SDK will automatically be forwarded to the Sprig SDK. Surveys will be presented on the top ViewController.
Each time a user is tracked by Sprig on an app with the SDK installed, they are assigned a unique visitor ID in Sprig that allows users to be targeted with studies when they perform specified behaviors.
While this is a requirement for targeting users with Sprig studies, these are still considered unauthenticated users until their Sprig visitor IDs are coupled with the unique USER_IDs assigned to users within your platform’s internal authentication framework.
We recommend that you follow this best practice when installing Sprig:
- This ensures consistency between the visitor IDs generated by Sprig and the ones in your internal database, product analytics/CDP, or data warehouse, allowing more effective targeting of studies.
- Your users have a consistent experience across platforms, and do not see the same study multiple times.
- It also optimizes the number of Monthly Tracked Users (MTUs) sent to Sprig, which impacts your billing.
If necessary, you can also use an anonymizing function or hash.
A good User ID is:
- Unique: Two users should not share the same User ID.
- Mappable: User IDs sent to Sprig should map back to your internal User IDs, either directly or anonymously.
- Static: Once assigned, a User ID should not change.
Once you've configured Sprig as a Segment destination above, users tracked from Segment's Identify method will be sent into Sprig:
Analytics.shared().identify("userId123", traits: ["firstName": "James", "lastName": "Gibbson"])
You can view these users in Segment in the Debugger, or in Sprig on the Users page.
When a user logs out of your app, make sure to log out of Sprig. This will prevent new activity from being associated with an incorrect user. Note that if you call
analytics.track("SOME_EVENT") on an unauthenticated user, Sprig will assign them a new profile and count this new user separately toward your MTU limit.
Logging out your users correctly
You must make the above call to log out your users and accurately track users in Sprig. Existing calls to Segment's
analytics.reset()in your codebase will log the user out of Segment but not out of Sprig, creating discrepancies in your data if an accompanying
"Signed Out"event is not tracked.
If you are already leveraging Segment's Track method, your events in Segment will automatically be passed to Sprig, and you do not need to do additional work.
Sprig uses events to trigger (display) studies after the user performs a specific action. They can also be used as a filter to target users who have previously performed an action.
To track an event, use:
Analytics.shared().track("Clicked Button", properties: ["plan": "Pro Annual", "accountType": "Wick"])
Now, go to your source site or app's Debugger page on Segment, and check to see if it has registered the
Clicked Button event. If it appears here, in Sprig's Events page, you will also see a banner showing that you have an event request to review. Click Manage Requests to see the event.
If you are already leveraging traits in Segment, your traits in Segment will automatically be passed to Sprig (as Attributes), and you do not need to do additional work.
Sprig allows you to track attributes, which can provide more context about the user to help you better understand their feedback. You can also use these attributes to filter your audience and target specific kinds of users. Some example attributes that can be tracked are:
- Plan type
- Super users / power users
A user’s attributes can be seen on their profile in the Users page, and are recorded and attached to any surveys response they submit. For more information, see Attributes.
In Segment, the equivalent of attributes are traits, and these are treated as a subset of the Identify spec.
To verify your SDK is configured properly, we recommend testing with your development
- Create a survey in your Sprig Development Environment
- Choose an approved event as a trigger for your study
- [For testing purposes only] Allow users to retake the survey and set the recontact waiting period to 0 days
- Track the approved event from your app
Congratulations! Your installation is complete and you can begin deploying.
Updated 6 months ago