Segment Integration

Introduction

Segment makes it easy to send your data to AppsFlyer. Once you have tracked your data through Segment's open source libraries, the data is translated and routed to AppsFlyer in the appropriate format. AppsFlyer helps marketers to pinpoint targeting, optimize ad spend and boost ROI.

Getting Started

To begin the implementation, follow these steps:

Mobile Components

The Segment<>AppsFlyer SDK must be packaged in your app for both iOS and Android. The most detailed steps for setting up AppsFlyer via Segment may be found in each Github repo: 
iOS app and Android app.

Server-Side Components

AppsFlyer offers an augmentative server side HTTP API intended for use along side its mobile SDK. Use the server side destination alongside the mobile SDK to associate out-of-app events such as website or offline purchases with attributed users/devices. Read on for more information on this functionality.

 Important

The Server-to-Server integration should only be used for tracking in-app events. 


The server-to-server API is an AppsFlyer premium feature. Contact AppsFlyer's support or your CSM to enable it.

Dashboard Steps

To enable AppsFlyer in the Segment dashboard, follow these steps:

  • Enter your unique AppsFlyer Dev Key, which is accessible from your AppsFlyer account, in Segment’s destination settings.
  • Follow the instructions in the Github repos: Android SDK and iOS SDK.
  • After you build and release to the app store, your data is translated and sent to AppsFlyer automatically.

 Important

If you plan to use the server side destination for an Android project, enter your Android App ID. If you are using only the mobile SDK, Android projects require the AppsFlyer Dev Key. iOS projects always require both the AppsFlyer Dev Key and the Apple App ID. In addition, if you do use the server side destination, you cannot selectively disable calls sent to AppsFlyer via the Segment dashboard.

Identify

When you call .identify() in Segment, Segment uses AppsFlyer’s setCustomerUserID to send the userId that it was passed in. They are sent using AppsFlyer’s setAdditionalData(e.g., on Android SDK).

Therefore, you can only send identify calls if you have the AppsFlyer SDK bundled.

Track

When you call track, Segment translates it automatically and sends the event to AppsFlyer.

Segment includes all the event properties as callback parameters on the AppsFlyer event, and automatically translates properties.revenue to the appropriate AppsFlyer purchase event properties based on Segment's spec’d properties.

Finally, Segment automatically uses AppsFlyer’s transactionId-based de-duplication when sending an an orderId.

If you want to attribute offline events with a certain user or device, the server side destination may be employed.

AppsFlyer requires the following properties for this attribution:

AppsFlyer Device ID

Send the AppsFlyer Device ID with each event at integrations.AppsFlyer.appsFlyerId, see example below. This identifier is unique to each device and can be retrieved using the AppsFlyer SDK. It is a good idea to store this value in an external database where it may be easily accessible by a server or website environments.

Device Type

AppsFlyer requires the user’s device type as either 'ios' or 'android', passed at context.device.type object, see example below.

Advertising ID (Optional)

AppsFlyer recommends passing an Advertising ID (referred to as IDFA on iOS and Advertising ID on Android) at context.device.advertisingId, see example below.

// node.js library example
analytics.track({
  event: 'Membership Upgraded',
  userId: '97234974',
  context: {
    device: {
      type: 'ios',
      advertisingId: '159358'
    }
  },
  integrations: {
    AppsFlyer: {
      appsFlyerId: '1415211453000-6513894'
    }
  }
});

Check your specific serverside library docs for specifics on how to format the method properly.

Finally, the server-side component searches for the following properties and handle them specially:

ip
(This should be the ip of your customer–this is not collected by Segment’s libraries out-of-the-box)
timestamp
(Refer to AppsFlyer’s docs on how they process timestamps. Since our libraries generate a timestamp, we always set this value)
currency
(Defaults to "USD")
revenue
(For Order Completed / Completed Order events, precedence is given to total, falling back to properties.revenue)
All other properties
Sent to AppsFlyer as custom properties inside eventValue.

 Note

Make sure to calibrate/update the time window in AppsFlyer's dashboard to see your events.

Other Features

Set out below are the additional features available with the Segment implementation:

Revenue Tracking

The destination automatically recognizes spec’d revenue property and translates them to AppsFlyer’s revenue tracking method.

Receiving Conversion Data

AppsFlyer's Segment integration collects conversion data automatically and sends the received data back to Segment.  If you want to receive the conversion data to your application, use the following code, depending upon your operating system:

Android iOS
AppsflyerIntegration.cld = new AppsflyerIntegration.ConversionListenerDisplay() {
 @Override
 public void display(Map<String, String> attributionData) {
 for (String attrName : attributionData.keySet()) {
            Log.d(TAG, "attribute: " + attrName + " = " +
                    attributionData.get(attrName));
        }
    }
}

Transaction De-Duplication

The destination automatically recognizes the spec’d orderId property, and sends it as the Transaction ID to AppsFlyer for revenue de-duplication.

In-App Purchase Receipts

The destination does not currently support in-app purchase receipts. If this is important to you, contact support@appsflyer.com.

Deep Linking

The destination does not automatically support out-of-the-box deep linking (code must be written regardless).

Therefore, you can use AppsFlyer’s OneLink integration which is a single, smart, tracking link that can be used to track on both Android and iOS. OneLink tracking links can launch your app when it is already installed instead of redirecting the user to the app store.

For more details, review the AppsFlyer OneLink Setup Guide. More information is available in the AppsFlyer SDK Integration Guides (iOSAndroid) and Segment’s mobile FAQs (iOSAndroid).

Supported Sources and Connection Modes

The following sources and connection modes are supported:

  Web Mobile Server
📱 Device-based        ✅  
☁️ Cloud-based        ✅      ✅

To learn more about about Connection Modes and what dictates what is supported, click here.

Segment offers an optional device-based Connection Mode for Mobile data with AppsFlyer. If you want to use the features requiring client-based functionality, follow the steps above to ensure you have packaged the AppsFlyer SDK with Segment’s.

Settings

Segment lets you change the destination settings via your Segment dashboard without having to touch any code.

Android App ID

Find this in your AppsFlyer’s My App dashboard. It appears as: ‘com.appsflyer.myapp’. This is required for Android projects if you want to send events using the server side integration.

Apple App ID (iOS)

This is accessible from iTunes or in AppsFlyer’s My App dashboard. This is optional for Android projects, and is only required for iOS projects.

AppsFlyer Dev Key

Your unique developer ID from AppsFlyer, which is accessible from your AppsFlyer account.

Enable HTTP fallback (Android)

If selected, HTTPS calls fallback on HTTP

Roku App ID

Your Roku App’s ID. Find this under My Apps in AppsFlyer’s dashboard. This is required for Roku projects if you want to send events using the server-side integration.

Track Attribution Data

Send attribution data to Segment and other tools as a track call (mobile libraries only).

Was this article helpful?
0 out of 2 found this helpful