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:

AffleTracker_Android_UnityPlugin_6.1.0

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.

<application>
//Other Settings

<meta-data
android:name=”af_DebugMode”
android:value=”true” />
</application>

* 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.

<application>
//Other Settings

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

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”>
<intent-filter>
<action android:name=”com.android.vending.INSTALL_REFERRER” />
</intent-filter>

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

<application>
//Other Settings

<meta-data
android:name=”af_cid”
android:value=”@integer/Affle_CAMPAIGN_ID”/>
</application>

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

<application
//Other Settings

<meta-data
android:name=”af_SessionTimeOut”
android:value=”3600″/>
</application>

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.

<uses-permissionandroid:name=”android.permission.GET_ACCOUNTS”/>
<uses-permissionandroid:name=”android.permission.WAKE_LOCK”/>
<permission
android:name=”PACKAGE_NAME.permission.C2D_MESSAGE”
android:protectionLevel=”signature”/>
<uses-permission
android:name=”PACKAGE_NAME.permission.C2D_MESSAGE”/>
<uses-permission
android:name=”com.google.android.c2dm.permission.RECEIVE”/>

<meta-data
android:name=”af_PushNotification”
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.

<receiver
android:name=”com.affle.gcm.GCMBroadcastReceiver ”
android:permission=”com.google.android.c2dm.permission.SEND”>
<intent-filter>
<actionandroid:name=”com.google.android.c2dm.intent.RECEIVE”/>
<actionandroid:name=”com.google.android.c2dm.intent.REGISTRATION”/>
<category android:name=”PACKAGE_NAME”/>
</intent-filter>
</receiver>

Setting up the PushService

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

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

Configure Push Notification Timer

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

<meta-data
android:name=”af_pnt”
android:value=”120″/>

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:

<meta-data
android:name=”af_PushReceiveEvent”
android:value=”true”/>

Configure Push Sender Id

<meta-data
android:name=”SENDER_ID”
android:value=”senderid:APP_PROJECT_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 http://developer.android.com/google/gcm/gs.html#create-proj

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 (this.gameObject.name);
/*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 .

afflePlugin.setEnablePushNotification(true);

Also do the permission settings in the AndroidManifest.xml

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

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”>
<intent-filter>
<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” />
</intent-filter>
</activity>

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 com.android.vending.INSTALL_REFERRER -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.