Appfiliate Docs
appfiliate.io

Flutter SDK (Dart)

Add affiliate install and purchase attribution to your Flutter app with a single Dart package.


Prerequisites

  • Flutter 3.0 or later
  • Dart 3.0 or later
  • An Appfiliate account with an App ID and API Key (available at app.appfiliate.io)

Step 1: Add the dependency

Add the Appfiliate package to your pubspec.yaml:

pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
  appfiliate: ^1.0.0

Then run the following command to fetch the package:

Terminal
flutter pub get

Step 2: Configure and track install

Initialize the SDK as early as possible. You can do this in your main() function or in the initState() of your root widget. Replace the placeholder values with the App ID and API Key from your Appfiliate dashboard.

In main()

main.dart
import 'package:flutter/material.dart';
import 'package:appfiliate/appfiliate.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  Appfiliate.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
  await Appfiliate.trackInstall();

  runApp(const MyApp());
}

In initState()

my_app.dart
import 'package:flutter/material.dart';
import 'package:appfiliate/appfiliate.dart';

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    _initAppfiliate();
  }

  Future<void> _initAppfiliate() async {
    Appfiliate.configure(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
    await Appfiliate.trackInstall();
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomeScreen(),
    );
  }
}

Step 3: Track purchases (optional)

To attribute revenue to affiliates, call trackPurchase() after every successful in-app purchase.

purchase_handler.dart
import 'package:appfiliate/appfiliate.dart';

Future<void> handlePurchase(PurchaseDetails purchaseDetails) async {
  if (purchaseDetails.status == PurchaseStatus.purchased) {
    await Appfiliate.trackPurchase(
      productId: purchaseDetails.productID,
      revenue: 9.99,
      currency: 'USD',
      transactionId: purchaseDetails.purchaseID ?? '',
    );
  }
}

Important notes

No special permissions required

The Appfiliate SDK does not use IDFA on iOS or advertising IDs on Android. No ATT prompt is needed. Attribution is handled through deterministic matching.
  • trackInstall() is safe to call on every app launch. It only fires once per install.
  • trackPurchase() should be called after every successful in-app purchase.
  • The SDK is under 200 KB with zero external dependencies.
  • Works alongside any other analytics or attribution provider.