Skip to content

Latest commit

 

History

History
600 lines (481 loc) · 17.7 KB

API.md

File metadata and controls

600 lines (481 loc) · 17.7 KB

API

Types

Methods


parameter type description
appsFlyerOptions Map SDK configuration

options

name type default description
afDevKey string Appsflyer Dev key
afAppId string Apple Application ID (for iOS only)
isDebug boolean false debug mode (optional)

Example:

import 'package:appsflyer_sdk/appsflyer_sdk.dart';
//..

Map appsFlyerOptions = { "afDevKey": afDevKey,
                "afAppId": appId,
                "isDebug": true};

AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions);

Or you can use AppsFlyerOptions class instead

AppsflyerSdk(Map options)
parameter type description
appsFlyerOptions AppsFlyerOptions SDK configuration

Example:

import 'package:appsflyer_sdk/appsflyer_sdk.dart';
//..

final AppsFlyerOptions options = AppsFlyerOptions(afDevKey: "af dev key",
                                                  showDebug: true,
                                                  appId: "123456789");

Once AppsflyerSdk object is created, you can call initSdk method.


initialize the SDK, using the options initialized from the constructor| Return response object with the field status

Example:

import 'package:appsflyer_sdk/appsflyer_sdk.dart';
//..

AppsflyerSdk _appsflyerSdk = AppsflyerSdk({...});

_appsflyerSdk.initSdk(   
  registerConversionDataCallback: true, 
  registerOnAppOpenAttributionCallback: true, 
  registerOnDeepLinkingCallback: true)

  • Trigger callback when onAppOpenAttribution is activated on the native side

Example:

_appsflyerSdk.onAppOpenAttribution((res) {
      print("res: " + res.toString());
    });
  • Trigger callback when onInstallConversionData is activated on the native side

Example:

    _appsflyerSdk.onInstallConversionData((res) {
      print("res: " + res.toString());
    });
  • Trigger callback when onDeepLinking is activated on the native side

Example:

    _appsflyerSdk.onDeepLinking((res) {
      print("res: " + res.toString());
    });

  • These in-app events help you to understand how loyal users discover your app, and attribute them to specific campaigns/media-sources. Please take the time define the event/s you want to measure to allow you to send ROI (Return on Investment) and LTV (Lifetime Value).
  • The logEvent method allows you to send in-app events to AppsFlyer analytics. This method allows you to add events dynamically by adding them directly to the application code.
parameter type description
eventName String custom event name, is presented in your dashboard. See the Event list HERE
eventValues Map event details

Example:

Future<bool> logEvent(String eventName, Map eventValues) async {
    bool result;
    try {
      result = await appsflyerSdk.logEvent(eventName, eventValues);
    } on Exception catch (e) {}
      print("Result logEvent: ${result}");
  }

Other functionalities:

setUserEmails(List<String> emails, [EmailCryptType cryptType])

Set the user emails with the given encryption (EmailCryptTypeNone, EmailCryptTypeSHA1, EmailCryptTypeMD5, EmailCryptTypeSHA256). the default encryption is EmailCryptTypeNone.

Example:

appsFlyerSdk.setUserEmails(
       ["[email protected]", "[email protected]"], EmailCryptType.EmailCryptTypeSHA1);

void setMinTimeBetweenSessions(int seconds) You can set the minimum time between session (the default is 5 seconds)

appsFlyerSdk.setMinTimeBetweenSessions(3)

void stop(bool isStopped) You can stop sending events to Appsflyer by using this method.

Example:

widget.appsFlyerSdk.stop(true);

void setCurrencyCode(String currencyCode)

Example:

appsFlyerSdk.setCurrencyCode("currencyCode");

void setIsUpdate(bool isUpdate)

Example:

appsFlyerSdk.setIsUpdate(true);

void enableUninstallTracking(String senderId)

Example:

appsFlyerSdk.enableUninstallTracking("senderId");

void setImeiData(String imei)

Example:

appsFlyerSdk.setImeiData("imei");

void setAndroidIdData(String androidIdData)

Example:

appsFlyerSdk.setAndroidIdData("androidId");

void enableLocationCollection(bool flag)

Example:

appsFlyerSdk.enableLocationCollection(true);

void setCustomerUserId(String userId) What is customer user id?

Example:

appsFlyerSdk.setCustomerUserId("id");

void waitForCustomerUserId(bool wait) You can set this function to true if you don't want to log events without setting customer id first.

Example:

appsFlyerSdk.waitForCustomerUserId(true);

void setAdditionalData(Map addionalData)

Example:

appsFlyerSdk.setAdditionalData({"customData": "data"});

void setCollectAndroidId(bool isCollect)

Example:

appsFlyerSdk.setCollectAndroidId(true);

void setCollectIMEI(bool isCollect)
NOTE: Make sure to add <uses-permission android:name="android.permission.READ_PHONE_STATE" /> in the AndroidManifest and request these permissions in the runtime in order for the SDK to be able to collect IMEI

Example:

appsFlyerSdk.setCollectIMEI(false);

void setHost(String hostPrefix, String hostName) You can change the default host (appsflyer) by using this function

Example:

appsFlyerSdk.setHost("pref", "my-host");

Future<String> getHostName()

Example:

appsFlyerSdk.getHostName().then((name) {
         print("Host name: ${name}");
       });

Future<String> getHostPrefix()

Example:

appsFlyerSdk.getHostPrefix().then((name) {
         print("Host prefix: ${name}");
       });

void updateServerUninstallToken(String token)

Example:

appsFlyerSdk.updateServerUninstallToken("token");

Validate Purchase

Android:

Future<dynamic> validateAndLogInAppAndroidPurchase( String publicKey, String signature, String purchaseData, String price, String currency, Map<String, String> additionalParameters)

Example:

appsFlyerSdk.validateAndLogInAppAndroidPurchase(
           "publicKey",
           "signature",
           "purchaseData",
           "price",
           "currency",
           {"fs": "fs"});

iOS:

Future<dynamic> validateAndLogInAppIosPurchase( String productIdentifier, String price, String currency, String transactionId, Map<String, String> additionalParameters)

Example:

appsFlyerSdk.validateAndLogInAppIosPurchase(
           "productIdentifier",
           "price",
           "currency",
           "transactionId",
           "additionalParameters");

Purchase validation sandbox mode for iOS:

void useReceiptValidationSandbox(bool isSandboxEnabled)

Example:

appsFlyerSdk.useReceiptValidationSandbox(true);

Purchase validation callback

void onPurchaseValidation(Function callback)

Example:

appsflyerSdk.onPurchaseValidation((res){
  print("res: " + res.toString());
});

void setPushNotification(bool isEnabled)

Example:

appsFlyerSdk.setPushNotification(true);

NOTE:

For Android: Make sure to call this API inside the page of every activity that is launched after clicking the notification.

For iOS: This API can be called once at the initalization phase.

Please check the following guide in order to understand the relevant payload needed for AppsFlyer to attribute the push notification:

https://support.appsflyer.com/hc/en-us/articles/207364076-Measuring-push-notification-re-engagement-campaigns


User Invite

  1. First define the Onelink ID (find it in the AppsFlyer dashboard in the onelink section:

Future<void> setAppInviteOneLinkID(String oneLinkID, Function callback)

  1. Set the AppsFlyerInviteLinkParams class to set the query params in the user invite link:
class AppsFlyerInviteLinkParams {
  final String channel;
  final String campaign;
  final String referrerName;
  final String referreImageUrl;
  final String customerID;
  final String baseDeepLink;
  final String brandDomain;
}
  1. Call the generateInviteLink API to generate the user invite link. Use the success and error callbacks for handling.

void generateInviteLink(AppsFlyerInviteLinkParams parameters, Function success, Function error)

Example:

appsFlyerSdk.setAppInviteOneLinkID('OnelinkID', 
(res){ 
  print("setAppInviteOneLinkID callback: $res"); 
});

AppsFlyerInviteLinkParams inviteLinkParams = new AppsFlyerInviteLinkParams(
      channel: "",
      referrerName: "",
      baseDeepLink: "",
      brandDomain: "",
      customerID: "",
      referreImageUrl: "",
      campaign: ""
);

appsFlyerSdk.generateInviteLink(inviteLinkParams, 
  (result){ 
    print(result); 
  }, 
  (error){ 
    print(error);
  }
);

void enableFacebookDeferredApplinks(bool isEnabled)

Please make sure the relevant Facebook dependecies are added to the project!

For more information check the following article: https://support.appsflyer.com/hc/en-us/articles/207033826-Facebook-Ads-setup-guide#advanced-using-facebook-ads-appsflyer-sdks-for-deferred-deep-linking

Example:

appsFlyerSdk.enableFacebookDeferredApplinks(true);

void disableSKAdNetwork(bool isEnabled)

Use this API in order to disable the SK Ad network (request will be sent but the rules won't be returned).

Example:

appsFlyerSdk.disableSKAdNetwork(true);

Future<String?> getAppsFlyerUID() async

Use this API in order to get the AppsFlyer ID.

Example:

appsFlyerSdk.getAppsFlyerUID().then((AppsFlyerId) {
  print("AppsFlyer ID: ${AppsFlyerId}");
});

void setCurrentDeviceLanguage(string language)

Use this API in order to set the language

Example:

appsFlyerSdk.setCurrentDeviceLanguage("en");

void setSharingFilterForPartners(List<String> partners)

setSharingFilter & setSharingFilterForAllPartners APIs were deprecated!

Use setSharingFilterForPartners instead.

Used by advertisers to exclude specified networks/integrated partners from getting data. Learn more here

Example:

appsFlyerSdk.setSharingFilterForPartners([]);                                        // Reset list (default)
appsFlyerSdk.setSharingFilterForPartners(null);                                      // Reset list (default)
appsFlyerSdk.setSharingFilterForPartners(['facebook_int']);                          // Single partner
appsFlyerSdk.setSharingFilterForPartners(['facebook_int', 'googleadwords_int']);     // Multiple partners
appsFlyerSdk.setSharingFilterForPartners(['all']);                                   // All partners
appsFlyerSdk.setSharingFilterForPartners(['googleadwords_int', 'all']);              // All partners

Conversion Data and on app open attribution for older versions

For plugin version 6.0.5+2 and below the user can access conversionDataStream, appOpenAttributionStream and onDeepLinkingStream to listen for events (see example app)

Returns Stream. Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking). Read more: Android, iOS. AppsFlyer plugin will return attribution data as JSON Map in Stream.

Example:

StreamBuilder<dynamic>(
    stream: _appsflyerSdk.conversionDataStream?.asBroadcastStream(),
    builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        ...
    }
)

Example of success Organic response:

{
  "status": "success",
  "type": "onInstallConversionDataLoaded",
  "data": {
    "af_status": "Organic",
    "af_message": "organic install",
    "is_first_launch": "false"
  }
}

Example of failure response:

{
  "status": "failure",
  "type": "onInstallConversionDataLoaded",
  "data": "SOME_ERROR_MESSAGE"
}

In case you want to use deep links in your app, you will need to use registerOnAppOpenAttributionCallback on the AppsflyerSdk instance you've created.
Example:

StreamBuilder<dynamic>(
    stream: _appsflyerSdk.appOpenAttributionStream?.asBroadcastStream(),
    builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        ...
    }
)

Example of response on deep-link "https://flutter.demo" :

{
  "status": "success",
  "type": "onAppOpenAttribution",
  "data": {
    "link": "https://flutter.demo"
  }
}

In case you want to use deep links in your app, you will need to use registerOnDeepLinkingCallback on the AppsflyerSdk instance you've created.
Example:

StreamBuilder<dynamic>(
    stream: _appsflyerSdk.onDeepLinkingStream?.asBroadcastStream(),
    builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        ...
    }
)

Example of response on deep-link "https://flutter.demo" :

{
  "status": "success",
  "type": "onDeepLinking",
  "data": {
    "deepLink":{
      "media_source": "test",
      "campaign": "None",
      "is_deferred": false
    },
    "status": "FOUND"
  }
}