mParticle Android

Integrate Branch

  • Configure Branch

  • Install Branch

    • Import the Branch SDK to your build.gradle

      apply plugin: ''
      android {
          compileSdkVersion 25
          buildToolsVersion "25.0.2"
          defaultConfig {
              applicationId "com.eneff.branchandroid"
              minSdkVersion 15
              targetSdkVersion 25
              versionCode 1
              versionName "1.0"
              testInstrumentationRunner ""
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
          androidTestCompile('', {
              exclude group: '', module: 'support-annotations'
          compile ''
          compile ''
          compile 'com.mparticle:android-core:4.+'
          compile 'com.mparticle:android-branch-kit:4+'
  • Enable Branch on mParticle

    • Retrieve your Branch Key on the App Settings page of the Branch dashboard.
    • From your mParticle dashboard navigate to the Services page. (The paper airplane icon on the left side)
    • Scroll down to the Branch tile, or enter Branch in the search bar.
    • Click on the Branch tile and then select "Activate a Platform".
    • Click on the Android icon, then toggle the status ON.
    • Enter your Branch key in the marked field and click "Save".
  • Configure app

    • Add Branch to your AndroidManifest.xml

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android=""
          <uses-permission android:name="android.permission.INTERNET" />
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                  <!-- Branch URI Scheme -->
                      <data android:scheme="branchandroid" />
                      <action android:name="android.intent.action.VIEW" />
                      <category android:name="android.intent.category.DEFAULT" />
                      <category android:name="android.intent.category.BROWSABLE" />
                  <!-- Branch App Links (optional) -->
                  <intent-filter android:autoVerify="true">
                      <action android:name="android.intent.action.VIEW" />
                      <category android:name="android.intent.category.DEFAULT" />
                      <category android:name="android.intent.category.BROWSABLE" />
                      <data android:scheme="https" android:host="" />
    • Replace the following with values from your Branch Dashboard

      • branchandroid
  • Open the Activity for which you registered the Intent Filter in the previous section, and hook into the onStart lifecycle method by adding this override:

    public void onStart() {
      MParticle.getInstance().checkForDeepLink(new DeepLinkListener() {
        public void onResult(DeepLinkResult result) {
          // Check for the existence of a given key in the link data and route accordingly.
          try {
            if ((result.getParameters().has("my_custom_key")) && (result.getParameters().get("my_custom_key").equals("custom value"))) {
              // Send user to intended path
          } catch (JSONException e) {
        public void onError(DeepLinkError error) {
          // If an error occurred, it will be surfaced via a DeepLinkError.
          Log.d("my log tag", error.toString());
  • Initialize Branch

    As with any kit, mParticle will automatically handle initializing Branch sessions. At this point you should start seeing your Branch session data - including installs, re-opens, and any custom events - in your Branch dashboard.

    • Create a deep link from the Branch Dashboard

    • Delete your app from the device

    • Compile your app to your device

    • Paste deep link in Google Hangouts

    • Click on the deep link to open your app

Implement features

  • Create content reference

    BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
        // The identifier is what Branch will use to de-dupe the content across many different Universal Objects
       // The canonical URL for SEO purposes (optional)
       // This is where you define the open graph structure and how the object will appear on Facebook or in a deepview
       .setTitle("My Content Title")
       .setContentDescription("My Content Description")
       // You use this to specify whether this content can be discovered publicly - default is public
        // Here is where you can add custom keys/values to the deep link data
       .addContentMetadata("property1", "blue")
       .addContentMetadata("property2", "red");
  • LinkProperties linkProperties = new LinkProperties()
       .addControlParameter("$desktop_url", "")
       .addControlParameter("$ios_url", "");
    branchUniversalObject.generateShortUrl(this, linkProperties, new     BranchLinkCreateListener() {
        public void onLinkCreate(String url, BranchError error) {
           if (error == null) {
               Log.i("MyApp", "got my Branch link to share: " + url);
  • ShareSheetStyle shareSheetStyle = new ShareSheetStyle(MainActivity.this, "Check this out!", "This stuff is awesome: ")
        .setCopyUrlStyle(getResources().getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to clipboard")
        .setMoreOptionStyle(getResources().getDrawable(android.R.drawable.ic_menu_search), "Show more")
        .setSharingTitle("Share With");
                                           new Branch.BranchLinkShareListener() {
        public void onShareLinkDialogLaunched() {
        public void onShareLinkDialogDismissed() {
        public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
        public void onChannelSelected(String channelName) {
  • Display content

  • Track content

  • Track users

    Branch branch = Branch.getInstance(getApplicationContext());
    branch.setIdentity(your user id); // your user id should not exceed 127 characters
  • Track events

    Branch branch = Branch.getInstance(getApplicationContext());
    Branch branch = Branch.getInstance(getApplicationContext());
    branch.userCompletedAction("your_custom_event", (JSONObject)appState); // same 63 characters max limit
  • Track commerce

  • Handle referrals

Troubleshoot issues

  • Recommendations

  • Simulate an install

  • Sample app

  • Android instant app