### Handle SDK Start Callbacks Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Provides a standalone example of using the startSDK method with success and error handlers. ```dart _appsflyerSdk.startSDK( onSuccess: () { showMessage("AppsFlyer SDK initialized successfully."); }, onError: (int errorCode, String errorMessage) { showMessage("Error initializing AppsFlyer SDK: Code $errorCode - $errorMessage"); }, ); ``` -------------------------------- ### Run the AppsFlyer Flutter Demo Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/example/README.md Execute these commands from the root directory of the cloned repository to install dependencies and launch the example app. ```bash $ flutter packages get $ cd example/ $ flutter run ``` -------------------------------- ### Full AppsFlyer Purchase Connector Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md A comprehensive Dart example demonstrating the initialization of `PurchaseConnector`, setting up listeners for subscription and in-app validation results for Android, and handling purchase revenue validation for iOS. It also shows how to start observing transactions. ```dart PurchaseConnectorConfiguration config = PurchaseConnectorConfiguration( logSubscriptions: true, logInApps: true, sandbox: false, storeKitVersion: StoreKitVersion.storeKit2 // Use StoreKit 2 on iOS (requires iOS 15.0+) ); final afPurchaseClient = PurchaseConnector(config: config); // set listeners for Android afPurchaseClient.setSubscriptionValidationResultListener( (Map? result) { // handle subscription validation result for Android result?.entries.forEach((element) { debugPrint( "Subscription Validation Result\n\t Token: ${element.key}\n\tresult: ${jsonEncode(element.value.toJson())}"); }); }, (String result, JVMThrowable? error) { // handle subscription validation error for Android var errMsg = error != null ? jsonEncode(error.toJson()) : null; debugPrint( "Subscription Validation Result\n\t result: $result\n\terror: $errMsg"); }); afPurchaseClient.setInAppValidationResultListener( (Map? result) { // handle in-app validation result for Android result?.entries.forEach((element) { debugPrint( "In App Validation Result\n\t Token: ${element.key}\n\tresult: ${jsonEncode(element.value.toJson())}"); }); }, (String result, JVMThrowable? error) { // handle in-app validation error for Android var errMsg = error != null ? jsonEncode(error.toJson()) : null; debugPrint( "In App Validation Result\n\t result: $result\n\terror: $errMsg"); }); // set listener for iOS afPurchaseClient .setDidReceivePurchaseRevenueValidationInfo((validationInfo, error) { var validationInfoMsg = validationInfo != null ? jsonEncode(validationInfo) : null; var errMsg = error != null ? jsonEncode(error.toJson()) : null; debugPrint( "iOS Validation Result\n\t validationInfo: $validationInfoMsg\n\terror: $errMsg"); // handle subscription and in-app validation result and errors for iOS }); // start afPurchaseClient.startObservingTransactions(); ``` -------------------------------- ### Initialize and Manually Start AppsFlyer SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Configures the SDK with manual start enabled and demonstrates the initialization and manual start sequence with success and error callbacks. ```dart // SDK Options final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: "", appId: "", showDebug: true, timeToWaitForATTUserAuthorization: 15, manualStart: true); _appsflyerSdk = AppsflyerSdk(options); // Initialization of the AppsFlyer SDK _appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true); // Starting the SDK with optional success and error callbacks _appsflyerSdk.startSDK( onSuccess: () { showMessage("AppsFlyer SDK initialized successfully."); }, onError: (int errorCode, String errorMessage) { showMessage("Error initializing AppsFlyer SDK: Code $errorCode - $errorMessage"); }, ); ``` -------------------------------- ### Start SDK Manually Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Manually start the SDK after initialization, useful for controlling the SDK's start time. ```APIDOC ## `startSDK()` ### Description Manually starts the SDK. This is an alternative to the automatic start after `initSdk` when `manualStart: true` is set in the options. ### Endpoint `/startSDK` ### Method POST ### Request Example ```dart appsflyerSdk.startSDK(); ``` ``` -------------------------------- ### iOS Launch Event Log Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Testing.md Example of the launch event URL structure found in Xcode logs. ```text <~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~~+~> <~+~ SEND Start: https://launches.appsflyer.com/api/v6.4/iosevent?app_id=7xXxXxX1&buildnumber=6.4.4 <~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~~+~> { launch event payload } // Just an example of a JSON. you will see the full payload ``` -------------------------------- ### Implement V2 Purchase Validation Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/AdvancedAPI.md Complete example showing how to create purchase details and handle validation results or platform exceptions. ```dart // Create purchase details AFPurchaseDetails purchaseDetails = AFPurchaseDetails( purchaseType: AFPurchaseType.oneTimePurchase, purchaseToken: "sample_purchase_token_12345", productId: "com.example.product", ); // Validate purchase (works on both Android and iOS) try { Map result = await appsFlyerSdk.validateAndLogInAppPurchaseV2( purchaseDetails, additionalParameters: {"custom_param": "value"} ); print("Validation successful: $result"); } on PlatformException catch (e) { // Handle platform-specific errors with detailed information print("Validation failed: ${e.message}"); print("Error code: ${e.code}"); if (e.details != null) { // Access detailed error information final details = e.details as Map; print("Error details: $details"); // On iOS, additional fields may include: // - error_code: The NSError code // - error_domain: The NSError domain // - error_user_info: Additional error context } } catch (e) { print("Unexpected error: $e"); } ``` -------------------------------- ### Configure Consent Before SDK Start Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Demonstrates the required sequence to configure consent data before starting the SDK. ```dart // Set AppsFlyerOption - make sure to set manualStart to true final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: dotenv.env["DEV_KEY"]!, appId: dotenv.env["APP_ID"]!, showDebug: true, timeToWaitForATTUserAuthorization: 15, manualStart: true); _appsflyerSdk = AppsflyerSdk(options); // Init the AppsFlyer SDK _appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true); // Set configurations to the SDK // Enable TCF Data Collection _appsflyerSdk.enableTCFDataCollection(true); // Set Consent Data // If user is subject to GDPR // var forGdpr = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage: true, hasConsentForAdsPersonalization: true); // _appsflyerSdk.setConsentData(forGdpr); // If user is not subject to GDPR var nonGdpr = AppsFlyerConsent.nonGDPRUser(); _appsflyerSdk.setConsentData(nonGdpr); // Here we start a session _appsflyerSdk.startSDK(); ``` -------------------------------- ### Android Launch Event Log Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Testing.md Example of the launch event URL and payload found in Android Logcat. ```text I/AppsFlyer_6.4.3: url: https://launches.appsflyer.com/api/v6.4/androidevent?app_id=com.aXxXxt.rxXxXxt&buildnumber=6.4.3 I/AppsFlyer_6.4.3: data: { launch event payload } // Just an example of a JSON. you will see the full payload ``` -------------------------------- ### startSDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Manually starts the AppsFlyer SDK when manualStart is enabled in the configuration. ```APIDOC ## startSDK ### Description Starts the SDK manually. This is required if `manualStart` is set to `true` in the `AppsFlyerOptions`. ### Parameters #### Request Body - **onSuccess** (Function) - Optional - Callback triggered after successful initialization. - **onError** (Function) - Optional - Callback triggered on error, providing an error code and message. ### Request Example _appsflyerSdk.startSDK( onSuccess: () { ... }, onError: (int errorCode, String errorMessage) { ... }, ); ``` -------------------------------- ### Implement setConsentDataV2 Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DMA.md Example of using setConsentDataV2 with manual SDK initialization. Call this method before starting the SDK to ensure consent is captured correctly. ```dart // Initialize AppsFlyerOptions with manualStart: true final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: 'your_dev_key', appId: '1234567890', // Required for iOS only showDebug: true, manualStart: true ); // Create the AppsflyerSdk instance AppsflyerSdk appsflyerSdk = AppsflyerSdk(options); // Set consent data BEFORE initializing the SDK appsflyerSdk.setConsentDataV2( isUserSubjectToGDPR: true, consentForDataUsage: true, consentForAdsPersonalization: false, hasConsentForAdStorage: null // User has not explicitly provided consent ); // Initialize the SDK appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true ); // Start the SDK appsflyerSdk.startSDK(); ``` -------------------------------- ### Start the SDK Manually Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Manually trigger the SDK start process when manualStart is set to true in the initialization options. ```dart _appsflyerSdk.startSDK(); ``` -------------------------------- ### iOS Success Response Log Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Testing.md Example of a successful HTTP response log in iOS. ```text Result: { data = {length = 64, bytes = 0x7b226f6c 5f696422 3a224476 5769222c ... 696e6b2e 6d65227d }; dataStr = "{\"oxXxXxd\":\"DXxXxi\",\"oXxXer\":ss,\"olXxXxain\":\"xXxXxXx\"}"; retries = 2; statusCode = 200; // ~~> success! taskIdentifier = 4; } ``` -------------------------------- ### Android Success Response Log Example Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Testing.md Example of a successful response code log in Android. ```text I/AppsFlyer_6.4.3: response code: 200 // ~~> success! ``` -------------------------------- ### Configure Purchase Connector for Testing (StoreKit 2) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Example configuration for testing with StoreKit 2 on iOS. Enables sandbox mode, StoreKit 2, and logging for subscriptions and in-app purchases. Remember to set `sandbox` to `false` for production. ```dart final purchaseConnector = PurchaseConnector( config: PurchaseConnectorConfiguration( sandbox: true, // Enable sandbox for testing storeKitVersion: StoreKitVersion.storeKit2, logSubscriptions: true, logInApps: true, ), ); ``` -------------------------------- ### Start Observing Transactions Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Activate the transaction listener after starting the AppsFlyer SDK. ```dart // start afPurchaseClient.startObservingTransactions(); ``` -------------------------------- ### Initialize AppsFlyer SDK with Options Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Configure AppsFlyer SDK options such as developer key, app ID, debug mode, and ATT user authorization timeout. Set `manualStart` to true if you intend to manually start the SDK later. ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; AppsFlyerOptions appsFlyerOptions = AppsFlyerOptions( afDevKey: afDevKey, appId: appId, showDebug: true, timeToWaitForATTUserAuthorization: 50, // for iOS 14.5 appInviteOneLink: oneLinkID, // Optional field disableAdvertisingIdentifier: false, // Optional field disableCollectASA: false, //Optional field manualStart: true, ); // Optional field AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); ``` -------------------------------- ### Configure Android Out-of-Store Attribution Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Add the install referrer receiver to the AndroidManifest.xml for out-of-store attribution support. ```xml ... ``` -------------------------------- ### Initialize SDK with Manual Start for CMP Consent Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DMA.md Configure AppsFlyerOptions with manualStart set to true to allow the SDK to retrieve consent data from a TCF v2.2 compliant CMP. Initialize the SDK and then call startSDK() after the CMP has acquired user consent. ```dart final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: 'your_dev_key', appId: '1234567890', // Required for iOS only showDebug: true, manualStart: true // <--- Manual Start ); // Create the AppsflyerSdk instance AppsflyerSdk appsflyerSdk = AppsflyerSdk(options); // Initialize the SDK appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true ); // CMP pseudocode procedure if (cmpManager.hasConsent()) { appsflyerSdk.startSDK(); } else { cmpManager.presentConsentDialogToUser() .then((_) => appsflyerSdk.startSDK()); } ``` -------------------------------- ### Example Push Payload with `af` Object Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md This JSON payload demonstrates how to structure custom attribution parameters within the 'af' object for push notifications. ```json { "af": { "c": "test_campaign", "is_retargeting": true, "pid": "push_provider_int" }, "aps": { "alert": "Get 5000 Coins", "badge": "37", "sound": "default" } } ``` -------------------------------- ### getOutOfStore Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Get the third-party app store referrer value (Android Only). ```APIDOC ## Future getOutOfStore() ### Description **Android Only!** Get the third-party app store referrer value. ### Method Future ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```dart if(Platform.isAndroid){ Future store = appsflyerSdk.getOutOfStore(); store.then((store) { print(store); }); } ``` ### Response #### Success Response (200) - **String?** - The referrer value from the third-party app store. ``` -------------------------------- ### Register Attribution Callbacks Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Register callbacks to handle attribution data, install conversion data, and deep linking events. ```dart _appsflyerSdk.onAppOpenAttribution((res) { print("res: " + res.toString()); }); ``` ```dart _appsflyerSdk.onInstallConversionData((res) { print("res: " + res.toString()); }); ``` ```dart _appsflyerSdk.onDeepLinking((res) { print("res: " + res.toString()); }); ``` -------------------------------- ### Example Push Payload with OneLink URL Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md A sample JSON payload demonstrating the structure for a push notification containing a OneLink URL, including nested deep link parameters and APS information. ```json { "deeply": { "nested": { "deep_link": "https://yourapp.onelink.me/ABC/campaign123" } }, "aps": { "alert": "Check out our new feature!", "badge": "1", "sound": "default" } } ``` -------------------------------- ### Get Out-of-Store Source (Android) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Retrieve the third-party app store referrer value on Android. This is an Android-only feature. The result is returned as a Future. ```dart if(Platform.isAndroid){ Future store = appsflyerSdk.getOutOfStore(); store.then((store) { print(store); }); } ``` -------------------------------- ### Update Uninstall Token using Firebase Messaging (Cross-Platform) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/AdvancedAPI.md Register the uninstall token with AppsFlyer using the Firebase Messaging plugin. This example demonstrates how to get the token for both Android and iOS and update AppsFlyer. ```dart import 'dart:io' show Platform; import 'package:firebase_messaging/firebase_messaging.dart'; // Update uninstall token for AppsFlyer void _updateUninstallToken(appsFlyerSdk) { if (Platform.isAndroid) { FirebaseMessaging.instance.getToken().then((token) { if (token != null) { appsFlyerSdk.updateServerUninstallToken(token); } }); } else if (Platform.isIOS) { FirebaseMessaging.instance.getAPNSToken().then((token) { if (token != null) { appsFlyerSdk.updateServerUninstallToken(token); } }); } } ``` -------------------------------- ### Initialize SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initialize the SDK and register callbacks for conversion and attribution data. ```APIDOC ## `initSdk({bool registerConversionDataCallback, bool registerOnAppOpenAttributionCallback, bool registerOnDeepLinkingCallback}) async` ### Description Initializes the SDK. This method can also register callbacks for conversion data, app open attribution, and deep linking. ### Parameters #### Query Parameters - **registerConversionDataCallback** (bool) - Optional. If true, registers a callback for install conversion data. - **registerOnAppOpenAttributionCallback** (bool) - Optional. If true, registers a callback for app open attribution. - **registerOnDeepLinkingCallback** (bool) - Optional. If true, registers a callback for deep linking. ### Request Example ```dart await appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true ); ``` ### Response #### Success Response (200) - **status** (String) - Indicates the status of the initialization. ``` -------------------------------- ### SDK Initialization and Callbacks Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Methods to register listeners for conversion data and deep linking attribution. ```APIDOC ## registerConversionDataCallback ### Description Sets a listener for the Conversion Data (GCD) response and legacy deferred deeplinking. ## registerOnAppOpenAttributionCallback ### Description Sets a listener for the legacy direct deeplinking response. ## registerOnDeepLinkingCallback ### Description Sets a listener for the Unified Deep Linking (UDL) response. ``` -------------------------------- ### Initialize AppsFlyer SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Configure the SDK instance using a map of options and initialize it with required callbacks. ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; //.. AppsFlyerOptions appsFlyerOptions = { "afDevKey": afDevKey, "afAppId": appId, "isDebug": true}; AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); ``` ```dart appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true ); ``` -------------------------------- ### Initialize AppsFlyer SDK with Map Options Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Configure the SDK using a Map containing the developer key, app ID, and debug settings before instantiation. ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; //.. Map appsFlyerOptions = { "afDevKey": afDevKey, "afAppId": appId, "showDebug": true}; AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); ``` -------------------------------- ### SDK Initialization Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initializes the AppsFlyer SDK with provided options. This is the first step before using any other SDK methods. ```APIDOC ## Initialize SDK ### Description Initializes the AppsFlyer SDK with your application's devKey and other configuration options. ### Method `AppsflyerSdk(Map options)` ### Parameters #### Request Body - **options** (Map) - Required - SDK configuration options. - **afDevKey** (String) - Required - Your application's devKey provided by AppsFlyer. - **afAppId** (String) - Required for iOS only - Your application's App ID configured in the AppsFlyer dashboard. - **showDebug** (bool) - Optional - Set to `true` for debugging. Do not use in production. - **timeToWaitForATTUserAuthorization** (double) - Optional - Delays SDK start for a specified duration until ATT user authorization is resolved. - **appInviteOneLink** (String) - Optional - The OneLink template ID for generating User Invites. - **disableAdvertisingIdentifier** (bool) - Optional - Opt-out of collecting Advertising Identifiers. - **disableCollectASA** (bool) - Optional - Opt-out of Apple Search Ads attributions. - **manualStart** (bool) - Optional - Prevents automatic SDK launch. Requires manual call to `startSdk()`. ### Request Example ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; Map appsFlyerOptions = { "afDevKey": "YOUR_DEV_KEY", "afAppId": "YOUR_APP_ID", "showDebug": true }; AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); ``` ### Response This method does not return a value directly but initializes the SDK. ``` -------------------------------- ### Initialize AppsFlyer SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Configures the SDK using AppsFlyerOptions and initializes it with optional callbacks. ```APIDOC ## SDK Initialization ### Description Initializes the AppsFlyer SDK to track installations, sessions, and updates. The process involves creating an `AppsFlyerOptions` object and calling `initSdk`. ### Parameters #### Request Body (AppsFlyerOptions) - **afDevKey** (String) - Required - Your application's devKey provided by AppsFlyer. - **appId** (String) - Required (iOS only) - Your application's App ID. - **showDebug** (bool) - Optional - Debug mode; set to true for testing only. - **timeToWaitForATTUserAuthorization** (double) - Optional - Delays SDK start for x seconds for iOS 14.5 consent. - **appInviteOneLink** (String) - Optional - The OneLink template ID for User Invites. - **disableAdvertisingIdentifier** (bool) - Optional - Opt-out of collecting Advertising Identifiers (OAID, AAID, GAID, IDFA). - **disableCollectASA** (bool) - Optional - Opt-out of Apple Search Ads attributions. - **manualStart** (bool) - Optional - Prevents automatic launch request; requires manual call to startSdk(). ### Request Example ```dart AppsFlyerOptions appsFlyerOptions = AppsFlyerOptions( afDevKey: "your_dev_key", appId: "your_app_id", showDebug: true ); AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); ``` ### Initialization Method - **registerConversionDataCallback** (bool) - Optional - Register for conversion data (default: false). - **registerOnAppOpenAttributionCallback** (bool) - Optional - Register for legacy deep-linking (default: false). - **registerOnDeepLinkingCallback** (bool) - Optional - Register for deep linking (default: false; overrides legacy callback). ``` -------------------------------- ### Get AppsFlyer UID Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Retrieves the unique AppsFlyer ID for the device. ```APIDOC ## Future getAppsFlyerUID() ### Description Use this API to get the AppsFlyer ID. ### Method `Future` ### Parameters This method does not take any parameters. ### Request Example ```dart appsFlyerSdk.getAppsFlyerUID().then((AppsFlyerId) { print("AppsFlyer ID: ${AppsFlyerId}"); }); ``` ### Response #### Success Response (200) - **AppsFlyerId** (String?) - The AppsFlyer unique identifier for the device. ``` -------------------------------- ### SDK Initialization Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initialize the Appsflyer SDK with configuration options. ```APIDOC ## `AppsflyerSdk(Map options)` ### Description Initializes the SDK with the provided configuration options. ### Parameters #### Request Body - **appsFlyerOptions** (AppsFlyerOptions) - SDK configuration object. ### Request Example ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: "af dev key", showDebug: true, appId: "123456789" ); final AppsflyerSdk appsflyerSdk = AppsflyerSdk(options); ``` ``` -------------------------------- ### Get Host Prefix Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Retrieves the current host prefix configured for the AppsFlyer SDK. This is an asynchronous operation that returns a Future. ```dart appsFlyerSdk.getHostPrefix().then((name) { print("Host prefix: ${name}"); }); ``` -------------------------------- ### Configure SDK and Deep Linking Callback Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initialize the AppsFlyer SDK and set up a callback to handle deep linking. Ensure `addPushNotificationDeepLinkPath` is called before SDK initialization. ```dart // ======================================== // 1. Configure SDK (in main.dart or app initialization) // ======================================== void initializeAppsFlyer() async { // STEP 1: Configure the deep link path BEFORE starting SDK appsFlyerSdk.addPushNotificationDeepLinkPath(["deeply", "nested", "deep_link"]); // STEP 2: Initialize SDK with deep linking callback await appsFlyerSdk.initSdk( registerOnDeepLinkingCallback: true ); // STEP 3: Set up deep linking callback to handle the OneLink URL appsFlyerSdk.onDeepLinking((DeepLinkResult result) { if (result.status == Status.FOUND) { print("Deep link found: ${result.deepLink?.deepLinkValue}"); // Handle deep link navigation here } }); } ``` -------------------------------- ### Get Host Name Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Retrieves the current host name configured for the AppsFlyer SDK. This is an asynchronous operation that returns a Future. ```dart appsFlyerSdk.getHostName().then((name) { print("Host name: ${name}"); }); ``` -------------------------------- ### Initialize PurchaseConnector Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Instantiate the PurchaseConnector with a configuration object. The configuration is only applied during the first instantiation due to the singleton pattern. ```dart void main() { final afPurchaseClient = PurchaseConnector( config: PurchaseConnectorConfiguration( logSubscriptions: true, // Enables logging of subscription events logInApps: true, // Enables logging of in-app purchase events sandbox: true, // Enables testing in a sandbox environment storeKitVersion: StoreKitVersion.storeKit1, // iOS only: StoreKit version (defaults to storeKit1) ), ); // Continue with your application logic... } ``` ```dart void main() { // Correct usage: Providing configuration at first instantiation final purchaseConnector1 = PurchaseConnector( config: PurchaseConnectorConfiguration( logSubscriptions: true, logInApps: true, sandbox: true, storeKitVersion: StoreKitVersion.storeKit1, // Default StoreKit version ), ); // Additional instantiations will ignore the provided configuration // and will return the previously created instance. final purchaseConnector2 = PurchaseConnector( config: PurchaseConnectorConfiguration( logSubscriptions: false, logInApps: false, sandbox: false, storeKitVersion: StoreKitVersion.storeKit2, // This will be ignored ), ); // purchaseConnector1 and purchaseConnector2 point to the same instance assert(purchaseConnector1 == purchaseConnector2); } ``` -------------------------------- ### Handle Deferred Deep Linking Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DeepLink.md Register the onInstallConversionData callback before SDK initialization to handle deferred deep linking. ```dart appsflyerSdk.onInstallConversionData((res){ print("res: " + res.toString()); }); ``` -------------------------------- ### Disable AppSet ID Collection (Android) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Disable AppSet ID collection for privacy compliance on Android. Starting with v6.17.0, the SDK can automatically collect AppSet ID. ```dart if(Platform.isAndroid){ appsflyerSdk.disableAppSetId(); } ``` -------------------------------- ### Initialize StoreKit 2 with Error Handling Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Initializes the Purchase Connector with StoreKit 2 and includes a try-catch block for error handling. ```dart try { final afPurchaseClient = PurchaseConnector( config: PurchaseConnectorConfiguration( logSubscriptions: true, logInApps: true, sandbox: true, storeKitVersion: StoreKitVersion.storeKit2, ), ); // Start observing transactions afPurchaseClient.startObservingTransactions(); print("Purchase Connector initialized with StoreKit 2"); } catch (e) { print("Failed to initialize Purchase Connector: $e"); // Consider fallback to StoreKit 1 or handle error appropriately } ``` -------------------------------- ### Manually Trigger Deep Linking (Android) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Enable manual triggering of deep link resolution on Android, useful for apps delaying SDK start. This API triggers the `onDeepLink` callback. ```dart void afStart() async { // SDK Options final AppsFlyerOptions options = AppsFlyerOptions( afDevKey: dotenv.env["DEV_KEY"]!, appId: dotenv.env["APP_ID"]!, showDebug: true, timeToWaitForATTUserAuthorization: 15, manualStart: true); _appsflyerSdk = AppsflyerSdk(options); // Init of AppsFlyer SDK await _appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true); // Conversion data callback _appsflyerSdk.onInstallConversionData((res) { print("onInstallConversionData res: " + res.toString()); setState(() { _gcd = res; }); }); // App open attribution callback _appsflyerSdk.onAppOpenAttribution((res) { print("onAppOpenAttribution res: " + res.toString()); setState(() { _deepLinkData = res; }); }); // Deep linking callback _appsflyerSdk.onDeepLinking((DeepLinkResult dp) { switch (dp.status) { case Status.FOUND: print(dp.deepLink?.toString()); print("deep link value: ${dp.deepLink?.deepLinkValue}"); break; case Status.NOT_FOUND: print("deep link not found"); break; case Status.ERROR: print("deep link error: ${dp.error}"); break; case Status.PARSE_ERROR: print("deep link status parsing error"); break; } print("onDeepLinking res: " + dp.toString()); setState(() { _deepLinkData = dp.toJson(); }); }); if(Platform.isAndroid){ _appsflyerSdk.performOnDeepLinking(); } _appsflyerSdk.startSDK(); } ``` -------------------------------- ### Initialize SDK and Register Callbacks Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/BasicIntegration.md Initialize the AppsFlyer SDK and register callbacks for conversion data, app open attribution, and deep linking. Note that `registerOnDeepLinkingCallback` will override `registerOnAppOpenAttributionCallback`. ```dart await appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true ); ``` -------------------------------- ### Configure AppsFlyer SDK Options Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initialize the SDK configuration using the AppsFlyerOptions class. ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; //.. final AppsFlyerOptions options = AppsFlyerOptions(afDevKey: "af dev key", showDebug: true, appId: "123456789"); ``` -------------------------------- ### Enable Debug Mode and Initialize SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Testing.md Set showDebug to true in AppsFlyerOptions to enable full logging during development. ```dart AppsFlyerOptions appsFlyerOptions = AppsFlyerOptions( afDevKey: afDevKey, appId: appId, showDebug: true); AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions); appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: false ); ``` -------------------------------- ### Report Universal Links in Objective-C Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DeepLink.md Implement this method in the AppDelegate to report app opens from Universal Links. Note that the SDK method varies based on the version used. ```objective-c // Reports app open from a Universal Link for iOS 9 or above - (BOOL) application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> *restorableObjects))restorationHandler { // AppsFlyer SDK version 6.2.0 and above [[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler]; // AppsFlyer SDK version 6.1.0 and below [[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler]; return YES; } ``` -------------------------------- ### Define User Invite Link Parameters Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Defines the structure for invite link query parameters. ```dart class AppsFlyerInviteLinkParams { final String channel; final String campaign; final String referrerName; final String referrerImageUrl; final String customerID; final String baseDeepLink; final String brandDomain; } ``` -------------------------------- ### Opt-in for Android Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Set the appsflyer.enable_purchase_connector property in the gradle.properties file to enable the feature on Android. ```groovy appsflyer.enable_purchase_connector=true ``` -------------------------------- ### Simulate RC Pipeline Locally Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/docs/rc-pipeline-poc.md Execute the local simulation of the RC pipeline. Use '--platform' to specify 'ios', 'android', or 'both'. Pass '--keep-branch' to inspect the staging state after the run. ```sh ./scripts/simulate-rc-pipeline.sh --platform ios # or --platform android # or --platform both ``` -------------------------------- ### Handle URI Schemes in Swift Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Implementation of application openURL methods to handle deep links in Swift. ```swift override func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { AppsFlyerAttribution.shared()!.handleOpenUrl(url, sourceApplication: sourceApplication, annotation: annotation); return true } override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { AppsFlyerAttribution.shared()!.handleOpenUrl(url, options: options) return true } ``` -------------------------------- ### Handle Direct Deep Linking Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DeepLink.md Register the onAppOpenAttribution callback before SDK initialization to handle direct deep linking for existing users. ```dart appsflyerSdk.onAppOpenAttribution((res){ print("res: " + res.toString()); }); ``` -------------------------------- ### Report Universal Links in Swift Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DeepLink.md Implement these methods in the AppDelegate to handle Universal Links in Swift-based iOS projects. ```swift private func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { AppsFlyerAttribution.shared()!.continueUserActivity(userActivity, restorationHandler: nil) return true } override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { AppsFlyerAttribution.shared()!.continueUserActivity(userActivity, restorationHandler: nil) return true } ``` -------------------------------- ### Configure Deep Link Path and Initialize SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Call `addPushNotificationDeepLinkPath` before initializing the SDK to specify where the OneLink URL is located in the push payload. Ensure `registerOnDeepLinkingCallback` is set to true. ```dart // Must be called BEFORE initSdk() or startSDK() appsFlyerSdk.addPushNotificationDeepLinkPath(["deeply", "nested", "deep_link"]); // Then initialize the SDK await appsFlyerSdk.initSdk( registerOnDeepLinkingCallback: true // Enable deep linking callback ); ``` -------------------------------- ### Opt-in for iOS Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Set the AppsFlyerPurchaseConnector property in the Podfile to enable the feature on iOS. ```ruby $AppsFlyerPurchaseConnector = true ``` -------------------------------- ### Handle Android onNewIntent Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/DeepLink.md Required for Android activities using non-standard launch modes in plugin versions below 6.4.0. ```java @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); } ``` ```kotlin override fun onNewIntent(intent : Intent){ super.onNewIntent(intent) setIntent(intent) } ``` -------------------------------- ### Implement AppDelegate for Deep Linking in Swift Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Full AppDelegate implementation for handling URI schemes and Universal Links in a Flutter iOS project. ```Swift import UIKit import Flutter import AppsFlyerLib @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } // Open URI-scheme for iOS 9 and above override func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { NSLog("AppsFlyer [deep link]: Open URI-scheme for iOS 9 and above") AppsFlyerAttribution.shared()!.handleOpenUrl(url, sourceApplication: sourceApplication, annotation: annotation); return true } // Reports app open from deep link for iOS 10 or later override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { NSLog("AppsFlyer [deep link]: continue userActivity") AppsFlyerAttribution.shared()!.continueUserActivity(userActivity, restorationHandler:nil ) return true } override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { NSLog("AppsFlyer [deep link]: Open URI-scheme options") AppsFlyerAttribution.shared()!.handleOpenUrl(url, options: options) return true } } ``` -------------------------------- ### Initialize the AppsFlyer SDK Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Initialize the SDK after creating the AppsflyerSdk object. Note that the method signature changed in version 1.2.2. ```dart import 'package:appsflyer_sdk/appsflyer_sdk.dart'; //.. AppsflyerSdk _appsflyerSdk = AppsflyerSdk({...}); await _appsflyerSdk.initSdk( registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true, registerOnDeepLinkingCallback: true) ``` -------------------------------- ### Handle URI Schemes in Objective-C Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Implementation of application openURL methods to handle deep links in Objective-C. ```objective-c - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation { // AppsFlyer SDK version 6.2.0 and above [[AppsFlyerAttribution shared] handleOpenUrl:url sourceApplication:sourceApplication annotation:annotation]; // AppsFlyer SDK version 6.1.0 and below [[AppsFlyerLib shared] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation]; return YES; } // Reports app open from deep link for iOS 10 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options { // AppsFlyer SDK version 6.2.0 and above [[AppsFlyerAttribution shared] handleOpenUrl:url options:options]; // AppsFlyer SDK version 6.1.0 and below [[AppsFlyerLib shared] handleOpenUrl:url options:options]; return YES; } ``` -------------------------------- ### Simulate RC Pipeline Script Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/example_rc_smoke/README.md Execute this script for a local dry-run of the full RC pipeline. It modifies the smoke plan to use a local path dependency for testing. ```shell ./scripts/simulate-rc-pipeline.sh --platform ios ``` -------------------------------- ### setOutOfStore Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Specify the alternative app store that the app is downloaded from (Android Only). ```APIDOC ## void setOutOfStore(String sourceName) ### Description **Android Only!** Specify the alternative app store that the app is downloaded from. ### Method void ### Endpoint N/A (Method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **sourceName** (String) - Required - The name of the alternative app store. ### Request Example ```dart if(Platform.isAndroid){ appsflyerSdk.setOutOfStore("facebook_int"); } ``` ### Response None ``` -------------------------------- ### Request Tracking Authorization in AppDelegate.m Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/AdvancedAPI.md Implement the ATT pop-up for IDFA collection in your AppDelegate.m file. This code should be placed within the applicationDidBecomeActive method. ```objective-c - (void)applicationDidBecomeActive:(nonnull UIApplication *)application { if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { // native code here }]; } } ``` -------------------------------- ### validateAndLogInAppPurchaseV2 (Recommended - BETA) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md The unified cross-platform purchase validation API. Recommended for new implementations as it provides a consistent interface across Android and iOS. ```APIDOC ## POST /validateAndLogInAppPurchaseV2 ### Description Validates in-app purchases across Android and iOS using a unified, cross-platform API. This is the recommended approach for purchase validation. ### Method POST ### Endpoint /validateAndLogInAppPurchaseV2 ### Parameters #### Request Body - **purchaseDetails** (AFPurchaseDetails) - Required - Purchase details object containing purchase type, token, and product ID. - **additionalParameters** (Map?) - Optional - Additional parameters to send with the validation request. ### Request Example ```json { "purchaseDetails": { "purchaseType": "subscription", "purchaseToken": "your_purchase_token_from_store", "productId": "premium_subscription_monthly" }, "additionalParameters": { "app_version": "1.2.0", "validation_source": "flutter_example" } } ``` ### Response #### Success Response (200) - **validationResult** (Map) - Validation result with detailed response information. #### Response Example ```json { "validationResult": { "is_validated": true, "status": "success", "message": "Purchase validated successfully." } } ``` ``` -------------------------------- ### Configure Deep Link URLs Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Enable the SDK to resolve wrapped OneLink Universal Links for correct deep linking. Provide a list of domain strings to be resolved. ```dart appsflyerSdk.setResolveDeepLinkURLs(["clickdomain.com", "myclickdomain.com", "anotherclickdomain.com"]); ``` -------------------------------- ### Purchase Validation Callback Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/AdvancedAPI.md Sets up a callback function to receive purchase validation results. ```APIDOC ## onPurchaseValidation ### Description Registers a callback function that will be invoked with the purchase validation results. ### Method `void onPurchaseValidation(Function callback)` ### Parameters #### Request Body - **callback** (Function) - Required - The function to be called with the validation result. It receives one argument: `res` (dynamic). ### Request Example ```dart appsflyerSdk.onPurchaseValidation((res){ print("res: " + res.toString()); }); ``` ``` -------------------------------- ### Set Out-of-Store Source (Android) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/API.md Specify the alternative app store for Android app downloads. This is an Android-only feature. ```dart if(Platform.isAndroid){ appsflyerSdk.setOutOfStore("facebook_int"); } ``` -------------------------------- ### Configure Sandbox Environment in Dart Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/PurchaseConnector.md Set the `sandbox` parameter to `true` in `PurchaseConnectorConfiguration` for testing. Remember to revert to `false` for production to ensure proper event validation. ```dart final purchaseConnector = PurchaseConnector( config: PurchaseConnectorConfiguration( sandbox: true, logSubscriptions: true, logInApps: true, // storeKitVersion defaults to StoreKitVersion.storeKit1 ) ); final purchaseConnectorSK2 = PurchaseConnector( config: PurchaseConnectorConfiguration( sandbox: true, logSubscriptions: true, logInApps: true, storeKitVersion: StoreKitVersion.storeKit2, // Enhanced testing capabilities ) ); ``` -------------------------------- ### Android onNewIntent for Activity (Kotlin) Source: https://github.com/appsflyersdk/appsflyer-flutter-plugin/blob/master/doc/Guides.md Override `onNewIntent` in your `MainActivity.kt` to correctly handle intents for activities launched with non-standard launch modes. ```kotlin override fun onNewIntent(intent : Intent){ super.onNewIntent(intent) setIntent(intent) } ```