Android Integration: Unity

Welcome to the Affle MAAS Android Unity Plugin Integration Section. Our SDK provides developers the flexibility to choose and integrate one or more components based on their requirements.

Getting the Affle Tracker Unity Plugin

You can download the latest Affle’s Maas tracker Unity Plugin from the link below:


Affle’s Maas tracker Unity Plugin (Last updated: 21/October/2015)

1. AffleTrackerUnityPackage.unitypackage: This Affle’s UnityPackage has to be imported in unity android application, to be downloaded from the Google Playstore.
2. ProjectSettings.txt : This file contains Tracking URL and other key settings specific to the application.

The step-by-step integration process has been described in detail in the coming sections.
Pre-requisite: – It has been assumed that the developer has sound knowledge of using the Unity.

Integration Guide

Import the AffleTrackerUnityPackage in your Project
1. Import file “AffleTrackerUnityPackage.unitypackage” into unity AffleTrackerUnityPackage is includedAfflePlugin.cs file.

android import unity

2. Open the AndroidManifest.xml file in your project and add the following: – Permission to access Internet, Phone State and Network State.

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

Optional Permission:

<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

3. To enable “DEBUG” logs, the following setting should be enabled.

//Other Settings

android:value=”true” />

* Please ensure that the “af_DebugMode” should be set to “false” before going live.

4. Add google-play-services.jar along with res (needed only values->version.xml file) and .properties file into Assets->Plugins->Android folder (Ignore if already exists).

5. Add google_play_services_version in Project’s Manifest file inside application tag.

//Other Settings

android:value=”@integer/google_play_services_version” />

6. Add android-support-v4.jar in your Assets->Plugins->Android folder (Ignore if already exists).

Download Conversion Tracking

1. Open the AndroidManifest.xml file in your project and add the following RECEIVER settings.

<receiver android:name=”com.affle.affledowloadtracker.AffleAppDownloadTracker” android:exported=”true”>
<action android:name=”” />

2. Do the following settings in the AndroidManifest.xml, Under the Application section.

//Other Settings


The Affle_CAMPAIGN_ID is provided to you as a part of the Project Settings file.

3. Put the following lines of code in the first place of unity App run. We Recommend to place it in the Start() method of Application.

void Start ()
/*Track Download When App get launched*/
afflePlugin = new AfflePlugin ();
afflePlugin.trackDownload ();

In-App Stats and Purchase Tracking

1. Set tracking duration for a session as follow:
Under the Application section, add the following META-DATA

//Other Settings


The default value is 3600 seconds if it were not set.

2. Call the following methods in your program to capture the Page Views, Engagements, Events, Purchase Events & other Analytics

a) Page Views/Events Tracking

To track your Page or Screen views and Engagement/Events in the app call, the method “inAppTrackerViewName” and pass the View Name , Event Name , View Details that should be displayed on the analytics interface.

public void inAppTrackerViewName
string viewName, //View Name
string viewDetails, //View Details
string eventName, //Event name want to capture
string extraParams // Extra Parameters user want to track for example :- eventName, //eventLocation etc.

Note– Extra Params Key Mapping will be send by Affle Maas PlatformTeam.

Method Name : inAppTrackerViewName
For Example : –

string extraParams = “{\”key1\”:\”NCR\”, \”key2\”:\”Sector 50\”}”;

Where key1 mapped with First Name and key2 mapped with Last Name

Example for FB_LIKE on Home Screen: –
afflePlugin.inAppTrackerViewName (“home”, “home screen”, “fb_like”, extraParams);

Example for FB_SHARE on Category Detail Page with Title 4: –
afflePlugin.inAppTrackerViewName (“Category2Detail”, ” Title4″, “fb_share”, extraParams);

To track events, call the method on the place the event is triggered.

b) Purchase

To track your Purchase Events in the app, call the method “inAppEventTrackerViewName” and pass the View Name, the Detail Description (if required), Purchase Event Name, Transaction Id, Purchase Amount of Transaction, and Purchase Quantity that should be displayed on the analytics interface.

public void inAppEventTrackerViewName
string viewName, // View Name
string viewDetails, // View Details
string purchaseEventName, // Purchase Event Name
string pEventTransactionId, // Purchase transaction identifier
string pEventAmount, //Purchase amount
int pEventQuantity, // Purchase quantity
string currencyCode, // Currency code
string extraParams // Extra Params Key Mapping will be send by Affle Maas Team

Method Name : inAppEventTrackerViewName

Example for Purchase on Movie Booking Detail Page: –

string extraParams = “{\”key1\”:\”New Delhi\”, \”key2\”:\”Movie\”,\”key3\”:\”Visa\”}”;

Where Key1 mapped with Event City , key2 mapped with Event Type, key3 mapped with Card Type

Note:- Extra Params key mapping will be send by Affle MAAS Platform Team

afflePlugin.inAppEventTrackerViewName (“Movie1Title”, “Movie Description”, “Movie1Name”, “12345”, 1000, 4, “INR”, extraParams);
* Price of 1 Ticket = 250, 4 Tickets = 1000

Example for Purchase on Taxi Booking Detail Page: –
afflePlugin.inAppEventTrackerViewName (context, “TaxiCategory1”, “”, “YellowTaxi”, “abcd22344xxuz”, 1500, 1, “INR”, extraParams);
*Price of 1 Ticket = 1500

Push notification integration

Push Notification or Google Cloud Messaging for Android (GCM) is a service that allows the Application owner to send data from the server to the application users’ Android-powered device, and also to receive messages from devices on the same connection.

Enable Push Notification

Configure the AndroidManifest.xml file like below to enable push notification feature.


android:value=”true” />

Set af_PushNotification “true” for enable push Notification feature in AffletrackerSDK.

Setting Up Permissions

Replace the PACKAGE_NAME with the name of your application package.

Setting Up Receivers

Replace the PACKAGE_NAME with the name of your application package.

android:name=”com.affle.gcm.GCMBroadcastReceiver ”
<category android:name=”PACKAGE_NAME”/>

Setting up the PushService

implement/invoke own method to handle deep linking within the application.

<service android:name=”com.affle.afflepushtracker.PushService” >
android:value=”com.affle.affletrackerunity.AfflePushReceiver” />

Configure Push Notification Timer

When user open the push notification item the SDK will start a timer. During the timer running any


pevent/event generated will be sent to the server with the push_id included. You can specify how long the timer can run by configure the push notification timer in your AndroidManifest.xml
Above configuration, I specify the timer can run 120 seconds. If you not set the timer the SDK will start timer for 60 minutes by default.
If developer wants to configure timer on receiving Push Notification Message .Then Configured below mention code snippet on App’s Manifest file.

For Example:


Configure Push Sender Id


APP_PROJECT_ID is the project number provide by Google Projects Setup. Please refer to the step provided in the link to create Creating a Google API Project

Configure notification:

Extend AfflePushReceiveListener interface in your class , Register AfflePushReceiveListener by setAfflePushReceiveListener method and implement call back method onAfflePushReceive. onAfflePushReceive method is triggered when push is received in foreground as well as background . Set game object name by method setGameObjectName .

Vibrate, Sound, Icon.

By default, the SDK will use application’s icon to display on notification item. Also, sound and vibrate is enable.

For whom want to use your own icon or disable the sound or vibrate. We provide a configuration method called affleNotificationConfigurator to help. The below example will show you how to use this method.

For Example:-

public class btnScript : MonoBehaviour,AfflePushReceiveListener{
AfflePlugin afflePlugin;
// Use this for initialization
void Start () {
afflePlugin = new AfflePlugin ();
/*Configuration of push notification
* @paramiconName -Notification Icon Name from drawable
* folder of res.
* @paramisSoundEnable – Flag for enable or disable
* notification sound.
* @paramisVibrateEnable – Flag for enable or disable
* notification vibration mode.
* @paramsoundName – File Name from raw folder of res, to play
* custom sound when receiving notification.
afflePlugin.affleNotificationConfigurator (“ic_launcher”, true, true, “overthehorizon”);
/ *Set the game object name*/
afflePlugin.setGameObjectName (;
/*Register AfflePushReceiveListener */
afflePlugin.setAfflePushReceiveListener (this);
/*This method is automatically triggered when push is received in foreground/background */
public void onAfflePushReceive(string data){
if (data != null) {
//Write your stuff here

Handling enable/disable push notification dynamically use following method .


Also do the permission settings in the AndroidManifest.xml


To show that dialog you need to configure your app’s AndroidManifest.xml like below:
Add the permissions settings.

<uses-permission android:name=”android.permission.GET_TASKS” />
<uses-permission android:name=”android.permission.SYSTEM_ALERT_WINDOW” />

Application Deep-linking on mSite Banner

App Url Scheme Setting

Declares WebDeepLinkingActivity with intent filter in Manifest file,.
Note: – APP_URL_SCHEME will be provided in ProjectSetting file from Affle Maas Team.

<activity android:name=”com.affle.affletrackerunity.WebDeepLinkingActivity”>
<data android:scheme=”affle” />
<action android:name=”android.intent.action.VIEW” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.BROWSABLE” />

Handling Deep-linking in script –

Extend AffleWebDeepLinkingListener interface in your class, Register AffleWebDeepLinkingListener by setAffleWebDeepLinkingListener method and implement call back method onWebDeepLinkingReceive. onWebDeepLinkingReceive is triggered when web deep linking is received.

For Example:

public class btnScript : MonoBehaviour, AffleWebDeepLinkingListener {
AfflePlugin afflePlugin;
void Start () {
afflePlugin = new AfflePlugin ();
/*Register AffleWebDeepLinkingListener */
afflePlugin.setAffleWebDeepLinkingListener (this);
/*This method is automatically triggered when web deep linking is received */
public void onWebDeepLinkingReceive(string data){
if (data != null) {
//Write your stuff here

SDK Testing for Applications Hosted Google Playstore

1. Ensure that the App does not pre-exist on the emulator or the Android device
2. Now Load the your App on the Device or the Android Emulator via the IDE & Open it
3. Perform the following steps on the terminal:-
– Go to android-sdk/platform-tools
– Run ./adb shell
– Execute the command:

am broadcast -a -n com.affle.unitysample/com.affle.affledowloadtracker.AffleAppDownloadTracker –es “referrer” “af_tid=8a6064bd1d9d7b60eba90c82e85b5640”

** REPLACE com.affle.affletrackersdksample with Your Application’s Package Name

4. Validate from the logs printed in the DDMS of IDE by Tag “tag:Testing”.
5. You should be able to see the pings from configured Campaign ID.
6. Once you’ve reached the point in your app where the activity should be tracked, check to see if it was recorded in the Event Logs Report. The event should be attributed to the same publisher as the install unless the event uses Re-Engagement.