MobileAppTracking Android SDK
MobileAppTracking Android SDK
1
SDK Integration Guide
Version 2.4.1 | July 2013
Table of Contents
Introduction......................................................................................................................3 Compatibility....................................................................................................................3 Downloading the Android SDK.......................................................................................3 Implementation...............................................................................................................4 Installs and Updates........................................................................................................9 Track Install..................................................................................................................9 Handling Installs Prior to SDK Implementation.......................................................9 Sample Install Code...................................................................................................10 Events..............................................................................................................................10 Registration................................................................................................................11 Purchases....................................................................................................................11 Opens...........................................................................................................................12 Other Events...............................................................................................................13 Testing SDK......................................................................................................................13 Debug Mode and Duplicates.........................................................................................14 Reading Platform Responses....................................................................................15 Version History...............................................................................................................16 v2.4.1 changes............................................................................................................16 v2.4 changes...............................................................................................................16 v2.3 changes...............................................................................................................16 v2.2 changes...............................................................................................................16 v2.1 changes...............................................................................................................16 Additional Resources.....................................................................................................16 Custom SDK Settings.................................................................................................16 Event Items.................................................................................................................17 App to App Tracking...................................................................................................17 Track Referrer Application (Re-Engagement).........................................................17 Configure as Shared Instance...................................................................................17 Track Events in WebView..........................................................................................17 Unique Identifiers for Attribution...........................................................................18 Methodologies for Attributing Installs...................................................................18
Introduction
The MobileAppTracking (MAT) SDK for Google Android provides basic application install and event tracking functionality. The Android SDK is provided in the form of a single java JAR file that you simply include in your Android project. Our SDK is compatible with all devices running Android 2.1 and above . To track installs, you must first integrate the Android SDK with your Android app. You may also add and track additional events beyond an app install (such as purchases, game levels, and any other user engagement). This document outlines the MAT Android SDK integration and use cases.
Compatibility
The current version of the Android SDK is compatible with Android 2.1 and above.
Once youve downloaded the Android SDK, decompress the zip file and extract the files to your development computer. The Android SDK is provided as a single java JAR file.
Implementation
1. Configure the AndroidManifest.xml. The Android SDK requires setting up a MobileAppTracker receiver in your Android manifest. Once you have set up the MAT receiver, you will need to place it inside your application tags. 2. Install Referral (required) in your manifest file. Doing so gives the SDK access to the install referrer value from Google Play. Learn how the Google Play Install Referrer works and can be used for attribution.
If your app has multiple receivers for INSTALL_REFERRER, you will need to write a custom receiver that will call these receivers instead. Learn how to setup multiple Android install referrers. 3. Before closing the manifest tag, add the following permissions in as the SDK uses them. a. Internet Permission (Required): Internet permission is required to connect to tracking servers.
b. Offline Tracking Permission (Required): These permissions enable the SDK to queue tracking events while the user is not connected to the Internet. Once the user is online, the SDK will process all queued events.
c. Wifi State Permission (Optional): These permissions enable the SDK to access information about whether you are connected to a Wi-Fi network and obtain the device's MAC address. If not used, initialize MobileAppTracker with "collectMacAddres" set to false.
Allows the user's device ID to be recorded. If not used, initialize MobleAppTracker with "collectDeviceId" set to false.
4. Add MobileAppTracker.jar to your Android project's build path. If you are using Eclipse, right click on your project folder:
import com.mobileapptracker.*;
6. You'll then need to instantiate the "MobileAppTracker" class to allow you to call the functions from the Android SDK. Choosing where to instantiate a new class is a decision that is unique to your application/code design. Generally, the code is placed inside your main activity's "onCreate(Bundle)" method.
public class MyClass extends Activity { public MobileAppTracker mobileAppTracker = null; @Override public void onCreate(Bundle savedInstanceState) { mobileAppTracker = new MobileAppTracker( this, "your_advertiser_id", "your_key"); } //... }
The your_advertiser_id and the your_key values correlate to the Advertiser Id and Conversion Key provided to you when you created the Mobile App (Step 3 in Create Mobile App) in platform. See screenshots below for reference.
These values may also be found on the Tracking Code for XXXApp page by clicking on the Download SDK button and clicking on the appropriate mobile app. See screenshots below for reference.
7. You are now ready to call the functions to track installs and other events. IMPORTANT: Always call trackInstall or trackUpdate if the user is either installing the app for the first time or updating their app after a previous install.
Track Install
The trackInstall method is used to track when users install your mobile app on their device and will only record one conversion per install in reports. You should call trackInstall() in the main activitys onCreate method after instantiating a MobileAppTracker class.
mobileAppTracker.trackInstall();
The trackInstall method automatically tracks updates of your app if the app version differs from the last app version it saw.
If the code used to differentiate installs versus app updates is not properly implemented, then you will notice a spike of total installs on the first day of the SDK implementation.
The sample install code below also includes debugging. For more details on how debugging works, please refer to Debug Mode and Duplicates.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Instantiate MAT object with your advertiser ID and key mobileAppTracker = new MobileAppTracker(this, "your_advertiser_id", "your_advertiser_key"); // Enable these options for debugging only if (DEBUG) { mobileAppTracker.setAllowDuplicates(true); mobileAppTracker.setDebugMode(true); } // Track install on app open mobileAppTracker.trackInstall(); }
Events
After the install has been tracked, the trackAction method is intended to be used to track user actions such as reaching a certain level in a game or making an in-app purchase. The trackAction method allows you to define the event name dynamically.
10
All of the following events can be called after instantiating the MobileAppTracker: mobileAppTracker = new MobileAppTracker(this, "your_advertiser_id", "your_advertiser_key"); mobileAppTracker.setEventReferrer(getCallingPackage());
Registration
If you have a registration process, its recommended to track it by calling trackAction set to registration.
mobileAppTracker.trackAction("registration");
You can find these events in the platform by viewing Reports > Event Logs. Then filter the report by the registration event. While our platform always blocks the tracking of duplicate installs, by deafult it does not block duplicate event requests. However, a registration event may be an event that you only want tracked once per device/user. Please see block duplicate requests setting for events for further information.
Purchases
The best way to analyze the value of your publishers and marketing campaigns is to track revenue from in-app purchases. By tracking in-app purchases for a user, the data can be correlated back to the install and analyzed on a cohort basis to determine revenue per install and lifetime value. Track In-App Purchases The basic way to track purchases is to track an event with a name of purchase and then define the revenue (sale amount) and currency code.
11
Here is an example of tracking an event for purchase with revenue and currency code.
mobileAppTracker.trackAction("purchase",1.99, 'USD");
Pass the revenue in as a Double and the currency of the amount if necessary. Currency is set to "USD" by default. See Setting Currency Code for currencies we support. You can find these events in the platform by viewing Reports > Event Logs. Then filter the report by the purchase event. Purchases with Googles Billing system The SDK also allows you to track purchase events that occur inside your app by tieing in your events to Google Plays In-App Billing system. To do so, implement a Service that is bound to Googles billing system via their instructions. Learn more about tracking purchase events with Google Plays In-App Billing system here.
Opens
The SDK allows you to analyze user engagement by tracking unique opens. The SDK has built in functionality to only track one open event per user on any given day to minimize footprint. All subsequent open events fired on the same day are ignored and will not show up on the platform. To track an open event you need to override the onStart() inside your main activity. You must pass in open as the parameter in the trackAction call:
12
Some app ads will open your app if already installed on the device. We recommend sending the app package name that caused the open as the field for the setEventReferrer method. If your app was called from an Intent with startActivityForResult from another app, calling getCallingPackage() from your context will return the package name of the app that started it. You can find counts of Opens by viewing Reports > Mobile Apps. Include the parameter of Opens to see the aggregated count. The platform does not provide logs of Opens. If you track Opens using a name other than "open" then these tracked events will cost the same price as all other events to track.
Other Events
You can track other events in your app dynamically by calling trackAction. The trackAction method is intended for tracking any user actions. This method allows you to define the event name. To dynamically track an event, replace Event Name with the name of the event you want to track. The tracking engine will then look up the event by the name. If an event with the defined name doesnt exist, the tracking engine will automatically create an event for you with that name. An Event Name has to be alphanumeric.
mobileAppTracker.trackAction("Event Name");
You can find these events in platform by viewing Reports > Event Logs. The max event limit per site is 100. Learn more about the max limit of events. While our platform always blocks the tracking of duplicate installs, by deafult it does not block duplicate event requests. However, there may be other types of events that you only want tracked once per device/user. Please see block duplicate requests setting for events for further information.
Testing SDK
The SDK is designed to track conversions through the Google Play Store as well as from outside marketplaces like the Amazon App Store or third parties. This allows you to test it without updating your production app listing. Subsequently, you will be able to update your mobile app for Google Play after testing that tracking is fully operational - saving you time and resources.
13
Learn how to test the Android SDK integration here. After you are done testing, you should review the Android SDK Support Checklist before submitting your app with the SDK.
mobileAppTracker.setDebugMode(true);
Allow Duplicates The platform rejects installs from devices it has seen before. For testing purposes, you may want to bypass this behavior and fire multiple installs from the same testing device. There are two methods you can employ to do so: (1) calling the "setAllowDuplicates" method, and (2) set up a test profile. (1) Call the setAllowDuplicates after initializing MobileAppTracker, with Boolean true:
mobileAppTracker.setAllowDuplicates(true);
(2) Set up a test profile. A Test Profile should be used when you want to allow duplicate installs
and/or events from a device you are using from testing and don't want to implement setAllowDuplicateRequests in the code and instead allow duplicate requests from the platform.
***The setDebugMode and setAllowDuplicates calls are meant for use only during debugging and testing. Its required to disable these for production builds. ***
14
public class MyMATResponse implements MATResponse { @Override public void didSucceedWithData(JSONObject data) { Log.d("my tag here", data.toString()); } }
Instantiate an instance of this class and set it with the MobileAppTracker "setMATResponse" method:
Now when a platform request completes, the code in your custom MATResponse "didSucceedWithData" method will be run - outputting to LogCat in this example.
15
Version History
v2.4.1 changes
Add setAppAdTracking setter for app-level ad opt-out
v2.4 changes
Better exception handling and added more informative debug output Improve offline event queue synchronization
v2.3 changes
Add age, gender, latitude, longitude, altitude setters Add MATEventItem class for trackAction use
v2.2 changes
Separate debug and allow duplicates settings Add MATResponse interface for reading platform responses Show alert dialog warning if debug mode is on Add event_referrer setter for app that caused open
v2.1 changes
Add server response to debug log output Make revenue input a Double Add site_id setter Add "trackPurchase" method for store purchase events
Additional Resources
Custom SDK Settings
The SDK supports several custom identifiers that you can use as alternate means to identify your installs or events. Please navigate to the Custom SDK Settings page.
16
Event Items
While an event is like your receipt for a purchase, the event items are the individual items you purchased. Event items allow you to define multiple items per a single event. The trackAction method can include this event item data. Learn how to track event items.
17
18