AppsFlyer’s Unity Plugin

You can find the plugin on Github here: https://github.com/AppsFlyerSDK/Unity

Set out below are the integration instructions for using AppsFlyer’s Unity Plugin.

Plugin Installation

Set out below are the installation instructions for the AppsFlyer's plugin:

  1. Import the AppsFlyerUnityPlugin.unitypackage into your Unity project.
  2. Go to Assets >> Import Package >> Custom Package
  3. Select AppsFlyerUnityPlugin.unitypackage file.
  4. In your Start / Init methods add the following code:
Unity Plugin 4.15.1 and above Unity Plugin 4.14.3 and below
void Start () {
/* Mandatory - set your AppsFlyer’s Developer key. */
AppsFlyer.setAppsFlyerKey ("YOUR_APPSFLYER_DEV_KEY_HERE");
/* For detailed logging */
/* AppsFlyer.setIsDebug (true); */
/* Mandatory - set your apple app ID
NOTE: You should enter the number only and not the "ID" prefix */
AppsFlyer.setAppID ("YOUR_APP_ID_HERE");
AppsFlyer.trackAppLaunch ();
/* Mandatory - set your Android package name */
/* For getting the conversion data in Android, you need to add the "AppsFlyerTrackerCallbacks" listener.*/
AppsFlyer.init ("YOUR_DEV_KEY","AppsFlyerTrackerCallbacks");


In iOS, the conversion data response is triggered in the AppsFlyerTrackerCallbacks.cs class.

Getting Conversion Data

To load AppsFlyer's conversion data from its servers:

  1. Add an empty GameObject
  2. Attach to it the AppsFlyerTrackerCallbacks.cs which is included in the project (you must name this gameobject AppsFlyerTrackerCallbacks).
Android Unity Plugin > 4.15.1 Android Unity Plugin < 4.14.3 iOS
/*For getting the conversion data in Android, you need to add this listener. to the init() method*/
AppsFlyer.init ("YOUR_DEV_KEY","AppsFlyerTrackerCallbacks");

In Android, you can move the methods from AppsFlyerTrackerCallbacks.cs to another class, and call that class in your listener.

You must use the exact same method namespaces that appear on AppsFlyerTrackerCallbacks.

In-App Purchase Receipt Validation

For In-App Purchase Receipt Validation, follow the instructions according to your operating system.

Android Call Call the Listener (Android Only) iOS
//To get the callbacks
//AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");
AppsFlyer.validateReceipt(string publicKey, string purchaseData, string signature, string price, string currency, Dictionary additionalParametes);

The validate purchase response is triggered in the AppsFlyerTrackerCallbacks.cs class

Track Event API

Tracking Event Example:

System.Collections.Generic.Dictionary<string, string> purchaseEvent = new   
System.Collections.Generic.Dictionary<string, string> ();
purchaseEvent.Add ("af_currency", "USD");
purchaseEvent.Add ("af_revenue", "0.99");
purchaseEvent.Add ("af_quantity", "1");
AppsFlyer.trackRichEvent ("af_purchase", purchaseEvent);


  • Setting user local currency code for in app purchases: The currency code should be a 3 character ISO 4217 code. (default is USD)
  • AppsFlyer.setCurrencyCode("GBP");
  • Settings the user ID as used by the app:
  • AppsFlyer.setCustomerUserID("someId");


Set the AF receiver and permissions (Mandatory):

// receiver should be inside the <application> tag
<receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
<action android:name="com.android.vending.INSTALL_REFERRER" />
//Mandatory permission:
<uses-permission android:name="android.permission.INTERNET" />


For Deeplinking, follow the instructions according to your operating system.

Android iOS
Add the following to your manifest file:
<activity android:name="com.appsflyer.GetDeepLinkingActivity" android:exported="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your_scheme" />


For Uninstall, follow the instructions according to your operating system.

Android iOS
Add these lines to your manifest:


 <uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="android.appsflyer.sampleapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.appsflyer.sampleapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


You must replace android.appsflyer.sampleapp with the bundle identifier of your application.


<action android:name="com.google.android.c2dm.intent.RECEIVE" />

Call this method:


GCM Project number is obtained through your google developer console.

For more details please refer to our Android Uninstall guide

iOS Apple Search Ads

Add the following:

AppsFlyer collects IDFA only if you include this framework. Failure to add this framework means that you cannot track Facebook, Twitter and most other ad networks.

Adding this framework to your app project is highly recommend since it is mandatory for tracking Apple Search Ads.

Additional Links

SDK integration guides for complete API documentation:

Unity Sample Project:

Was this article helpful?
0 out of 0 found this helpful