1. Home
  2. Integrations
  3. Android Unity Integration

Android Unity Integration

Install the SDK

 mTraction  Android Unity SDK

Note: Please refer to the Android SDK Change log for details about the changes/upgrades on the latest SDK version from previous versions.

The mTracktion SDK should contain the following files:

mTractionPlugin.unitypackage: This is the SDK library that has to be integrated in the application.

The step-by-step integration process has been described in detail in the coming sections. Please note any developer attempting to integrate the SDK must have sound knowledge of Android Studio development suite by Google.

  1. Basic SDK Setup
  2. Download Conversion Tracking
  3. App Session Tracking (Optional)
  4. In App Events Integration (Optional)
  5. Application Push Notification Tracking

1.Basic SDK Setup

Import file “mTractionPlugin.unitypackage” into unity.

Note : Minimum Unity Version required is Unity 5.4.X versions.

Add the corresponding mTractionPlugin.unitypackage right-click your project Assets folder, click Import Package, Click on Custom Package, browse to the location of the mTractionPlugin.unitypackage, and then click on open and in last click on Import. shown in the following screenshots step by step.

  1. Now click on Custom Package.
  2. Click on Open
  3. Click on Import
  4. MTraction namespace must be included in the sample script to use the plugin related functionality. For example :using MTraction;
  5. Call Track Download at start function in your sample class. For example :
    void Start(){
     MTractionTracker.TrackDownload ();
     }

    Note : Your sample script must be attached to the gameobject.

  6. Go to File and click on Build Settings
    • Switch the platform to Android.
    • For Unity Versions 5.4.X and below, plz Check Google Android Project option in Build Settings.
    • For Unity Versions 5.5.X and above Check Build System to Gradle(New) and check on Export Project in Build Settings.
    • Click on Export.
  7. It will ask to save android project build now select the path and save the android project build.
  8. Once build is succeeded, android project will be made and it will open below window.
  9. Start Android Studio and import the upper exported project from unity. And save the imported project in different path.It will be converted to Android Studio Project.

Open the AndroidManifest.xml file in your project and change the following :


  1. Change the activity name to the following ::
    < activity android:name="com.unity3d.player.UnityPlayerActivity"/>

     

  2. Open the AndroidManifest.xml file in your project and add the following:

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

    This is to grant permission to access Internet and Network State.

    Optionally, you can also grant Phone State access (as shown below) for our SDK to receive device IMEI & Network Operator related information of your App Users.  

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

     

  3. To enable “DEBUG” logs, the following setting should be enabled inside the application tag.
    <application>
    // Other Settings
    <meta-data
    android:name=” mt_DebugMode ”
    android:value=”true” />
    </application>

    Note : Disable mt_DebugMode when app is going to live.

  4. Add google-play-services_lib, gson, appcompat dependency project into your project Properties.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>

     

     

2. Download Conversion Tracking

We have provided two different methods to handle download conversions, both single and multiple. Use multiple if you plan to use other methods for download conversion tracking. Choose one of the methods below:

  • Single Install Tracking SDK:
    1. Copy the MTractionSingleInstallReceiver.java file to your applications main Package folder. Change the Package Name at the top of the file, to the package name of the main project.
    2. Open the AndroidManifest.xml file in your project and add the following Receiver settings.

      <receiver android:name=”.MTractionSingleInstallReceiver” android:exported=”true”>
      <intent-filter>
      <action android:name=”com.android.vending.INSTALL_REFERRER” />
      </intent-filter>
      </receiver>

       

    3. Do the following settings in the AndroidManifest.xml under the Application section. The App_Token is provided to you as a part of the Application Registration process on the mTraction Platform.

      <application>
      // mTraction App Token
      <meta-data
      android:name=”appToken”
      android:value=”App_Token”/>
      </application>

       

At this point in time, you can validate your install tracking with our mTraction Testing Application. Please refer to this documentation and follow the steps as mentioned: mTraction Android SDK Testing

  • Multiple Installs Tracking SDK:
    1. If your Android app has multiple receivers for INSTALL_REFERRER, you will need to write a custom receiver that will call these receivers.We recommend to use MTractionMultipleInstallReceivers.java class included in SDK suite. Alternatively, you can create your custom class as per the below sample code:
      package com.test.sample; //Application Package Name
      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import com.mtraction.mtractiondownloadtracker.MTractionDownloadTracker;
      
      public class MTractionMultipleInstallReceivers extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
       
          // Call MTractionDownloadTracker\
          MTractionDownloadTracker mTractionDownloadTracker = new MTractionDownloadTracker();
          mTractionDownloadTracker.onReceive(context, intent);
      
          // Initialize and call onReceive for other receivers
      
      }
      }
    2. Then place the receiver in your AndroidManifest.xml file like shown below:

      <receiver android:name=”.MTractionMultipleInstallReceivers” android: exported=”true”>
      <intent-filter>
      <action android:name=”com.android.vending.INSTALL_REFERRER” />
      </intent-filter>
      </receiver>

       

      Note: Make sure that you change the receiver name to the one as you created above.

At this point in time you can validate your install tracking with our mTraction Testing Applciation. Please refer to this documentation and follow the steps as mentioned: mTraction Android SDK Testing

3. App Session Tracking (Optional)

Note: App Session implementation is optional for your Application. However, for Active Sessions and Session duration related data – this needs to be configured in your Application. Also note that this can generate a lot of traffic and hence cost if the request is large.

We have provided two different solutions, Standard Solution & Alternate Solution to handle Session tracking in your Application based on the supported Android versions. Use the alternate solution if your Application supports Android versions 4.0 or below (i.e, Ice Cream Sandwich – API Level 14 or below). Choose one of the solutions below:

  • The Standard Solution is supported by most of the applications and works in a manner that lets the SDK listen to and track the various state changes that happens inside the Application (For example: App moving to foreground/background). Please follow the below steps:
    1. If you don’t have a custom Application class, create one and specify the name in your AndroidManifest.xml as follows.

      <application
      android:name=".MyApplication">

       

    2. Make the following modifications to your Application class.
      • Import the MTractionActivityLifecycleCallbacks package.
        import com.mtraction.mtractioninapptracker.MTractionActivityLifecycleCallbacks;
      • Register MTractionActivityLifecycleCallbacks.
        @Override
        
        public void onCreate()
        {
         super.onCreate();
         registerActivityLifecycleCallbacks(
                  new MTractionActivityLifecycleCallbacks(this));
        }
  • The Alternate Solution is built in such a way that it tries to achieve the same result as the standard solution through initializing the SDK. In every Activity of your app, override onResume() and onPause() to manage the sessions as below:
    • In onResume, call onActivityResumed.
      MTractionInAppTracker.onActivityResumed(context);
    • In onPause, call onActivityPaused.
      MTractionInAppTracker.onActivityPaused(context);

4. In App Events (Optional)


  • At this stage, you might be interested in implementing certain In App events that needs to be tracked in order to measure your Application’s User Engagement after being installed. We have provided a list of generic events that you may need to implement depending on its necessity to your Application. Please follow the documentation (with examples) to implement them on your Application: Generic In App Events Setup
  • We have also provided sets of predefined In App events along with their respective keys setup (with example usage) based on the Industry or Vertical your Application is associated with. Please refer to the link to the various Vertical based Events integration guides: Vertical Specific Events Setup Guides
  • Additionally, you can implement custom events to track specific behavior on your application. Please follow the documentation (with example): Custom Events Setup Guide

5. Application Push Notification Tracking

  • Configure Push Notification:
    1. Register MTractionPushReceiverListener by setMTractionPushReceiveListener
    2. f
    3. Enable push notification feature for your application.
      <meta-data android:name=”mt_PushNotification” android:value=”true” />
       
      
    4. Permission Setting in Manifest.xml file
      <uses-permission android:name=”android.permission.GET_ACCOUNTS”/>
      <uses-permission android: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”/>
      <uses-permission android:name=”android.permission.VIBRATE”/>
      <uses-permission android:name=”android.permission.GET_TASKS” />Note: To set up your permissions, Replace "YOUR_PACKAGE_NAME" with your own app's package name.

      Note: To set up your permissions, Replace “YOUR_PACKAGE_NAME” with your own app’s package name.

    5. Open the AndroidManifest.xml file in your project and add the following Receiver settings.
      <receiver android:name=”com.mtraction.gcm.GCMBroadcastReceiver ”
      android:permission=”com.google.android.c2dm.permission.SEND”>
      <intent-filter>
      <action android:name=”com.google.android.c2dm.intent.RECEIVE”/>
      <action android:name=”com.google.android.c2dm.intent.REGISTRATION”/>
      <category android:name=”PACKAGE_NAME”/>
      </intent-filter>
      </receiver>Note: To set up your permissions, Replace "YOUR_PACKAGE_NAME" with your own app's package name.

      Note:To set up your permissions, Replace “YOUR_PACKAGE_NAME” with your own app’s package name. .

    6. Setting up push service
      <service android:name=”com.mtraction.mtractionpushtracker.PushService”>
      <meta-data android:name=”callback_receiver”android:value=”.MTractionPushReceiver”/>
      </service>

      Note: Implement/invoke own method to handle deep linking within the application.

    7. Configure Push Sender ID
      < meta-data android:name=”MTRACTION_SENDER_ID” android:value=”senderid:APP_PROJECT_ID”/>
      

      Note:  APP_PROJECT_ID is the project number provide by Google console Projects Setup . 

    8. Set Push Notification Timer (Optional)
      <meta-data android:name=”mt_pnt”android:value=”120″/>
    9. When user open the push notification item, SDK starts a timer (with specified timer value in mt_pnt key) and will send push_Id along with the tracked event to the server (this process is to track triggered events through push notification and it’s usage). On Above configuration example,timer value is -120 seconds which can be modified as per the application requirement, it’s default value is 3600 seconds.
       

 

 

 

 

Articles

Was this article helpful to you? Yes No

How can we help?