Setup with FCM (v1.1.8.fcm or older)

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

  1. Add Firebase to your App
  2. Get the Blueshift Android SDK
  3. Update AndroidManifest file
  4. Initialize the Blueshift SDK
  5. Setting user info
  6. Proguard Rules

Blueshift 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.

 

1. From jCenter

Update your build.gradle file with any one of the following two code snippets to get the SDK from jCenter.

// #1

dependencies {
    // BlueShift SDK
    compile('com.blueshift:android-sdk:1.1.0') { transitive = true }
}
// #2

dependencies {
    // for Android Advertising Id
    compile 'com.google.android.gms:play-services-ads:10.2.0'
    // for FCM Messaging
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    // for JSON parsing
    compile 'com.google.code.gson:gson:2.6.1'
    // for annotations used (ex @NotNull)
    compile 'org.jetbrains:annotations:13.0'

    // BlueShift SDK
    compile 'com.blueshift:android-sdk:1.1.0'
}
 

2. Using .AAR file

  1. Download the latest version of blueshift-android-sdk file from here
  2. Add it into your /libs folder.
  3. Modify your build.gradle file to contain following code.
repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    // for Android Advertising Id
    compile 'com.google.android.gms:play-services-ads:10.2.0'
    // for FCM Messaging
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    // for JSON parsing
    compile 'com.google.code.gson:gson:2.6.1'
    // for annotations used (ex @NotNull)
    compile 'org.jetbrains:annotations:13.0'

    // BlueShift SDK
    compile(name: 'blueshift-android-sdk-1.1.0', ext: 'aar')
}
 

3. Add as module

The sdk can be integrated into your application using simple steps.

  1. Clone this project into your machine
  2. Add this project as a library module

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 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Add the following block inside <application> tag to enable deep-linking from notification clicks.

<receiver android:name="com.blueshift.rich_push.RichPushActionReceiver">
    <!-- Important: Replace 'com.blueshift.sampleapp' with your app's package name -->
    <intent-filter>
        <action android:name="com.blueshift.sampleapp.ACTION_VIEW" />
        <action android:name="com.blueshift.sampleapp.ACTION_BUY" />
        <action android:name="com.blueshift.sampleapp.ACTION_OPEN_CART" />
        <action android:name="com.blueshift.sampleapp.ACTION_OPEN_OFFER_PAGE" />
        <action android:name="com.blueshift.sampleapp.ACTION_OPEN_APP" />

        <category android:name="com.blueshift.sampleapp" />
    </intent-filter>
</receiver>

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

// == 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);             

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

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