Flutter
Add Fload's attribution plugin to a Flutter app. One plugin covers iOS and Android. It calls Fload's native SDKs underneath, so it behaves exactly like them.
What you need
- Flutter 3.22 or later (Dart 3.4 or later).
- iOS 15 or later, and Android minSdk 24 or later.
- Your app's write key.
purchases_flutterin your app, if you want revenue per keyword. The plugin doesn't depend on it.
1. Add the plugin
flutter pub add fload_attributionThis adds a line like this to your pubspec.yaml:
dependencies:
fload_attribution: ^1.0.0On iOS, the plugin works with Swift Package Manager and with CocoaPods, whichever your project uses. On Android, it brings in the native SDK and the JitPack repository it comes from through Gradle.
If your android/settings.gradle.kts sets RepositoriesMode.FAIL_ON_PROJECT_REPOS, Gradle won't take the plugin's repository, so add JitPack there yourself:
// android/settings.gradle.kts
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://jitpack.io")
content { includeGroup("com.github.fload-ai") }
}
}
}Use this plugin or the native iOS SDK in an app, not both. The plugin already contains the iOS SDK, so don't also add the Swift package or pod.
2. Start it in main()
Call FloadAttribution.configure once, after WidgetsFlutterBinding.ensureInitialized() and before runApp. It returns quickly; the work runs in the background on the native side.
import 'dart:io' show Platform;
import 'package:flutter/widgets.dart';
import 'package:fload_attribution/fload_attribution.dart';
import 'package:purchases_flutter/purchases_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Purchases.configure(
PurchasesConfiguration(Platform.isIOS ? 'appl_…' : 'goog_…'),
);
await FloadAttribution.configure('fload_pk_…');
await FloadAttribution.setUserId(await Purchases.appUserID);
runApp(const PocketBudgetApp());
}3. Link the user after login
When a user logs in, RevenueCat's id changes. Send the new one too:
await Purchases.logIn('user_123');
await FloadAttribution.setUserId(await Purchases.appUserID);Fload keeps every id an install has had, so purchases before and after login both count.
4. Check it works
Turn on debug logs while you test:
await FloadAttribution.configure('fload_pk_…', logLevel: FloadLogLevel.debug);Run on a real iPhone and a real Android phone. The plugin logs through the native SDKs: the unified log subsystem com.fload.attribution on iOS, and the Logcat tag FloadAttribution on Android. Remove the debug option before you ship.
- The iOS Simulator has no AdServices token.
- Android builds you run from your machine have no Play referrer.
Both still send an install, without attribution. That's expected. On other platforms, such as web and desktop, the calls do nothing.
5. Ship it
Ship the update to both stores. Fill in the App Store privacy answers and the Play Data safety form from Privacy.
Reference
| Call | What it does |
|---|---|
FloadAttribution.configure(key, {logLevel}) | Starts the SDK. Call once, in main(). logLevel is a FloadLogLevel: none, error, warning (the default), info or debug |
FloadAttribution.setUserId(userId) | Links your user id to this install |
await FloadAttribution.installReference | This install's random reference, for support questions. null until the SDK has loaded |
Every call returns a Future. The native guides cover what happens underneath: SwiftUI and Android.