Skip to main content
All Collections3rd-party integrationsAttribution
How can I connect Batch to AppsFlyer?
How can I connect Batch to AppsFlyer?

You can use AppsFlyer attribution data to improve your segmentation within Batch. The connection only requires a quick code addition.

Baptiste avatar
Written by Baptiste
Updated over 2 months ago

AppsFlyer is a mobile advertising attribution and analytics company. AppsFlyer helps marketers to pinpoint their targeting, optimize their ad spend and boost their ROI. 

On the other hand, Batch can receive information from AppsFlyer using their callbacks attribution. This will allow you to re-target your users with notifications based on the installation source.


Understanding how the connection works

Callbacks provided by AppsFlyer SDK allow you to sync AppsFlyer data with Batch SDK. You will be able to use Batch segmentation to target users based on install source attribution data.

iOS integration

After setting up the AppsFlyer attribution callback (iOS instructions on callbacks), you need to send Batch the appropriate data via the SDK's method.


Here is an example of how you can set the callback in your app code (using Batch V2 SDK):

import AppsFlyerLib
import Batch

extension AppDelegate: AppsFlyerLibDelegate {
func onConversionDataSuccess(_ conversionData: [AnyHashable : Any]) {
BatchProfile.editor { editor in
if let mediaSource = conversionData["media_source"] as? String {
try? editor.set(attribute: mediaSource, forKey: "appsflyer_source")
}
if let campaignId = conversionData["campaign"] as? String {
try? editor.set(attribute: campaignId, forKey: "appsflyer_campaign")
}
if let adSet = conversionData["af_adset"] as? String {
try? editor.set(attribute: adSet, forKey: "appsflyer_adset")
}
}
}

func onConversionDataFail(_ error: any Error) {
}
}

Android integration

Similarly, you need to set up the AppsFlyer attribution callback (Android instructions) and send Batch the attribution data via the SDK's method.

Here is an example of how you can set the callback in your app code (using Batch V2 SDK):

AppsFlyerLib.getInstance().registerConversionListener(this, object:
AppsFlyerConversionListener {
override fun onConversionDataSuccess(conversionData: MutableMap<String, Any>?) {
if (conversionData == null) {
return
}

Batch.Profile.editor().apply {
(conversionData["campaign"] as? String)?.let {
setAttribute("appsflyer_campaign", it)
}

(conversionData["media_source"] as? String)?.let {
setAttribute("appsflyer_source", it)
}

(conversionData["af_adset"] as? String)?.let {
setAttribute("appsflyer_adset", it)
}

save()
}

}

override fun onConversionDataFail(error: String?) {
}

override fun onAppOpenAttribution(data: MutableMap<String, String>?) {
}

override fun onAttributionFailure(error: String?) {
}

})

What’s next?

Now, you can test your integration using our debug tool and find out if your data work properly on the Batch dashboard. 

Once your tests are finished, you will be able to specify an installation source and more from the campaign editor:

It's now super easy to target users based on attribution 😉.


This article belongs to Batch's FAQ. Need more help? Find insightful articles, documentation, case & market studies, guides, and even more in our website's Resources section on batch.com and our blog.

Did this answer your question?