Segment
With Segment, you can manage data and integrations with services across your Growth, Product, and Marketing stack. By tracking events and users through Segment's API and libraries, you can send your product's data to all your analytics and marketing platforms with minimal instrumentation. Segment supports most platforms, including iOS, Android, JavaScript, Node.js, and PHP.
This guide complements Segment's Amplitude (Actions) documentation. It provides more details on how the integrations affect your data in Amplitude, and instructions for setting up the integrations.
Segment's Amplitude (Classic) destination
Segment has an old destination, Segment's Amplitude (Classic). Future updates are limited to security updates and bug fixes. This document focuses on the new destination, Segment's Amplitude (Actions).
Set up the integration
To send data to Amplitude, you can:
- Install Amplitude's SDKs and send data directly to Amplitude through client-side bundled integration.
- Set up a Segment destination and connect it with a Segment source.
Set up Segment Destinations
Follow these steps with your Amplitude API key.
To ensure that Segment can send data to Amplitude, make sure your Segment's Amplitude destination connects to one of your Segment sources:
- In your Segment workspace, click Connections -> Sources.
- Verify the status of your Amplitude destination is set to Enable to allow Segment to send data to Amplitude.
Send data to your Segment source, and validate your events in Amplitude.
Client-side bundled integration
In addition to Segment's libraries, you can install Amplitude's SDKs. If you do, Segment's library delegates the data collection to Amplitude's SDK, which then sends the data to Amplitude's servers.
The client-side bundled approach has advantages and disadvantages. One advantage is that adding Amplitude native SDKs adds session tracking capability and automatic user property tracking:
- Amplitude groups events logged during the same user session together when viewing that user's stream on Amplitude Dashboard. This also allows for session length calculations.
- The SDKs automatically record several user properties such as device type, operating system, and user agent. For the list of user properties tracked automatically by Amplitude's SDKs, refer to the user property definitions.
- By enabling Track Session Events, you can ensure the SDKs automatically send
Start SessionandEnd Sessionevents to mark the start and end of a user's mobile session. - When you install Amplitude's SDKs, you can interact with them directly. Refer to the docs for iOS SDK and Android SDK to learn more.
Note that adding more SDKs increases the size of your application (each one is <200kb). You may have to account for this if you already use several libraries in your app. These SDKs are optional, and you can still conduct almost the same analysis in Amplitude by using only Segment's libraries.
Without session tracking:
- Events have a session ID of -1, so events triggered by a user during the same session aren't grouped together when viewing that user's timeline in Amplitude.
- Session length calculations aren't available in Amplitude, so the User Sessions chart doesn't display any data.
- Amplitude's Pathfinder and Pathfinder Users charts can't display out-of-session events alongside events within a session.
- You can't perform session-based Funnel Analysis effectively.
Without Amplitude's SDKs, you have to map user properties such as device type and operating system manually to track them, as described in Segment's docs.
Set up Segment Sources
Set up a Segment Source to send data to Segment.
JavaScript (client-side)
Follow Segment's Analytics.js quickstart guide and paste the snippet onto your website. Don't forget to put your Segment write key in the snippet.
You are now ready to use track and identify to track users. Analytics.js also automatically installs Amplitude's JavaScript SDK onto your website, so you can access the JavaScript SDK directly.
You can configure settings for the JavaScript integration in the Advanced Settings of your Segment Amplitude integration panel, without changing your instrumentation:
- Batch Events (default false): When true, you can send events in batches of 30, or every 30 seconds. You can adjust these two thresholds by changing the values of Event Upload Threshold and Event Upload Period Millis.
- Track All Pages to Amplitude, Track Categorized Pages to Amplitude, and Tracking Named Pages to Amplitude (default false): When true, calling
pagegeneratesViewed ___ Pageevents. If you select more than one of these three options at a time, a singlepagecall generates multiple events. - Track Referrer to Amplitude (default false): When true, Amplitude captures the user's referrer, initial referrer, and referring domain as user properties.
- Track UTM properties (default false): When true, Amplitude captures UTM properties from URL parameters or the cookie as user properties.
iOS (client-side)
If you send screen calls to Amplitude, review these destination settings.
Follow Segment's iOS quickstart guide. Install the Analytics pod using CocoaPods, import the SEGAnalytics.h header file, and initialize Segment's library in your iOS app.
You can now start calling track and identify to track users in your app. You also have the option to install Amplitude's iOS SDK alongside Segment's library to add more tracking capabilities. The pros and cons of adding Amplitude's SDK appear in Client-side bundled integration. If you choose to add the Amplitude SDK, follow these steps:
Install a second pod 'Segment-Amplitude' in CocoaPods:
pod 'Segment-Amplitude'.If you use Objective-C, add this second header in the file where you initialized the Segment SDK:
#import <Segment-Amplitude/SEGAmplitudeIntegrationFactory.h>.If you use Swift and have
use_frameworks!set, add this second header in the file where you initialized the Segment SDK:#import <Segment\_Amplitude/SEGAmplitudeIntegrationFactory.h>.Register Amplitude's SDK with Segment's SDK (do this before you initialize Segment's SDK):
obj-c[configuration use:[SEGAmplitudeIntegrationFactory instance]]; [SEGAnalytics setupWithConfiguration:configuration];
For code examples, refer to the Segment iOS demo code.
Android (client-side)
If you send screen calls to Amplitude, review these destination settings.
Follow Segment's Android quickstart guide. Install Segment's library using Gradle and initialize the Analytics client in your Android app. You may also need to update your app's permissions in the Android manifest file.
You can now start calling track and identify to track users in your app. You also have the option to install Amplitude's Android SDK alongside Segment's library to add more tracking functionality. The pros and cons of adding Amplitude's SDK appear in Client-side bundled integration. If you choose to add the Amplitude SDK, follow these steps:
Add the following to your
build.gradlefile:compile 'com.segment.analytics.android.integrations:amplitude:+'.In the file where you initialize the Segment SDK, add:
import com.segment.analytics.android.integrations.amplitude.AmplitudeIntegration;.Register the Amplitude integration with Segment's SDK. When building the Analytics object, append
.use(AmplitudeIntegration.FACTORY)before the.build(). It would look something like this:javaAnalytics analytics = new Analytics.Builder(this,"KEY").use (AmplitudeIntegration.FACTORY).build(); Analytics.setSingletonInstance(analytics);
For code examples, refer to the Android demo code.
Server-side and other libraries
Follow the appropriate instructions in Segment's documentation.
Mappings between Segment and Amplitude SDK functions
Segment and Amplitude use slightly different terms to describe the same concepts. The following table shows the mapping between the two:
| Segment | Amplitude | Description |
|---|---|---|
track (with properties) | track (with properties) | Logs an event with the specified event properties. |
| track with property "revenue" | revenue | Logs a revenue event to record a revenue amount. |
identify with traits | setUserId, identify | Assigns a userId and set any traits as user properties. |
screen / page with name | track "Viewed" + name | Logs an event "Viewed [page]" where [page] is the name provided. |
alias | User Mapping (Aliasing) | UserId aliasing lets you merge two users together that would otherwise have different User IDs tracked in Amplitude. |
group | groupIdentify (with GroupName) | Lets you designate user groups. |
For more information, refer to the Segment documentation.
Export cohorts to Segment
Amplitude Activation lets you automatically send behavioral audiences to ad networks, marketing automation tools, and personalization engines so you can better tailor campaigns and product experiences.
Refer to Send Cohorts to Segment for more information.
More help
Contact Segment support (friends@segment.com) or Amplitude support.
Was this helpful?