Android SDK

This document provides an overview of how to integrate, set-up and start tracking events using the Android SDK.

 ***SDK Releases***

Always check the GitHub Releases for the latest version of the SDK.


The latest version of Android SDK: v3.0.0

 

Integrating the Blueshift Android SDK to your app is pretty simple and straightforward. All you need to do is to follow the steps given below one-by-one.

Blueshift Android SDK uses FCM to deliver push messages to your app. Before starting the Blueshift Android SDK integration, you need to Add Firebase to Your App.

dependencies {
// BlueShift Android SDK
implementation 'com.blueshift:android-sdk:3.0.0'
}
To integrate the SDK manually, follow the steps given here

 

Update AndroidManifest file

Add the following permissions to your AndroidManifest.xml

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

<!-- For scheduling network operations effectively -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- For analytical purpose (optional) -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Register the following services to allow the SDK do the FCM registration and message handling.

<service android:name="com.blueshift.fcm.BlueshiftMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

To track installation referrer automatically, add the following lines inside your <application> tag.

<receiver
    android:name="com.blueshift.receiver.AppInstallReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />

        <data android:scheme="package" />
    </intent-filter>
</receiver>

 

Initialize the Blueshift SDK

To initialize the SDK, add the following code inside onCreate() of your Application file.

Configuration configuration = new Configuration();

// == Mandatory Settings ==
configuration.setAppIcon(R.mipmap.ic_launcher);
configuration.setApiKey("YOUR_BLUESHIFT_API_KEY");

// == Deeplink (Optional) ==
configuration.setProductPage(ProductActivity.class);
configuration.setCartPage(CartActivity.class);
configuration.setOfferDisplayPage(OfferDisplayActivity.class);

// == Notification (Optional) ==
configuration.setLargeIconResId(R.drawable.notification_big_icon);
configuration.setSmallIconResId(R.drawable.notification_small_icon);
int color = ContextCompat.getColor(getApplicationContext(), R.color.notification_color);
configuration.setNotificationColor(color);
configuration.setDialogTheme(R.style.dialog_theme); // for dialog type notifications

// == Notification Channel (Android O and above) ==
// Optional: if not set and not found in payload, SDK will assign a default id (bsft_channel_General).
configuration.setDefaultNotificationChannelId("app_channel_id_default");
// Optional: if not set and not found in payload, SDK will assign a default name (General).
configuration.setDefaultNotificationChannelName("app_channel_name_default");
// optional: only set if present in payload or config object
configuration.setDefaultNotificationChannelDescription("app_channel_description_default");

// == Batched Events (Optional) ==
/*
* This is the time interval used for batching events which are then sent to
* Blueshift using the bulk events api call. It defaults to 30 min if not set.
*
* It is recommended to use one of the following for API < 19 devices.
* AlarmManager.INTERVAL_FIFTEEN_MINUTES
* AlarmManager.INTERVAL_HALF_HOUR
* AlarmManager.INTERVAL_HOUR
* AlarmManager.INTERVAL_HALF_DAY
* AlarmManager.INTERVAL_DAY
*/
configuration.setBatchInterval(timeInMilliSeconds);

// == Enable In-app Messaging Feature (Optional) ==
configuration.setInAppEnabled(true);
configuration.setJavaScriptForInAppWebViewEnabled(true);

Blueshift.getInstance(this).initialize(configuration);

Learn more about the blueshift configuration class here

Learn more about Batch and Real-time events here

The UserInfo class helps sending the user related details to Blueshift. If the values are set after sign in, they will be used for building the events params for all events going forward. Here is an example of setting customer id and email after user sign in.

// sign in complete
UserInfo userInfo = UserInfo.getInstance(this);
userInfo.setRetailerCustomerId(retailerCustomerId);
userInfo.setEmail(email);
// It is important to save the instance once an updation is made on UserInfo
userInfo.save(context); 

Add the following lines to your proguard-rules.pro file to exclude the Blueshift Android SDK

-keep class com.blueshift.** { *; }
-dontwarn com.blueshift.**

That's it! You are all set to start using the sdk!

Next step is to start Tracking Events

Was this article helpful?
0 out of 0 found this helpful