Segment iOS
Getting Started
Overview
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.
Requirements
- 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
Install SDK
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.
Obtain a Sprig Environment ID
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.
Set up Sprig as a Segment Destination
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.
Install the Sprig Plugin via SPM
- 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
Install the Sprig Plugin via Package.swift
Open your Package.swift file and add the following to the dependencies section:
dependencies: [
// ... other dependencies
.package(
url: "https://github.com/UserLeap/analytics-swift-sprig.git",
from: "1.2.1"
),
]
If you have not migrated to Xcode 14 and need an Xcode 13 compatible version, you will need to use our legacy build:
dependencies: [
// ... other dependencies
.package(
url: "https://github.com/UserLeap/analytics-swift-sprig.git",
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:
targets: [
.target(
name: "YourPackageName",
dependencies: [
.product(name: "SegmentSprig", package: "analytics-swift-sprig"),
]
)
]
Note the Sprig iOS SDK will also be installed as an additional dependency.
Initialize the Sprig Plugin
Go to your file that sets up your Segment Installation and add the following import:
import Segment
import SegmentSprig // <-- Add this line
Add the following after you have initialized your Analytics
object:
Analytics.add(plugin: SprigDestination())
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.
Identify Users
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.
Logout
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.
Analytics.shared().track("Signed Out")
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.
Track Events
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.
Track Attributes
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
- Company
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.
Test & Deploy
To verify your SDK is configured properly, we recommend testing with your development ENVIRONMENT_ID
.
- 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 about 1 year ago