1. Home
  2. Integrations
  3. Android PhoneGap Integration

Android PhoneGap Integration

Welcome to the mTraction Android PhoneGap SDK Integration Section. Our SDK provides developers the flexibility to choose and integrate one or more components based on their requirements.

Install the SDK

Download the latest Android Phonegap SDK

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

Phonegap SDK  should contain the following files:

  1. MTractionSDK.jar : This is the SDK library for integration in the application.
  2. MTractionSingleInstallReceiver.java : This file is provided to extend/implement the base class of the MTractionDownloadTracker.java
  3. MTractionMultipleInstallReceivers.java: This file is provided to listen more than one receiver at a time.
  4. MTractionPushReceiver.java
  5. MTractionApplication.java
  6. MTractionSDKTracker.java
  7. mTractionData.js
  8. mTractionTracker.js

The step-by-step integration process has been described in detail in the coming sections.

  1. Basic Integration Settings
  2. Installs Tracking
  3. App Session Tracking (Optional)
  4. In App Events Integration (Optional)
  5. CRM Integration – Android SDK

1. Basic Integration Settings


  1. Add the MTractionSDK.jar to your project’s lib folder as shown in the image below.
  2.  Add the MTractionSDKTracker.java, MTractionApplication.java,MTractionSingleInstallReceiver.java to your project’s src/”application package name” folder as shown in the image below.
  3.  Followed by adding the www/js/mTractionData.js,mTractionTracker.js, to your project’s assets/www/js folder as shown in image.
  4. Followed by adding the feature tag to your project’s res/xml/config.xml file as shown in image.

    <feature name="MTractionSDKTracker">
       <param name="android-package" value="package name.MTractionSDKTracker" />
    </feature>

    Followed by adding the script tag to your project’s www/index.html file.

    <script type="text/javascript" src="js/mTractionData.js"></script>
    <script type="text/javascript" src="js/mTractionTracker.js"></script>
    
    
    
    

2. Installs Tracking


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

 

  • 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>
// Other Settings
<meta-data
android:name=”appToken”
android:value=”App_Token”/>
</application>

 

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.

5. CRM Integration – Android SDK


  • Configure Push Notification:Call getNotificationData() method in your index.html/js. This method register the callback functionality for getting “Push Notification” data(when app is in background).Note: We recommend to call getNotificationData() method in onDeviceReady() method in index.html/js.Example: Call getNotificationData() method for getting notification data.
    <script type=”text/javascript”>
    function onDeviceReady() {
    MTractionSDKTracker.getNotificationData();
    <script>

    Setting up the Push Notification Handlers

              Application State : In-Active/Background   

    •  When a push notification is received while the application is not in the foreground, it is displayed in the Android Notification Bar.
    •  When we click on push notification massage ,and notification data can be handled by onPushNotificationBackgroundCallBack() method in the mtractiontracker.js file.Application State : Active/Foreground
    • If the notification is received while the app is active, it is up to the app to handle it. To do so, the call came into onPushNotificationForegroundCallBack() method in the mtractiontracker.js file. Also developer can set custom/own message box in this method.Custom Configuration setting for Push Notification:
      trackMTractionNotificationConfigurator
      :function(soundFileName,iconName,isEnableSound,isVibrateEnable,callBackFlag)
    • Mandatory parameters (Login):
      • Sound File Name -Unique sound file name.
      • Icon Name – Unique icon name
      • Callback Flag – True/False
    • Optional parameters (Login):
      • Sound Enable – True/False
      • Vibration Enable – True/False
  • Enable Push Notification:
    1. Copy the MTractionPushReceiver.java file to your application main Package folder. Change the Package Name at the top of the file, to the package name of the main project. .
    2. Enable push notification feature for your application.
      <meta-data android:name=”mt_PushNotification” android:value=”true” />
       
      
    3. 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.

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

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

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

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

  • Sample Code

    <script>
    function trackCustomNotification(){
    mtractiontracker.trackMTractionNotificationConfigurator("soundFileName","iconName",”sound,vibration”,”callback”);
    }
    </script>

Articles

Was this article helpful to you? Yes No

How can we help?