Push rich notifications to customers

This article provides information on how you can customize notifications that you push to your users.

📘

Wait. Are you ready for this part?

In this article, we'll show you how to integrate notifications on your app with our platform so that we can send notifications to your app's users. However, this cannot work until you have the SDK in your project and you can use it in your app. If not, then we suggest that you do those things first and then come back here to integrate notifications on your app with our platform.

It's absolutely not complicated. We promise. And, like earlier, we'll wait. No pressure. :relaxed:

Our Android SDK supports rich push notifications with contents like single image, animated carousel and non-animated carousel in addition to the basic notification content. If you could set up the SDK successfully, then we can push rich notifications to your customers who use your app without much of a problem.

Yes. It's kinda done. :smile: And, you can create notifications in the rich push studio of our platform and send notifications to your app's users. Ensure that you follow the guidelines for the images that you want add in your notifications.

If your application is targeting Android 13 users, you would need to request permission from the user for showing notifications.

The Blueshift Android SDK version 3.2.8-beta.1 and above comes with a helper method to do this. You may call this method after showing a rationale to the user for the consent.

Blueshift.requestPushNotificationPermission(context);

We also provide a feature where you could send an in-app notification to request the notification permission. To know more about this, write to us at [email protected]

Override Blueshift Android SDK's FCM

If you have an existing MessagingService that extends FirebaseMessagingService, then you can override BlueshiftMessagingService and let blueshift SDK handle the push messages from Blueshift and let your code handle the rest of the push messages.

public class YourMessagingService extends BlueshiftMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (BlueshiftUtils.isBlueshiftPushMessage(remoteMessage)) {
            super.onMessageReceived(remoteMessage);
        } else {
            /*
             * The push message does not belong to Blueshift. Please handle it here.
             */
        }
    }

    @Override
    public void onNewToken(String newToken) {
        super.onNewToken(newToken);

        /*
         * Use the new token in your app. the super.onNewToken() call is important
         * for the SDK to do the analytical part and notification rendering.
         * Make sure that it is present when you override onNewToken() method.
         */
    }
}

In addition, update the AndroidManifest.xml file:

<service
    android:name="your.package.name.YourMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

Override notification taps

Use the following methods to override the taps on notifications that our SDK receives.

📘

Note

Ensure that you trigger click and app_open at the right time so that we get the correct input for analytics.

To receive the callback when a customer taps on the notification, override the BlueshiftNotificationEventsActivity class and its processAction method.

public class NotificationClicksActivity
        extends BlueshiftNotificationEventsActivity {

    @Override
    protected void processAction(String action, Bundle extraBundle) {
        // check for actions and implement your version of the
        // click-handling here
    }
}

Register your implementation of the BlueshiftNotificationEventsActivity class inside AndroidManifest.xml:

<activity android:name=".NotificationClicksActivity">
 <intent-filter>
 <action android:name="com.blueshift.NOTIFICATION_CLICK_EVENT"/>
 </intent-filter>
</activity>

Push notification event listeners

Min SDK version 3.1.9

You can set listeners to receive callbacks when a push message is delivered/clicked. This is useful when you would like to track these events from outside the Blueshift SDKs.

The push payload will be passed in as a Map object in both the callbacks.

Blueshift.setBlueshiftPushListener(new BlueshiftPushListener() {
    @Override
    public void onPushDelivered(Map<String, Object> map) {
        Log.d(TAG, "onPushDelivered:");
    }

    @Override
    public void onPushClicked(Map<String, Object> map) {
        Log.d(TAG, "onPushClicked:");
    }
});

Schedule push notifications

The Schedule Push Notification feature provides a way to separate campaign execution and display of push notification. This feature enables the marketer to schedule push notifications to show up on the phone at a set time. For ex: The marketer can run the campaign at 5 am and have the push notification displayed at 9am.

How to use this
First, be sure to upgrade the Android app to use the latest release of the sdk(>=v1.1.3). Then, create a push notification using the custom json option in the Push Studio, associating the template with a campaign.

Payload
You'll need to add the following fields to the payload: timestamp_to_display and timestamp_to_expire_display.

timestamp_to_display: When the push message needs to be displayed, if a push message is received after this timestamp and if the push message is still valid, it will be displayed immediately.

timestamp_to_expire_display: If the push message is received later than this timestamp, it will not be displayed.

For any questions related to payload, please contact us at: [email protected]

{
  "timestamp_to_display": 1508142900, // epoch timestamp
  "timestamp_to_expire_display": 1510820700, // <optional> epoch timestamp
}