appsflyer_sdk 6.0.3+1 appsflyer_sdk: ^6.0.3+1 copied to clipboard
A Flutter plugin for AppsFlyer SDK. Supports iOS and Android.
appsflyer_sdk #
A Flutter plugin for AppsFlyer SDK.
In order for us to provide optimal support, we would kindly ask you to submit any issues to support@appsflyer.com
When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , reproduction steps, logs, code snippets and any additional relevant information.
Supported Platforms #
- Android
- iOS 8+
This plugin is built for #
- iOS AppsFlyerSDK v6.0.2
- Android AppsFlyerSDK v5.4.1
API Methods #
Getting started #
In order to install the plugin, visit this page.
To start using AppsFlyer you first need to create an instance of AppsflyerSdk
before using any other of our sdk functionalities.
Migration Guide to v6 #
Integration guide Migration guide In v6 of AppsFlyer SDK there are some api breaking changes:
Before v6 | v6 |
---|---|
trackEvent | logEvent |
stopTracking | stop |
validateAndTrackInAppPurchase | validateAndLogInAppPurchase |
iOS #
on iOS you need to implement IDFA request pop up and add AppTrackTransparency framework in order for the plugin to work
AppsflyerSdk(Map options)
parameter | type | description |
---|---|---|
options |
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 options = { "afDevKey": afDevKey,
"afAppId": appId,
"isDebug": true};
AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
Or you can use AppsFlyerOptions
class instead
AppsflyerSdk(Map options)
parameter | type | description |
---|---|---|
options |
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.
static Future<Map<dynamic, dynamic>> initSdk({bool registerConversionDataCallback, bool registerOnAppOpenAttributionCallback}) async
(Changed in 1.2.2)
initialize the SDK, using the options initialized from the constructor|
Return response object with the field status
The user can access conversionDataStream
and appOpenAttributionStream
to listen for events
Example:
import 'package:appsflyer_sdk/appsflyer_sdk.dart';
//..
AppsflyerSdk _appsflyerSdk = AppsflyerSdk({...});
FutureBuilder<dynamic> ( future: _appsflyerSdk.initSdk(registerConversionDataCallback: true, registerOnAppOpenAttributionCallback: true), builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData)
return HomeContainer(
onData: _appsflyerSdk.conversionDataStream,
onAttribution: _appsflyerSdk.appOpenAttributionStream,
...
)
...
static Future<bool> logEvent(String eventName, Map eventValues) async
(optional)
- 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> sendEvent(String eventName, Map eventValues) async {
bool result;
try {
result = await appsflyerSdk.logEvent(eventName, eventValues);
} on Exception catch (e) {}
print("Result logEvent: ${result}");
}
Conversion Data and on app open attribution #
static Stream<dynamic> registerConversionDataCallback()
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:
appsflyerSdk.registerConversionDataCallback().listen((data) {
//print("GCD: " + data.toString());
//....
}).onError((handleError) {
print("error");
});
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"
}
static Stream<dynamic> registerOnAppOpenAttributionCallback()
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:
appsflyerSdk.registerOnAppOpenAttributionCallback().listen((data) {
//print("OnAppOpenAttribution: " + data.toString());
//....
}).onError((handleError) {
print("error");
});
Example of response on deep-link "https://flutter.demo" :
{
"status": "success",
"type": "onAppOpenAttribution",
"data": {
"link": "https://flutter.demo"
}
}
Android Out of store #
Please make sure to go over this guide to get general understanding of how out of store attribution is set up in AppsFlyer. If the store you distribute the app through supports install referrer matching or requires the referrer in the postback, make sure to add the following to the AndroidManifest.xml:
<application>
...
<receiver android:name="com.appsflyer.SingleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
Other functionalities: #
void 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(
["a@a.com", "b@b.com"], 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 track 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");
Stream validateAndTrackInAppPurchase( String publicKey, String signature, String purchaseData, String price, String currency, Map<String, String> additionalParameters)
Example:
appsFlyerSdk.validateAndTrackInAppPurchase(
"publicKey",
"signature",
"purchaseData",
"price",
"currency",
{"fs": "fs"}).listen((data) {
print(data);
}).onError((error) {
print(error);
});