Android SDK integration guideline

1. Embedding the SDK into Your Application (Mandatory)

The following steps are mandatory to measure installs and sessions. You can integrate the Unliche SDK automatically using Gradle’s Dependency Management.

1.1 Add the Unliche SDK to your Project

The simplest way to integrate the SDK into your project is by using Gradle’s Dependency. Adding Unliche’s Android SDK Dependency:

  1. Open your project (or create a new project), and then open your_app -> build.gradle


  1. Add this to Module-level /app/build.gradle before dependencies:
repositories {
        mavenCentral()
}
  1. Add the compile dependency with the latest version of the Unliche SDK in the build.gradle file:
dependencies {
        compile 'com.rappier.unlichesdk:UnlicheSDK:version_code+@aar'
}

version_code is latest version

1.2 Set the Required Permissions

  • The AndroidManifest.xml should include the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  • ACCESS_WIFI_STATE and READ_PHONE_STATE permissions are optional.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Adding this permission enables the carrier to track IMEI.

1.3 Request permissions for Android version marshmallow and above

If your app needs permissions that were listed in the app manifest, it must ask the user to grant the permission. In our case, must ask permission of READ_PHONE_STATE. to integrate permission refer this

Note

If you don’t provide this permission, then this leads to be data inconsistency in backend.

1.4 Set an Install Referrer Broadcastreceiver in AndroidManifest.xml

receiver: Unliche SDK provides a solution that broadcasts INSTALL_REFERRER to all other receivers automatically. In the AndroidManifest.xml, add the following receiver as the FIRST receiver for INSTALL_REFERRER, and ensure the receiver tag is within the application tag:

<receiver android:name="com.rappier.unlichesdk.unlichelib.mainsdkclasses.TrackerEventReceiver" android:exported="true">
        <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
</receiver>

1.5 Embed Google Play Services into Your App

Collecting the Google Advertising ID (GAID) is essential for tracking campaigns across several channels including Facebook, Google and Twitter. To add Google Advertising ID:

Install the Google Play Services SDK and import it into your project. Add the following entry to the AndroidManifest.xml as the last entry under application (before </application>):

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

OR add following in build.gradle to avoid multidex exception:

dependencies {
        compile 'com.google.android.gms:play-services-ads:google_play_services_version'
}

Note

  • Unliche uses the Google Play Services library for retrieving the Google Advertising ID.
  • Google Play Services 7.5 is the minimum requirement for the GCM Registration Token (which is used for our Uninstall measurement). Unliche recommends to always use the latest version.

2. SDK Initialization and Installation Event (Minimum Requirement for Tracking)

Note

This is the minimum requirement to begin tracking your app installs.

2.1 Initializing the SDK

To initialize the SDK, add the following code to your Application’s onCreate function:

Unliche.initEvent(Context context, String AccessToken);
  • context - use getApplicationContext()
  • AccessToken - is token used to otherize advertiser.

Note

AccessToken will get while register on portal of Unliche for tracking. If not already register then click here to register.

This API enables Unliche to detect installations, sessions, and updates.

2.2 Reporting Background Sessions

If your app is a utility app running in the background you can use the API as described in here to measure sessions and retention within Unliche.

3. In-App Events Tracking API (Optional)

There are two types of optional events contains in Unliche sdk, 1) Sdk defined 2) Custom events

3.1 Unliche Sdk Defined Events

This API enables Unliche to track some in app events that are already defined in sdk. App just need to call the methods of event and use it with specific events.

Events:

3.1.1 Register

If app contain registration/signup event this event will useful to track whether installed app made registration complete or not

Syntax:

Unliche.setRegisterEvent(Context context);
  • context - use getApplicationContext()

3.1.2 Purchase

If app contain purchase event, this event will useful to track purchase

Syntax:

Unliche.setPurchaseEvent(Context context, int PurchaseAmount, String Currency, String PaymentGetway);
  • context - use getApplicationContext()
  • PurchaseAmount - amount of purchase.
  • Currency - currency of purchase amount.
  • PaymentGetway - payment getway name(Optional).

3.1.3 Open

For user retention you have to include this event

Syntax:

Unliche.setOpenEvent(Context context);
  • context - use getApplicationContext()

3.2 Custom events(Advertiser defined events)

This API enables Unliche to track post install events. These events are defined by the advertiser and include an event name, in addition to optional event values. Tracking in-app events helps you measure and analyze how loyal users discover your app, and attribute them to specific campaigns/media sources.

Syntax:

Unliche.setCustomEvent(Context context, String customEventId);
  • context - use getApplicationContext().
  • customEventId - event id generated while create custom event in Unliche system

4. Optional fields to provide

There are some optional parameter you can provide.

4.1 User ID

Syntax:

Unliche.setUserId(String userId);

4.2 User name

Syntax:

Unliche.setUserName(username);

4.3 User phone number

Syntax:

Unliche.setPhoneNumber(String phoneNumber);

5. Uninstalls

To detect uninstalls you have to integrate GCM/FCM in your app. Register app to GCM with project number and provide GCM token to below function.

To integrate GCM/FCM in app click here

Syntax:

Unliche.setUninstallEvent(Context context, String GCMToken);
  • context - use getApplicationContext().
  • GCMToken - is token provided by GCM/FCM to client.