How to Add Affiliate Tracking to Your Flutter App
Step-by-step guide to adding creator and affiliate install attribution to a Flutter app using the Appfiliate SDK. Track which creators drive installs and revenue.

If you are reading this guide, you probably want to add affiliate tracking to your Flutter app. Not campaign tracking, not ad tracking. Creator-level attribution. You want to know which creators are driving installs and purchases. Because you have affiliates or influencers or content creators of some kind promoting your app, and you need to figure out which ones are sending you which customers.
The problem is that your user clicks a link in a creator's bio. The link takes them to the App Store or Google Play. They open the app and it launches. By the time your app has launched, the browser session is gone. There is no cookie, no referral header, no query parameter that your app can use to tell you who sent that user. This is the attribution gap, and it is a fundamental challenge for every mobile app, regardless of framework.
If you already have an analytics tool like Firebase or Mixpanel installed, you know that you can use it to track what your users do once they are inside your app. You can see that they tapped on a button, or made a purchase, or whatever else it is that your users do. But you cannot see which creator sent that user to your app in the first place. That is a different question, and it requires a different tool.
The tool you need is an affiliate tracking SDK. An affiliate tracking SDK collects some context about the device when your app launches, and uses that context to figure out which link the user clicked to get to your app store listing. And then it tells you. This install came from this link. And if you connect a subscription platform, it goes further. This purchase came from this link. This renewal came from this link. This cancellation came from this link.
Appfiliate is an affiliate tracking SDK, and it is built specifically for this purpose. It is pure Dart with no native dependencies, so you do not need to display an IDFA prompt or an ATT prompt to use it. It requires just a few lines of code to integrate. And it has zero transitive dependencies, so it will not bloat your app or conflict with anything else in your tree.
So. Here is how you integrate it.
Step 1: Add the Appfiliate SDK dependency
The first step is to add the Appfiliate SDK to your project. Add the following to your pubspec.yaml:
dependencies:
appfiliate: ^1.0.0
Then run flutter pub get in your terminal. That is the only dependency you need. You can find the full package details on the Flutter SDK page.
Step 2: Configure the SDK and track installs
The next step is to configure the SDK and start tracking installs. Find the entry point to your application, which is typically main() in main.dart. Add the following code:
import 'package:appfiliate/appfiliate.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Appfiliate.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
runApp(MyApp());
}
Your appId and apiKey are available in your Appfiliate dashboard. That is it. You should now be tracking installs. When a user launches your app, the SDK will collect some context and use it to figure out who sent them. If it successfully attributes the install, you will see it in your dashboard. You can now integrate a subscription platform and start tracking purchases as well. If you haven't already, create an account at appfiliate.io and go to pricing to select a plan.
Then, call trackInstall() once when your app starts. A good place for this is in the initState of your root widget:
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_initAttribution();
}
Future<void> _initAttribution() async {
final result = await Appfiliate.trackInstall();
print('Attributed: ${result.matched}');
}
}
trackInstall() is idempotent. It will only send attribution information once per installation of your app, so it is safe to call it every time your app starts. Subsequent calls will return the cached result immediately.
That's it for basic install attribution. All installations that occur via a creator's tracking link will now be matched and show up in your Appfiliate dashboard.
Step 3: Track purchases
If your app offers in-app purchases, you will want to attribute revenue to the creator that brought in the installation. After a successful purchase, call trackPurchase():
await Appfiliate.trackPurchase(
productId: 'premium_monthly',
revenue: 9.99,
currency: 'USD',
transactionId: purchaseDetails.purchaseID,
);
Call this after every successful purchase. The SDK will associate the revenue with the creator that referred the user originally, so you can accurately calculate commissions and see which creators are driving paying users, not just installs.
Step 4: Automate purchase tracking with webhooks
If you are using a subscription platform such as RevenueCat, Stripe, Superwall, Adapty, or Qonversion, you can completely skip the calls to trackPurchase(). Instead, connect your subscription platform's webhooks to Appfiliate, and purchases, renewals, and cancellations will all be tracked automatically.
First, link the user's subscription ID in your app, by calling setUserId() after calling trackInstall():
import 'package:appfiliate/appfiliate.dart';
// After configure and trackInstall:
Appfiliate.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
await Appfiliate.trackInstall();
await Appfiliate.setUserId(await Purchases.appUserID); // RevenueCat example
For Stripe, pass the Stripe customer ID instead:
await Appfiliate.setUserId(stripeCustomerId);
Then, copy the corresponding webhook URL from the integrations page, and paste it into your subscription platform's dashboard. For RevenueCat, this is in the Dashboard under Integrations -> Webhooks. Once connected, purchases, renewals, and cancellations will flow through automatically and be attributed to the creator who brought in the installation. No further code is needed in your app.
Testing your integration
Before going live, you can verify that attribution is working:
- Build a debug version of your app.
- Create a test tracking link in your Appfiliate dashboard.
- Click the link on a test device or emulator.
- Install and launch the app.
- Open your Appfiliate dashboard to verify that the install was correctly attributed.
If you are tracking purchases, make a test purchase after the attributed install and verify that it shows up in the dashboard under the right creator.
The complete integration
Here is the full integration in one place:
import 'package:appfiliate/appfiliate.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Appfiliate.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
runApp(MyApp());
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_initAttribution();
}
Future<void> _initAttribution() async {
final result = await Appfiliate.trackInstall();
// If using RevenueCat or another subscription platform:
await Appfiliate.setUserId(await Purchases.appUserID);
}
// If tracking purchases manually (without webhooks):
Future<void> _onPurchaseComplete(PurchaseDetails details) async {
await Appfiliate.trackPurchase(
productId: details.productID,
revenue: 9.99,
currency: 'USD',
transactionId: details.purchaseID,
);
}
}
Three methods for install tracking. One optional method for revenue attribution. That is the entire surface area of the SDK.
FAQ
Does the Appfiliate SDK require IDFA or trigger the ATT prompt?No. The SDK does not use IDFA and does not require an ATT prompt. It uses privacy-preserving attribution techniques, so your users will never see a "Allow this app to track you?" dialog from Appfiliate. On Android, it uses the Google Install Referrer API for deterministic matching.
Can I use Appfiliate with both manual purchase tracking and webhooks?You should use one or the other. If you connect a subscription platform via webhooks (RevenueCat, Stripe, Superwall, Adapty, or Qonversion), purchases are tracked automatically, and you do not need to call trackPurchase() in your code. If you are not using one of those platforms, use trackPurchase() to report purchases directly from your app.
No. trackInstall() is idempotent. It only sends attribution data on the first launch after a fresh install. On subsequent launches, it returns the cached result immediately without making a network request. It is safe and recommended to call it on every app launch.
The SDK still runs, but the attribution result will indicate no match. There is no negative side effect. The SDK simply reports that the install was organic rather than attributed to a creator. You only pay for attributed installs, not organic ones.