Overview

Optimise Android SDK is an advance tracking tool which helps in tracking app installation, registration and sales (in-app purchase). Please read the following steps carefully to integrate SDK in your app.

optimise-android-sdk-overview

Download the Android tracking SDK 2.1.2

Assumptions & Prerequisites

1. You are familiar with using Android Studio as a development environment.

2. You will need to enable Google Play Services in your project.

Adding SDK to your Application

The following steps helps you to integrate the SDK in your application.

Add optimisesdk.aar as a module in the project structure

add_optimise_sdk_aar

Click on import .JAR/.AAR and click Next

import_aar

Select Optimise SDK path and click finish

selec_sdk_path

Select Module Dependency under Project Structure

select_dependency_module

Select optimisesdk module and click OK

select_optimiseSDKModule and click ok

Mandatory permissions to add in Manifest file

Add the following permissions to your Manifest:

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

Adding a receiver to the Manifest file

// Omg Install track Receiver

<receiver
     android:name="com.optimise.sdk.activities.OptimiseReferrerReceiver"
     android:exported="true" >
     <intent-filter>
          <action android:name="com.android.vending.INSTALL_REFERRER" />
     </intent-filter>
  </receiver>

If you need to add multiple referrer receivers, then create your own receiver as follows:

public class MyInstallReferrer extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent)
new OptimiseReferrerReceiver().onReceive(context, intent);
new com.google.android.gms.analytics.CampaignTrackingReceiver().onReceive(context, intent);
// Create instance of all Referrer receivers which you have added in your application and call it’s    //onReceive() method as shown above.
}

Add your receiver in Manifest file

<receiver
    android:name="com.example.testing.MyInstallReferrer"
    android:exported="true" >
    <intent-filter>
       <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

Add Receiver and meta-data tags in manifest

// The meta-data to be added for google play servies
<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />

// Omg Install track Receiver
<receiver android:name="com.optimise.sdk.activities.OptimiseReferrerReceiver"
          android:exported="true" >
    <intent-filter>
          <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

Add Google play services to your app

Google play services are required for Optimise Tracking SDK to retrieve the Google Advertising ID. Add the latest Play Services SDK in your application. Click here to integrate Play Services in your application.

Add the following metadata tag in your application tag of your Manifest file:

// The meta-data to be added for google play servies

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

Initializing Optimise Tracking SDK and Method Calls

Setting up Global Parameters (Mandatory)

Set the SDK’s Global Parameters. These parameters need only be set once, in the onCreate method of the application.

OptimiseAppTracker.APPLICATION_KEY = “Application key”;
OptimiseAppTracker.MID             = MID;
Parameter Type Required? Description
Application Key String Yes The unique key provided by Optimise.
MID int Yes The merchant Id provided by Optimise.

Please contact your account manager from Optimise to get Application key, MID and PID values.

Call track Install method of SDK

Add the following method in the onStart() method of your launcher activity:

new Thread(new Runnable() {
@Override
public void <run() {
    try{
        AdvertisingIdClient.Info adInfo = null;
        String googleAdvertisingId = null;
        adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
        googleAdvertisingId = adInfo.getId(); 
        //Call trackInstall method 
        OptimiseAppTracker.getInstance().trackInstall(APPID, PID, EX1, EX2, EX3, EX4, EX5, googleAdvertisingId, deeplink, Context);
      }catch(IOException Io){ 
           Io.printStackTrace(); 
      }catch(GooglePlayServicesRepairableException Gpre){ 
           Gpre.printStackTrace(); 
      }catch(GooglePlayServicesNotAvailableException Gpne){ 
           Gpne.printStackTrace(); 
      }catch(IllegalStateException Ie){
           Ie.printStackTrace(); 
      } } }).start();

Parameter description:

Parameter Type Required? Description
APPID String Optional A unique transaction reference such as an order number. For track install please set this as blank or null.
PID int Yes The product id (pid) provided by optimise.
EX1-EX5 String Optional Extended Data, Pass any additional variable you would like to capture or pass Ex1 = “Install” in trackInstall method.
GoogleAdvertisingID String Yes Google Advertising Id of device required.
Deeplink String Optional Set “YES” if  deferred deep linking is required else set it as “NO”. For Deferred deep link developer needs to add URL schemes in application.
Context Context Yes Activity’s context, like MainActivity.this

Call trackEvent method of SDK

Call our trackEvent method For tracking sales (in-app purchase) and registration. Follow below steps to use this method:-

1. For tracking sales call this method on successful transaction of product.

2. For tracking user registration call this method just after the user is successfully registered in app. For example call this after mobile number verification or after user login in app.

OptimiseAppTracker.getInstance().trackEvent(APPID, PID, EX1, EX2, EX3, EX4, EX5, Status, Currency, Context);

Parameter description:

Parameter Type Required? Description
APPID String Optional Pass a unique transaction reference such as an order number in case of tracking sale. In case of tracking registration you can pass empty or null in this.
PID int Yes The ProductID (PID) provided by Optimise.
EX1-EX5 String Optional Extended Data. Pass any additional variable you would like to capture or pass Ex1 = “Sale” in case of tracking sale.Pass Ex1 = “Registration” in case of tracking user registration.
Status String Optional To validate a transaction pass the order value here. e.g. if order value (product price) is 100 pass 100 in it or if it is 89.9 than pass 89.9 in it.
Currency String Yes 3 digit ISO standard value currency e.g. INR, GBP
Context Context Yes Activity’s context, like MainActivity.this

Location based tracking (Optional)

If you require a location based install and registration tracking than this is the right option for you. For this you require the following permissions to add in your manifest file:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Get the device location and set the parameters to SDK for example:

// Get the location manager
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

// Define the criteria how to select the location provider
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setCostAllowed(false);

// Get the best provider depending on the criteria
String provider = locationManager.getBestProvider(criteria, false);

// The last known location of this provider
Location location = locationManager.getLastKnownLocation(provider);

//Following code shows how to pass the latitude and longitude parameter to SDK:

if(location != null) {
OptimiseAppTracker.getInstance().setLatitude(location.getLatitude ());
OptimiseAppTracker.getInstance().setLongitude(location.getLongitude());
}

Note:- Call trackInstall and trackEvent method mentioned above after setting Latitude and Longitude values to SDK.

Proguard entries

You need add following entries in your proguard-rules.pro file for our SDK.

-keep class com.optimise.** { *; }
-dontwarn com.optimise.**

Version change log

Version 2.1.1

  • Bug fixes.

Version 2.1

  • Merged trackEvent & trackSale method into a single trackEvent method.
  • Efficiency improvements.

Version 2.0

  • Introduced location based tracking.
  • Developer can set latitude and longitude to SDK and can track for location specific installs.