Opentracker's events engine supports tracking of Android native app events.
This is done by including the Opentracker Android net folder in your app and following the instructions below.
Opentracker's events engine includes functions and listeners so you can easily insert your custom events into our tracking/ logging engine.
1 | Signup or add your app to an existing account (receive signup email). | |
2 |
Download the android client zip file and unzip. You should now have a folder called Opentracker-android-xxx Or browse the code On Github and see if you like it |
|
3 |
Open your project in Eclipse, and add the the 'net' folder (located in the 'src' directory) into your project's source in order to include the tracking library. This will add 3 folders ( A pretty good article on how to use Eclipse with Android can be found here |
|
4 |
Add the following import statement to your main Activity object:
import net.opentracker.android.*; |
|
5 |
In your onCreate method add the following code (example)
// Return the Context of the Activity to access its resources appContext = this.getApplicationContext(); // Initiate opentracker's logging service, with the Context and your-registered-app-name OTLogService.onCreate(appContext, "your-registered-app-name"); // Record an event with the title "Activity started", but you can call it anything you want OTLogService.sendEvent("Activity started"); More information on |
|
6 |
In your onPause method add the following code (example)
// Close the session and upload the events.. // The onPause method is guaranteed to be called in the life cycle of an Android App. OTLogService.onPause(); |
|
7 |
Add the following to your application's manifest AndroidManifest.xml (example)
<!-- http://developer.android.com/reference/android/Manifest.permission.html --> <!-- Allows an application to open network sockets. --> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <!-- Allows an application to access fine (e.g., GPS) location --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <!-- Allows an applications to access information about networks: needed for methods OTDataSockets.getNetworkType() and OTDataSockets.getNetwork(); --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /></uses-permission> <!-- Allows an applications to access information about Wi-Fi networks --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /></uses-permission> |
|
8 |
Add your events (as many as you like, anywhere you see fit, just like logging).
// Record an event with the title "My event", but you can call it anything you want. OTLogService.sendEvent("My event");
In order to avoid collecting too much data, do not call this function in a loop.
|
To use OTLogService to its full potential, you can add key/ value pairs to mark an event.
For example if you have an event going to an advertisement use the following
We recommend adding a title key/ value pair. If there is no title defined, the title will default to '[no title]'
// Example of sending a multi-dimensional event HashMap myEvent = new HashMap(); myEvent.put("title", "HP ad tapped"); myEvent.put("ad link", "http://www.hp.com/external/link.html"); myEvent.put("value", "$20"); myEvent.put("source", "Overview screen"); OTLogService.sendEvent(myEvent);
Opentracker's events engine includes counting functionality with segmentation within the API calls.
The following example will add a shopping cart event:
// Example of sending a custom event HashMap map = new HashMap(); map.put("item", "Panasonic Lumix DMC-TZ30"); map.put("brand!", "Panasonic"); map.put("price", "257"); map.put("item-type", "camera[+257]"); OTLogService.sendEvent("Checkout complete", map);
A full example of an android eclipse project can be checked out at Github
In certain cases you might want to override some values for certain properties. See below for instructions on how to do so.
You can override the default browser or App name by submitting the 'browser' variable. You can also specify a version.
For Apps, not providing a browser variable will default to "unknown" and "version" will be specified as per version attributes in the <manifest> element of the manifest file.
example
myEvent.put("browser", "My cool app"); myEvent.put("browserVersion", "1.5.2");
Visible in: