Android SDK

northDASH ingests native Android App events using the opensource Mixapanel Android SDK – https://github.com/mixpanel/mixpanel-android.



Step 1 – Add the mixpanel-android library as a gradle dependency:

dependencies {
    implementation 'com.mixpanel.android:mixpanel-android:5.+'
}


Step 2 – Add permissions to your AndroidManifest.xml:

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

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

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



Initializing the Library

Initialize the code by calling MixpanelAPI.getInstance. You can add this code to your onCreate method.

public static final String NORTHDASH_TOKEN = "YOUR_TOKEN";

// Set the events endpoint
final MPConfig mpConfig = MPConfig.getInstance(this);
mpConfig.setEventsEndpoint("http://www.iknowlogy.net/jssdk/track");

// Initialize the library with your
// northDASH integration token, NORTHDASH_TOKEN, and a reference
// to your application context.
MixpanelAPI mixpanel =
     MixpanelAPI.getInstance(context, NORTHDASH_TOKEN);


Flushing Events

The SDK keeps a queue of events that are sent in batches to preserve bandwidth and battery life. Add this to flush events for when the app closes.

@Override
 protected void onDestroy() {
     mixpanel.flush();
     super.onDestroy();
 }


Sending Events

Once the code is initialized you can send events like this:

JSONObject props = new JSONObject();
 props.put("Gender", "Female");
 props.put("Plan", "Premium");

mixpanel.track("Plan Selected", props);
Did you find this helpful?10