Flutter SDK

Complete reference for the AppRefer Flutter SDK. Supports iOS and Android with a single integration.

Installation#

Add the SDK as a git dependency in your pubspec.yaml:

pubspec.yaml
dependencies:
  apprefer_flutter_sdk:
    git:
      url: https://github.com/AppAgentic/apprefer-flutter-sdk.git
      ref: main
flutter pub get

Android Setup#

To enable Google Play Install Referrer attribution on Android, add the Install Referrer library to your app-level build.gradle:

android/app/build.gradle
dependencies {
    implementation "com.android.installreferrer:installreferrer:2.2"
}

iOS

No extra setup is needed for iOS. The SDK automatically uses AdServices when available (iOS 14.3+).

Configuration#

The AppReferConfig object accepts the following parameters:

ParameterTypeRequiredDescription
apiKeyStringYesYour SDK key (pk_live_... or pk_test_...)
userIdString?NoOptional user ID to associate with attribution (e.g., RevenueCat app user ID)
debugboolNoEnable verbose logging. Defaults to false.

API Reference#

AppReferSDK.configure(config)#

Initialize the SDK and resolve attribution. Call once at app launch. Returns the attribution result or null if the device is organic (no matching click found).

Details
Signaturestatic Future<Attribution?> configure(AppReferConfig config)
ReturnsAttribution? — the resolved attribution, or null
ThrowsNever — errors are caught internally and logged
final attribution = await AppReferSDK.configure(AppReferConfig(
  apiKey: 'pk_live_your_key_here',
  debug: true,
));

AppReferSDK.trackEvent(name, ...)#

Send a custom event to AppRefer. Events can trigger ad network forwarding if configured.

ParameterTypeRequiredDescription
nameStringYesEvent name (e.g., 'signup', 'tutorial_complete')
propertiesMap<String, dynamic>?NoArbitrary key-value metadata
revenuedouble?NoRevenue amount (e.g., 9.99)
currencyString?NoISO 4217 currency code (e.g., 'USD')
await AppReferSDK.trackEvent(
  'tutorial_complete',
  properties: {'level': 3, 'time_spent': 42},
);

// With revenue
await AppReferSDK.trackEvent(
  'purchase',
  revenue: 9.99,
  currency: 'USD',
);

AppReferSDK.setAdvancedMatching(...)#

Send hashed PII to improve ad network match rates. All values are SHA256-hashed on the device before being sent to the server. The server never receives plaintext PII.

ParameterTypeRequiredDescription
emailString?NoUser's email address
phoneString?NoPhone number in E.164 format
firstNameString?NoUser's first name
lastNameString?NoUser's last name
dateOfBirthString?NoDate of birth (YYYYMMDD)
await AppReferSDK.setAdvancedMatching(
  email: 'user@example.com',
  phone: '+15551234567',
  firstName: 'Jane',
  lastName: 'Doe',
);

AppReferSDK.setUserId(userId)#

Associate a user ID with the device's attribution. This provides an additional matching signal for purchase webhooks.

Set appreferId on RevenueCat FIRST

Before calling setUserId(), you must set the appreferId attribute on RevenueCat. This is the primary mechanism for matching RevenueCat webhook events back to AppRefer attributions. setUserId() alone is not sufficient — without appreferId, purchase events cannot be attributed.
Details
Signaturestatic Future<void> setUserId(String userId)
Returnsvoid
// REQUIRED: Set appreferId on RevenueCat first
await Purchases.shared.setAttributes({"appreferId": attribution.deviceId});

// Then optionally set user ID for additional matching
await AppReferSDK.setUserId(Purchases.appUserID);

AppReferSDK.getAttribution()#

Returns the cached attribution from the last configure() call. Returns null if configure() has not been called yet or the device is organic.

Details
Signaturestatic Attribution? getAttribution()
ReturnsAttribution? — cached attribution result

AppReferSDK.getDeviceId()#

Returns the device ID generated by AppRefer. This is a stable UUID created on first launch and persisted across app restarts.

Details
Signaturestatic String? getDeviceId()
ReturnsString? — the device UUID, or null before configure()

Attribution Model#

The Attribution object returned by configure() contains the following fields:

FieldTypeDescription
networkString?Ad network name (e.g., 'meta', 'google', 'tiktok', 'apple_search_ads')
matchTypeString?Confidence level of the attribution match
campaignNameString?Campaign name from the tracking link
adsetNameString?Ad set / ad group name
adNameString?Ad creative name
fbclidString?Facebook click ID
gclidString?Google click ID
ttclidString?TikTok click ID
clickIdString?Generic click ID (AppRefer internal)
deviceIdString?Device UUID assigned by AppRefer
createdAtString?ISO 8601 timestamp of the attribution

Full Integration Example#

This example shows a complete integration with RevenueCat, including attribution resolution, user ID linking, and advanced matching after signup:

main.dart
import 'package:flutter/material.dart';
import 'package:apprefer_flutter_sdk/apprefer_flutter_sdk.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

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

  // 1. Initialize AppRefer
  final attribution = await AppReferSDK.configure(AppReferConfig(
    apiKey: 'pk_live_your_key_here',
  ));

  // 2. Initialize RevenueCat
  await Purchases.configure(
    PurchasesConfiguration('your_revenuecat_api_key'),
  );

  // 3. CRITICAL: Link AppRefer device ID to RevenueCat
  //    This is REQUIRED for purchase attribution via webhooks
  await Purchases.shared.setAttributes({"appreferId": attribution.deviceId});

  // 4. Optional: Link RevenueCat user ID to AppRefer
  final customerInfo = await Purchases.getCustomerInfo();
  await AppReferSDK.setUserId(customerInfo.originalAppUserId);

  runApp(const MyApp());
}

// Later, after user signs up...
Future<void> onUserSignup(String email, String firstName) async {
  // 5. Send advanced matching data (hashed on-device)
  await AppReferSDK.setAdvancedMatching(
    email: email,
    firstName: firstName,
  );

  // 6. Track the signup event
  await AppReferSDK.trackEvent('signup');
}

Best Practices#

  • Call configure() as early as possible in the app lifecycle (before runApp()). The sooner you call it, the more accurate the attribution window.
  • Always set appreferId on RevenueCat immediately after configure(). This is the primary mechanism for matching RevenueCat purchase webhooks back to AppRefer attributions. Without it, purchases cannot be attributed.
  • Optionally call setUserId() with the RevenueCat user ID for additional matching. This supplements appreferId but is not a replacement for it.
  • Call setAdvancedMatching() after the user signs up or logs in. More matching data means higher match rates on Meta and other networks.
  • Use pk_test_ keys during development. Sandbox events are completely isolated from production and never forwarded to ad networks.
  • Enable debug: true in development to see verbose logs. Disable it in production.

Requirements#

PlatformMinimum Version
Flutter3.0+
Dart3.0+
iOS14+
AndroidAPI 21+ (Lollipop)