Integrate mParticle with Blueshift (Android)

This article provides information on how to integrate our SDK with mParticle's Android SDK.

If you use mParticle in your app for data collection, you can integrate our SDK alongside their SDK so that we can capture data from it and send it to our platform. Here are a couple of things that we need as a prerequisite:

  • Blueshift account
  • mParticle account with Blueshift integration enabled
  • mParticle's Android SDK integrated with your app

Integrate Blueshift's kit with mParticle's SDK

In the build.gradle file, add android-mparticle-kit as a dependency.

dependencies {
    implementation 'com.blueshift:android-mparticle-kit:0.0.6'
}

Yes, that’s it! The mParticle core SDK can now detect the blueshift-kit.

Blueshift configuration

You can customize how the blueshift-kit works. Pass the configuration object to the kit using the setBlueshiftConfig method before you initialize the mParticle SDK.

Configuration configuration = new Configuration();
// for push
configuration.setAppIcon(R.drawable.ic_stat_name);

BlueshiftKit.setBlueshiftConfig(configuration);

For more information on the Configuration object, see Get started with the SDK

Push notifications

Follow this document on mParticle's documentation to enable push notifications in the Kit.

In-app messages

To enable in-app messaging, call the following methods of our SDK:

//in-app messaging
configuration.setInAppEnabled(true);
configuration.setJavaScriptForInAppWebViewEnabled(true);

Now, you can start registering activities to receive in-app messages in it. Once done, unregister the activities to avoid memory leaks.

@Override
protected void onStart() {
    super.onStart();

    BlueshiftKit.registerForInAppMessages(this);
}

@Override
protected void onStop() {
    BlueshiftKit.unregisterForInAppMessages(this);

    super.onStop();
}

Automatically fetch in-app messages in background

You can pull in-app messages from our API in the background. To do this, call the following method of our SDK.

configuration.setInAppBackgroundFetchEnabled(true);

Manually fetch in-app messages in background

By default, the SDK attempts to pull all the pending in-app messages from our API when the apps starts. If you don't want the SDK to call the API, and you want to call the API yourself, enable the manual mode using the method below to disable the automatic background fetch.

configuration.setInAppManualTriggerEnabled(true);

If you enable the manual in-app message fetch (and disable the automatic background fetch), use the following method to call the API manually to actually fetch messages.

BlueshiftKit.fetchInAppMessages(context, new InAppApiCallback() {
    @Override
    public void onSuccess() {
        
    }

    @Override
    public void onFailure(int code, String message) {

    }
});

To display the in-app messages in manual mode, call the following method:

BlueshiftKit.displayInAppMessage(context);

Integrate Blueshift's deep links

With our latest Android SDK, you can integrate Blueshift's deep links (commonly known as Android App links) in your app. If you include a Blueshift deep link a message of a campaign and a user clicks on it, Android opens your app and takes the user to the page that is linked to it.

Prerequisites

Before you get started, there are a couple of things that we need you to do:

  • The Blueshift deep link domain should have a cname record that points to links.getblueshift.com. (This is probably done if you have configured email campaigns with us. A valid cname record looks like links.clientdomain.com that points to links.getblueshift.com. Only top-level domains and subdomains are supported at the moment. For example, either clientdomain.com or links.clientdomain.com should point to links.getblueshift.com. We do not support path on a domain such as links.clientdomain.com/repo/folder.)
  • Share the applinks.json file with us. Get in touch with your Blueshift account executive on how to do this. For more information, see Declare website associations on Android developer portal.
  • The host app should be configured to receive and handle the redirection URL obtained from the universal links received in emails or SMSes (described below).

Integration

There are two methods that you can use to integrate Blueshift's deep links.

#1. Override BlueshiftLinksActivity

Register your activity in the AndroidManifest.xml file.

<activity android:name="com.example.MyLinksActivity">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />

       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />

       <data
           android:host="links.clientdomain.com"
           android:scheme="http" />

       <data
           android:host="links.clientdomain.com"
           android:scheme="https" />
   </intent-filter>
</activity>

To handle the Blueshift deep link URLs, create an activity that extends BlueshiftLinksActivity. Then, override the getBlueshiftLinksListener() method to get a callback when a user clicks or launches the URL.

public class MyLinksActivity extends BlueshiftLinksActivity {

    @Override
    protected BlueshiftLinksListener getBlueshiftLinksListener() {
        return new BlueshiftLinksListener() {
            @Override
            public void onLinkProcessingStart() {

            }

            @Override
            public void onLinkProcessingComplete(Uri uri) {

            }

            @Override
            public void onLinkProcessingError(Exception e, Uri link) {

            }
        };
    }
}

#2. Use handleBlueshiftUniversalLinks method.
First, register your activity as the receiver of Blueshift's deep links in the AndroidManifest.xml file.

<activity android:name="com.example.MyLinksActivity">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />

       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />

       <data
           android:host="links.clientdomain.com"
           android:scheme="http" />

       <data
           android:host="links.clientdomain.com"
           android:scheme="https" />
   </intent-filter>
</activity>

Call the SDK’s handleBlueshiftUniversalLinks() with a BlueshiftLinksListener to handle the app link callbacks.

public class MyLinkActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        BlueshiftKit.handleBlueshiftUniversalLinks(this, getIntent(), new BlueshiftLinksListener() {

            @Override
            public void onLinkProcessingStart() {

            }

            @Override
            public void onLinkProcessingComplete(Uri link) {

            }

            @Override
            public void onLinkProcessingError(Exception e, Uri link) {

            }
        });
    }
}

❗️

Ensure that you replace links.clientdomain.com with the cname-record value that points to links.getblueshift.com.

Troubleshooting

Existing Android app links stopped working after we started using Blueshift's deep links.
This can happen if the assetlinks.json file is missing on both the domains. For more information, see this document.