Analytics Implementations
How to add AppsFlyer to a Flutter app with analytics_sdk
Free Reference for appsflyer_analytics_impl: every variable, option and package it generates. Command: archipelago generate appsflyer_analytics_impl
Generate the AppsFlyer vendor, set the dev key and app ID in shared/app_config, and learn when the SDK starts and how consent affects it.
What you'll learn
- Generating the AppsFlyer vendor for
analytics_sdk - Setting the dev key and app ID in
shared/app_config - Understanding when the SDK starts and how consent affects it
Prerequisites
- Analytics SDK generated in your monorepo
- An AppsFlyer account with your app configured
- The dev key and the App Store or Play Store app ID
Generate analytics_sdk first. This brick does not check for it. The workspace fails to resolve without it.
Step 1: Generate the Brick
Skip this step if you chose appsflyer in analyticsVendors at project creation.
archipelago generate appsflyer_analytics_implThe prompts are:
- appName: the name of your app
- isForMonorepo: leave this as
true
The brick creates infrastructure/appsflyer_analytics_impl/. The post-generation hook adds the package to the app pubspec.yaml and registers AppsflyerAnalyticsImplPackageModule in lib/di/injector.dart.
Step 2: Add Credentials
Add the two values to the .env files in shared/app_config:
APPSFLYER_DEV_KEY=your-dev-key
APPSFLYER_APP_ID=your-app-idThe vendor reads them as AppEnv.appsflyerDevKey and AppEnv.appsflyerAppId. Use a different value per flavor if you have separate AppsFlyer apps. Never commit real keys. See shared_app_config.
Step 3: Let the Initializer Start the SDK
You write no bootstrap code. The vendor calls AppsFlyerSdk.init inside initialize(). AnalyticsInitializer calls it after the first frame and only after analytics consent is granted.
The vendor registers itself under AnalyticInjectorKey.appsFlyerImpl. The tracker finds it through AnalyticVendorRegistry. You call AnalyticTracker, never the vendor.
Step 4: Verify
Grant analytics consent, then track an event:
await getIt<AnalyticTracker>().track(MyTestEvent());Check the AppsFlyer dashboard under Events. Allow a few minutes for events to appear.
How the vendor behaves:
- Revoking consent calls
stop(true). Granting it again resumes the SDK. reset()clears the customer user ID only. AppsFlyer has no full reset call.setUserPropertyoverwrites the additional data with one key and value per call.
Next Steps
- Set up the Analytics SDK for the full multi-vendor design
- Configure shared_app_config to manage per-environment credentials