AppsFlyer
The Magify Flutter SDK does not depend on the AppsFlyer SDK. If your app already integrates
appsflyer_sdk for attribution, forward its
acquisition-cost data to Magify with a single call.
Linking by user ID
To make AppsFlyer and Magify report the same user, both SDKs must use the same identifier. There are two ways to do it.
Magify clientId is passed to AppsFlyer
Initialize Magify first, then set its clientId as the AppsFlyer customer user ID before
starting AppsFlyer, so attribution is linked to the Magify user from the first session:
await MagifyClient.instance.init(config);
final clientId = await MagifyClient.instance.clientId;
final appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
appsflyerSdk.setCustomerUserId(clientId);
await appsflyerSdk.initSdk(...);
AppsFlyer UID is passed to Magify
If you want AppsFlyer's own identifier to be the Magify clientId, read it first and pass it
in MagifyConfig.clientId at init time:
final appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
await appsflyerSdk.initSdk(...);
final appsFlyerUid = await appsflyerSdk.getAppsFlyerUID();
await MagifyClient.instance.init(
MagifyConfig(
applicationName: 'MyApplication',
defaultConfig: 'assets/magify_default_config.json',
isSandbox: false,
clientId: appsFlyerUid,
),
);
setAppsFlyerCostData
Future<void> setAppsFlyerCostData(Map<String, Object> conversionInfo)
Call it with the conversion-data payload as AppsFlyer delivers it — do not reshape it first. The SDK reads the map as follows:
- If
cost_cents_USDis present, it is used directly. - Otherwise,
af_cost_valuecombined withaf_cost_currencyis used. - Either way, a supported
af_cost_modelis required:cpi,cpc,cpmorcpa. Without one of these four values, the cost data is ignored. - Any other key in the map is ignored.
Wiring it up
Feed the payload from AppsFlyer's conversion-data callback straight into
setAppsFlyerCostData, after MagifyClient.instance.init has completed:
import 'package:appsflyer_sdk/appsflyer_sdk.dart';
import 'package:magify_flutter_sdk/magify_sdk.dart';
void onConversionDataSuccess(Map<dynamic, dynamic> data) {
final conversionInfo = Map<String, Object>.from(data);
MagifyClient.instance.setAppsFlyerCostData(conversionInfo);
}
// When wiring up the AppsFlyer SDK:
appsflyerSdk.onInstallConversionData(onConversionDataSuccess);
Notes
- This is a one-way call — there is no getter to read back what was reported.
- It does not block Magify's own startup: the first context request to the Magify backend
goes out without cost data if AppsFlyer hasn't resolved it yet, and the config is reloaded
once
setAppsFlyerCostDatais called. - Calling it again replaces the previously reported cost data. A call with a map that fails
validation (missing/unsupported
af_cost_model, and nocost_cents_USD) leaves the previous value untouched.
Next step
See Adjust if you also integrate Adjust, or Your own integration for the general pattern this call follows.