Overview

The Android SDK enables application developers to tag their application to enable measurement and reporting in Narratiive's dashboard. 

Instructions are provided for implementing the SDK using Android Studio as well as Eclipse.

Unique Browser (Android ID)

The unique browser identifier uses the Android ID, which is fetched as follows:

// fetch android id
Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)

This is a 64-bit ID that is generated and stored when the device first boots. It is reset when the device is wiped.

Sessions and Duration

The sessions (visits) and duration are maintained by the SDK. Cookies are not required to track sessions and duration, however the methodology for calculating sessions and duration is written to mimic the cookie based metrics.

Page Impressions

A page impression is recorded by the SDK every time the getTracker() method is called. The application developer should make calls to getTracker() at  appropriate points during the application's life-cycle.

User Agent

The user agent string is fetched as follows:

// fetch user-agent string
System.getProperty("http.agent");

Debugging

In order to ensure the SDK is operating correctly, the developer should check the LOGCAT or device log for info and error messages.

SDK Initialisation

The EM SDK needs to be initialised with the following parameters, this needs to be done only once in the call to getInstance(), which returns a singleton.

----------------------------------------------------------------------------------------------------------------------------Description: Valid Android application context
Type: android.context.Context
Status: Required

Description: Valid top level domain
Type: String
Status: Required

Description: Android application name ([a-z0-9]-) e.g. "em-survey-app".  There should not be any spaces in the App Name.
Type:
String
Status: Required

Description: Content descriptor like news,  sport,  video, etc. If not required an empty string can be used as the method argument.
Type: java.lang.String
Status:  Optional

Description: SDK Key provided by Narratiive
Type: String
Status: Required

Description: Secure (https) measurement required
Type: Boolean
Status: Required
----------------------------------------------------------------------------------------------------------------------------

EM technical support work with the application developer to ensure correct setup of the SDK parameters.

Downloads

Android Developer - Android Studio

Add following jar in lib folder of Android application

  • emtracker-$LATEST.jar (latest version from above)
  • commons-codec-1.6.jar
  • android-async-http-1.4.6.jar
  • commons-httpclient-3.0.jar

In AndroidManifest.xml, under manifest

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

and under application

<receiver
   android:name="em.app.network.NetworkChangeReceiver"
   android:label="NetworkChangeReceiver">        
      <intent-filter>            
         <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>            <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>           </intent-filter>
</receiver>

(For example) In MainActivity.java, call em-tracker to record an impression.

// Import SDK
import em.app.tracker.EmTracker;

// Example parameter values are given below.
// These must be changed for each application.
// getInstance() returns the tracker singleton,
// getTracker() forces an impression to be recorded
// parameters:  Context con, String top_level_domain,
// String app_name, String content, String sdk_key,
// boolean isSecuremode
EmTracker.getInstance(<Context>,
                      "narratiive.com",
                      "em-survey-app",
                      "",
                      "01f2ff17a576",
                       false
).getTracker();

Important: Please do not reverse the TLD.  The domain labels should appear in their natural order.

Eclipse With ADT

The setup for Eclipse is similar to Android Studio. The only difference being that the developer will need to add the android-async-http JAR file provided in the downloads section above.

Did this answer your question?