Code Monkey home page Code Monkey logo

unity's Introduction

Integrating AppsFlyer Plugin into Unity Project

Whats new:

V-4.8

  • Updated iOS native SDK to v4.4.1
  • Updated Android native SDK to v4.3.7

Installation instructions for the AppsFlyer's plugin:

  1. Import the AppsFlyerUnityPlugin.unitypackage into your Unity project. go to Assets/import Package/Custom Pacakge and chose AppsFlyerUnityPlugin.unitypackage file.

  2. In your Start / Init methods add the following code:

void Start () {
		
	AppsFlyer.setAppsFlyerKey ("YOUR_APPSFLYER_DEV_KEY_HERE");

	#if UNITY_IOS 

	AppsFlyer.setAppID ("YOUR_APP_ID_HERE");
		
	// For detailed logging
	//AppsFlyer.setIsDebug (true); 
		
	// For getting the conversion data will be triggered on AppsFlyerTrackerCallbacks.cs file
	AppsFlyer.getConversionData (); 
		
	// For testing validate in app purchase (test against Apple's sandbox environment
	//AppsFlyer.setIsSandbox(true); 		
	
	AppsFlyer.trackAppLaunch ();

	#elif UNITY_ANDROID
		
	// All Initialization occur in the override activity defined in the mainfest.xml, 
	// including the track app launch
	// For your convinence (if your manifest is occupied) you can define AppsFlyer library
	// here, use this commented out code.
		
	//AppsFlyer.init ("YOUR_ANDROID_PACKAGE_NAME_HERE"); 
	//AppsFlyer.setIsDebug (true);
	//AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");
	AppsFlyer.loadConversionData("AppsFlyerTrackerCallbacks","didReceiveConversionData", "didReceiveConversionDataWithError");

	#endif
}	

Important: The conversion data response will be triggered in the AppsFlyerTrackerCallbacks.cs class.

There is a sample project located here: https://github.com/AppsFlyerSDK/AppsFlyerUnitySampleApp.git

Getting Conversion Data:

To load AppsFlyer's conversion data from it's servers: Add Empty Object call it AppsFlyerTrackerCallbacks, and attach to it the AppsFlyerTrackerCallbacks.cs which is included in the project, for more information, please refer to the sample scene provided with the project.

public void didReceiveConversionData(string conversionData) {
	print ("AppsFlyerTrackerCallbacks:: got conversion data = " + conversionData);
}
//The conversion data is in Json Format.

In App Purchase Receipt Validation

iOS:

For testing make sure you test against Apple sandbox server call:

AppsFlyer.setIsSandbox(true);
AppsFlyer.validateReceipt(string productIdentifier, string price, string currency, string transactionId, Dictionary additionalParametes);

Android:

For Android call:
AppsFlyer.validateReceipt(string publicKey, string purchaseData, string signature, string price, string currency);

Note: If you are NOT using Appsflyer Override Activity defined in the manifest.xml you should call this code in order to initialize the callback response:

AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");

The validate purchase response will be 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");

#For Android:

The Android Override Activity in the manifest sends the TrackAppLaunch() automatically.
Set the Dev_Key in the manifest.

<meta-data android:name="AppsFlyerDevKey" android:value="YOUR_DEV_KEY_HERE"/>

If your manifest file is occupied by other services, you can initialize the Appsflyer tracker manually in the startup script and call AppsFlyer.trackAppLaunch (); explicitly.
Remove all related code from the manifest besides the receiver tag which holds the reffer information.

Set permissions mandatory (if missing):

<pre><code><receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
	<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
// inside the <application> tag

//For permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE” />

*READ_PHONE_STATE permission is optional. Adding this permission will enable Carrier tracking Android_id and IMEI (required for tracking out of Google Play)

To collect Google advertising ID

Integrate Google Play Services.

Open the Android SDK manager, scroll down to the Extras folder and verify that you have downloaded the Google Play Services package. See http://developer.android.com/google/play-services/setup.html. Uncomment the following line in the AndroidManifest.xml file:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

Pelase refer to SDK integration guides for complete API documentation.

iOS Integration Guide.

Android Integration Guide.

unity's People

Contributors

gmeroz avatar orenbaranes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.