- Print
- DarkLight
- PDF
Adding Mobile Tracking to Android Projects
How to add permissions, import the Webtrends.xml
file, and initialize tracking:
Add the
Webtrends-android-sdk-release.x.x.aar
file to your project as a new module dependency.Add the minimum permissions to your application and ensure that an application is defined.
Edit
AndroidManifest.xml
to add the INTERNET and ACCESS_NETWORK_STATE permissions. Here's an example of the XML code with an application defined and these permissions granted:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.webtrends.helloworld"
android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloWorld" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
You may need additional permissions to suspend data collection based on battery life, to add location data to your collected statistics, or to perform other tracking tasks.
To add optional persmissions for BATTERY_STATS:
<uses-permission android:name="android.permission.BATTERY_STATS" />
Import the
Webtrends.xml
file to establish operating settings for the library and provide a unique identifier for the data that you send to Webtrends. TheWebtrends.xml
file is included in the Library.- Copy the
Webtrends.xml
file into theres/values/ directory
. This file must be edited to include your unique DCSID. The DCSID is a unique identifier assigned to your account by Webtrends for the data that you send to our collection servers. TheWebtrends.xml
file is included in the Library distribution. - Change the
wt_dc_dcsid
value to your DCSID, and change thewt_dc_timezone
value to match the time zone of the Webtrends data source, expressed as an offset from GMT. - If you want to run your application in debug mode, set
wt_dc_debug
.
wt_dc_debug
logs messages using the Log class of theandroid.util
package, so you may view them using the LogCat utility.
- Copy the
Initialize application tracking: This enables you to track application opens and exits and uncaught exceptions. Session starts and ends are managed, and the Webtrends queue is initialized to capture both online and offline events. If your application extends the Application base class, you can set it to use the
WTApplication
class instead. This allows you to streamline application-level measurement by implementing a number of Webtrends data collection methods without additional coding.NoteIf you would rather not extend your application for automatic tracking, then you must call the
WTDataCollector.setApplication()
method to initialize the Library before calling any of the event methods. Inside the main application, as the first line in theonCreate
method, add the call tosetApplication()
as follows:public class HelloWorld extends Application { @Override public void onCreate(Bundle savedInstanceState) { // programmatically configure the Library WTDataCollector.setApplication(this); ... } ... }
Open the
.java
file containing your Application implementation.Import the Webtrends package by adding this import statement:
import com.webtrends.mobile.analytics.*;
Modify the main class that extends “Application” by replacing “Application” with "WTApplication” as shown in the graphic:
(Optional) Extend the Activity: This enables you to streamline Activity-level measurement by implementing a number of Webtrends data collection methods without additional coding.
NoteIf you would rather not extend your activities for automatic tracking, and you have not already called
setApplication()
at the Application level as described in Initialize Application Tracking, add the call tosetApplication()
. Inside the main application, as the first line in theonCreate
method, enter:public class HelloWorld extends Activity { @Override public void onCreate(Bundle savedInstanceState) { // programmatically configure the Library WTDataCollector.setApplication(this); ... } ... }
Open the
.java
file containing your Activity implementation.Import the Webtrends package by adding this import statement:
import com.webtrends.mobile.analytics.*;
(Optional) Add Explicit Measurement Methods To further customize application tracking and enrich your data, you can add explicit measurement events anywhere in your application. For information about adding this instrumentation code, see "Instrumenting an Android Application."