AppsFlyer

AppsFlyer is an industry-leading mobile attribution and marketing analytics platform, provided as a Software-as-a-Service (SaaS). It offers exciting features to understand your customers better, through intuitive dashboards, real-time data reports, and a unique deep linking technology.

RudderStack allows you to configure AppsFlyer as a destination and send your event data to it directly.

Find the open-source transformer code for this destination in our GitHub repo.

Getting Started

To enable sending data to AppsFlyer, you will first need to add it as a destination to the source from which you are sending your event data. Once the destination is enabled, events from our SDK will start flowing to AppsFlyer.

Before configuring your source and destination on the RudderStack, please verify if the source platform is supported by AppsFlyer, by referring to the table below:

Connection ModeWebMobileServer
Device mode-Supported-
Cloud modeSupportedSupportedSupported

To know more about the difference between Cloud mode and Device mode in RudderStack, read the RudderStack connection modes guide.

Once you have confirmed that the platform supports sending events to AppsFlyer, perform the steps below:

Please follow our guide on How to Add a Source and Destination in RudderStack to add a source and destination in RudderStack.

  • Give a name to the destination and click on Next. You should then see the following screen:
screen shot 2021 06 08 at 4 01 45 pm
  • Enter the AppsFlyer Dev Key.
  • Sharing Filter is set to all by default. For more information on this field please visit the AppsFlyer docs here
  • If you are setting up an Android, iOS, or React Native SDK, you must enter the respective App ID for each SDK.
    • Android App ID is the application id used in your app/build.gradle file
    • Apple App ID is the iTunes Application ID, and it is mandatory for iOS applications.
  • By default, the Use native SDK to send events button will be toggles to on. If you would like to change this default behavior, select the toggle to choose between Cloud Mode and Device Mode.
  • Click on Next to complete the configuration.

AppsFlyer should now be added and enabled as a destination in RudderStack.

Adding AppsFlyer to your project

Depending on your platform of integration, follow these steps below to add AppsFlyer to your project:

To add AppsFlyer to your iOS project:
  • Add the following line to your CocoaPods Podfile
    pod 'Rudder-Appsflyer'
  • After adding the dependency, you must register the RudderAppsflyerFactory with your RudderClient initialization as a factory of RudderConfig. To do this, run the following command to import the RudderAppsflyerFactory.h file in your AppDelegate.m file.
    #import <Rudder-Appsflyer/RudderAppsflyerFactory.h>
  • Then, change the SDK initialization to the following:
    RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
    [builder withDataPlaneUrl:DATA_PLANE_URL];
    [builder withTrackLifecycleEvens:YES];
    [builder withRecordScreenViews:YES];
    [builder withFactory:[RudderAppsflyerFactory instance]];
    [builder withLoglevel:RSLogLevelDebug];
    [RSClient getInstance:WRITE_KEY config:[builder build]];
To add AppsFlyer to your Android project:
  • Add the repository as shown:
    repositories {
    mavenCentral()
    }
  • Add the following line to your app/build.gradle file under dependencies section:
    implementation 'com.rudderstack.android.sdk:core:1.+'
    implementation 'com.rudderstack.android.integration:appsflyer:1.+'
    implementation 'com.appsflyer:af-android-sdk:6.+'
    implementation 'com.android.installreferrer:installreferrer:2.+'
  • Finally, change the initialization of your RudderClient in your Application class.
    val rudderClient: RudderClient = RudderClient.getInstance(
    this,
    WRITE_KEY,
    RudderConfig.Builder()
    .withDataPlaneUrl(DATA_PLANE_URL)
    .withFactory(AppsFlyerIntegrationFactory.FACTORY)
    .build()
    )
To add AppsFlyer to your ReactNative project:
  • Add the RudderStack-AppsFlyer module to your app using :
    npm install @rudderstack/rudder-integration-appsflyer-react-native
    // OR //
    yarn add @rudderstack/rudder-integration-appsflyer-react-native
  • Import the module you added above and add it to your SDK initialization code in the following manner:
    import rudderClient from "@rudderstack/rudder-sdk-react-native"
    import appsflyer from "@rudderstack/rudder-integration-appsflyer-react-native"
    const config = {
    dataPlaneUrl: DATA_PLANE_URL,
    trackAppLifecycleEvents: true,
    withFactories: [appsflyer],
    }
    rudderClient.setup(WRITE_KEY, config)

Cloud Mode

For all cloud mode calls, the externalId key must be included and must include the id, as well as the type of appsFlyerExternalId as shown below:

"externalId": [
{
"id": "some_other2345_sample_external_id",
"type": "appsflyerExternalId"
}
]

We expect the externalId under context.

Identify

The identify call from RudderStack sets the userId through the setCustomerUserId method from AppsFlyerLib .

RudderStack sets the email from RudderTraits to AppsFlyer using the setUserEmails method from the native SDK.

[[RSClient sharedInstance] identify:@"developer_user_id"
traits:@{@"email": @"bar@foo.com"}];

Track

The track call from RudderStack is mapped to the appropriate standard events of AppsFlyer wherever possible.

We map the events as per the following table:

RudderStack EventAppsFlyer Event
Products Searchedaf_search
Product Viewedaf_content_view
Product List Viewedaf_list_view
Product Added to Wishlistaf_add_to_wishlist
Product Addedaf_add_to_cart
Checkout Startedaf_initiated_checkout
Order Completedaf_purchase
Product Removedremove_from_cart

Also, for any event with a name not matching the table above, RudderStack makes the following changes to the event name:

  • Convert the entire event name to lower case
  • Replace <space> with <underscore>

After these steps, RudderStack passes the event to AppsFlyer via the native SDK, along with the properties for that event.

Along with the above event mapping, the event property mapping is done as well, as shown:

RudderStack Property NameAppsFlyer Property Name
queryaf_search_string
priceaf_price
product_idaf_content_id
categoryaf_content_type
currencyaf_currency
productsWe formulate the list as per List View specification and pass it to the property af_content_list
quantityaf_quantity
order_idaf_receipt_id
revenueaf_revenue

A Sample track call for an iOS application will look like the below.

[[RSClient sharedInstance] track:@"Accepted Terms of Service"
properties:@{
@"foo": @"bar",
@"foo_int": @134
}];

Screen

For all the screen calls from the SDK, RudderStack calls the trackEvent method of the AppsFlyer SDK with the eventName as screen . Then, all the properties are passed to AppsFlyer as is.

RudderStack performs the same task for the automatically recorded screen calls as well. For those calls, a Boolean property called automatic is obtained in the properties.

Mobile SDK ID for Advertisers

Advertising ID

If the advertising ID is set according to the associated docs, RudderStack will utilize them appropriately for the AppsFlyer destination. They should be found in context.device.advertisementId

ATTrackingManager

If the ATTrackingManager.trackingAuthorizationStatus is passed appropriately according to this documentation, RudderStack will utilize it for the AppsFlyer destination. It should be found in context.device.attTrackingStatus

Error Messages

The following are possible error messages you may encounter.

Invalid platform or required androidAppId or appleAppId missing

This message will occur when either the OS Name is not set or your respective appId is not set. You can set the appId in your settings config (see the Getting Started section above). The OS Name should be set by the SDK automatically and it should be present at context.os.name

Appsflyer id is not set. Rejecting the event

This message will occur when the appsflyerExternalId is not set. Please refer to the Cloud Mode section above to see how to properly set the appsflyerExternalId.

Debugging

We set the logLevel in AppsFlyer based on the logLevel set for the RudderClient. If it is set for DEBUG or more, RudderStack sets the logLevel to VERBOSE for AppsFlyer. For anything below that, RudderStack sets the logLevel to NONE for AppsFlyer.

FAQs

Where do I get the AppsFlyer Dev Key?

You can find the AppsFlyer Dev Key by logging into your AppsFlyer account and navigating to the Apps Settings page in your dashboard.

Getting an error saying "Build input file cannot be found" for iOS device mode?

The latest AppsFlyer SDK requires XCode 12. Make sure to meet the requirement. You need to downgrade AppsFlyer SDK to build with a lower version of XCode. You can declare the version with the pod in your Podfile

pod 'Rudder-Appsflyer',' 1.0.0'

How do I get the AppsFlyerId to send events via Cloud mode from my mobile sources?

Depending on your platform of integration, include the following code snippet to get the AppsFlyerId:

#import <AppsFlyerLib/AppsFlyerLib.h>
NSString *appsflyerId = [AppsFlyerLib shared].getAppsFlyerUID;
import com.appsflyer.AppsFlyerLib;
String appsFlyerId = AppsFlyerLib.getInstance().getAppsFlyerUID(this);
import AppsFlyerIntegrationFactory from "@rudderstack/rudder-integration-appsflyer-react-native/src/bridge"
const appsFlyerId = await AppsFlyerIntegrationFactory.getAppsFlyerId()

This works only if your source has a device mode connection with AppsFlyer i.e the AppsFlyer native SDK is loaded through RudderStack.

Contact Us

If you come across any issues while configuring AppsFlyer with RudderStack, please feel free to contact us. You can also start a conversation on our Slack channel; we will be happy to talk to you!