Skip to content

AppsFlyer Analytics Implementation

What you'll learn

  • Generating the AppsFlyer vendor implementation
  • Configuring credentials via app_config
  • Bootstrapping the AppsFlyer SDK before event tracking starts

Prerequisites

  • Analytics SDK installed in your monorepo
  • An AppsFlyer account with a configured app (dev key + App Store / Play Store App ID ready)

Step 1: Generate the Brick

bash
archipelago generate appsflyer_analytics_impl

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • isForMonorepotrue

The brick is generated into infrastructure/appsflyer_analytics_impl/.

Step 2: Add Credentials to app_config

Open your app_config package and add the two AppsFlyer values to AppEnv:

dart
// lib/src/app_env.dart
class AppEnv {
  // existing fields …
  final String appsflyerDevKey;   // from AppsFlyer dashboard → App Settings
  final String appsflyerAppId;    // App Store / Play Store App ID
}

Populate the values for each environment (dev, staging, prod) in the corresponding .env or config factory.

Step 3: Initialise the SDK at Bootstrap

Important: AppsFlyer requires initSdk() to be called in your app's bootstrap before any event tracking occurs. This is done in the shell app's initialiser, not inside the generated package.

dart
import 'package:appsflyer_sdk/appsflyer_sdk.dart';

final appsFlyerOptions = AppsFlyerOptions(
  afDevKey: AppEnv.current.appsflyerDevKey,
  appId: AppEnv.current.appsflyerAppId,
  showDebug: kDebugMode,
);

final appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
await appsflyerSdk.initSdk(
  registerConversionDataCallback: true,
  registerOnAppOpenAttributionCallback: true,
);

Register the SDK instance in GetIt so the generated package can resolve it:

dart
getIt.registerSingleton<AppsflyerSdk>(appsflyerSdk);

Step 4: Register the Module and Verify

dart
import 'package:appsflyer_analytics_impl/appsflyer_analytics_impl.dart';

await initAppsFlyerAnalyticsImplModule(getIt);

The implementation is registered as @Named(AnalyticInjectorKey.appsFlyerImpl). The analytics_sdk orchestrator picks it up automatically via getIt.getAll<AnalyticVendor>().

Trigger an event and verify it appears in the AppsFlyer dashboard under Events (allow a few minutes for ingestion outside DebugMode).

Next Steps

Built by Banua Coder