Getting the App Install Source

AppsFlyer

If you need to track the app install source (for example, to measure the effectiveness of marketing campaigns), follow these steps:

1. Install the AppsFlyer SDK

Follow the official guide: GitHub — AppsFlyer Flutter Plugin.

2. Initialize the AppsFlyer SDK

Create an AppsFlyerSdk instance and initialize it in your widget’s initState(). This allows the SDK to start processing attribution as soon as the app launches.

import 'package:appsflyer_sdk/appsflyer_sdk.dart';

late AppsflyerSdk _appsflyerSdk;

@override
void initState() {
  super.initState();
  _initAppsFlyerSdk();
}

void _initAppsFlyerSdk() async {
  // SDK Setup
  final AppsFlyerOptions options = AppsFlyerOptions(
    afDevKey: 'YOUR_AF_DEV_KEY',           // Your AppsFlyer Dev Key
    appId: 'YOUR_IOS_APP_ID',              // App ID (only for iOS)
    showDebug: true,
  );

  _appsflyerSdk = AppsflyerSdk(options);

  // SDK Initialization
  await _appsflyerSdk.initSdk(
    registerConversionDataCallback: true,
    registerOnAppOpenAttributionCallback: true,
    registerOnDeepLinkingCallback: true,
  );

  // Handling Conversion Data
  _appsflyerSdk.onInstallConversionData((data) {
    print("onInstallConversionData data:");
    data.forEach((key, value) {
      print('$key : $value');
    });

    final status = data['af_status'];

    if (status == 'Non-organic') {
      final sourceID = data['media_source'];
      final campaign = data['campaign'];
      print('Non-organic installation. Source: $sourceID Campaign: $campaign');
    } else if (status == 'Organic') {
      print('Organic installation');
    }

    final isFirstLaunch =
        data['is_first_launch'] == 'true' || data['is_first_launch'] == true;

    if (isFirstLaunch) {
      print('First app launch');
    } else {
      print('Subsequent app launch');
    }
  });
}

Sending the sourceID to Maestra

  1. Create an operation in Maestra with an action and/or populated custom field. Detailed instructions are available in the Maestra documentation.
  2. After receiving the sourceID from AppsFlyer, send it to the method’s custom field:
Mindbox.instance.executeAsyncOperation(
  operationSystemName: "<operationSystemName>",
  operationBody: {
    // Send the received sourceID
  },
);

For more details, see the AppsFlyer SDK example for Flutter.

General Information

Errors:
404 — An incorrect afDevKey or appID is specified.
403 — The AppsFlyer Zero plan does not allow access to install data.