Business Messaging Guide v2
Business Messaging
Version 2

Track notification events

Copy link

Sendbird Business Messaging offers comprehensive tracking capabilities for both in-app messages and push notifications, extending the application of Business Messaging including the [Sequence] functionality.

Business Messaging allows you to track viewed and clicked events for in-app messages and delivered and clicked for push notifications.


In-app notifications

Copy link

Viewed

Copy link

When a user enters a channel after a new notification message arrives, it is considered viewed. This event is crucial for tracking user engagement and interaction with messages. The methods below should be used when a message is viewed by a user.

JavaSwiftJavaScript
fun logViewed(channel: FeedChannel, visibleMessages: List<BaseMessage>) {
    val result = channel.logViewed(visibleMessages)
    if (result) {
        // Success
    } else {
        // Error
    }
}

Clicked

Copy link

Click events are critical to track to gauge user interaction with the content. A message is marked as "clicked" when a user interacts with it, such as selecting a message or tapping a link or button within a message. The methods below should be used when a message is clicked and is considered to have been clicked by a user.

JavaSwiftJavaScript
fun logClicked(channel: FeedChannel, clickedMessage: BaseMessage) {
    val result = channel.logClicked(clickedMessage)
    if (result) {
        // Success
    } else {
        // Error
    }
}

Push notifications

Copy link

For the Business Messaging to accurately track push notifications, push notifications must be correctly set up in your mobile application. Sendbird provides detailed guides for configuring push notifications on both Android and iOS.

Set up environment for Android

Copy link

To integrate push notifications with Sendbird on Android, follow the guide for setting up push notifications for Firebase Cloud Messaging (FCM). This setup includes creating a Firebase project, configuring your app with Firebase, adding Firebase configuration files to your project, and integrating FCM with the Sendbird SDK.

For a step-by-step guide, visit the Sendbird documentation: Set up push notifications for FCM.

This guide will walk you through the steps to ensure your Android application can receive and process push notifications, pivotal for tracking delivered and clicked events within your app.

Automatic Delivery Tracking with SendbirdPushHelper

Copy link

Sendbird Android Chat SDK simplifies push notification handling by providing an interface that automatically sends a Push Delivered event when an FCM push notification is received. This feature is facilitated through the SendbirdPushHelper class, which allows for easy registration and handling of FCM messages within your Android application.

By utilizing the SendbirdPushHelper, developers can streamline the process of tracking delivered notifications, as the SDK handles these events automatically, eliminating the need for manual implementation.

Register push handlers

Copy link

To leverage automatic delivery tracking, you need to register a push handler. This functionality ensures that your application receives push notifications efficiently and tracks delivery status without additional code, enhancing the overall user experience and providing valuable engagement data.

RegisterUnregister
SendbirdPushHelper.registerPushHandler(object : SendbirdPushHandler() {
    override fun onMessageReceived(context: Context, remoteMessage: RemoteMessage) {
        // This callback is called when a message is received, and you can create and display a Notification banner from it.
    }
})

Track delivered

Copy link

For Android, the SendbirdPushHelper class automatically sends push delivered status upon receiving an FCM push. There is no need for manual delivered status handling since SDK can support for multi-device push management.

fun markPushNotificationAsDelivered(message: RemoteMessage) {
    SendbirdPushHelper.markPushNotificationAsDelivered(message.data) {
        if (it == null) {
            // Success
        } else {
            // Error
        }
    }
}

Track clicked

Copy link

Similar to in-app messages, tracking when a push notification is clicked provides insights into how users interact with notifications and which messages prompt action. Call the methods below when a push notification banner is clicked

You can hand over the data of RemoteMessage received from the FCM to the Sendbird SDK.

fun markPushNotificationAsClicked(message: RemoteMessage) {
    SendbirdPushHelper.markPushNotificationAsClicked(message.data) {
        if (it == null) {
            // Success
        } else {
            // Error
        }
    }
}

Set up environment for iOS

Copy link

For iOS, setting up push notifications involves registering your app with the Apple Push Notification service (APNs), configuring your app's notification settings, and integrating these settings with the Sendbird SDK. This process ensures your iOS app is prepared to handle push notifications, allowing for effective tracking within the Business Messaging feature.

Detailed instructions can be found in the Sendbird documentation: Register push notification credentials.

This comprehensive guide provides the steps to configure your iOS application to receive push notifications from APNs and how to communicate these notifications to the Sendbird servers for tracking purposes.

Track delivered

Copy link

To mark a push notification as delivered when received, follow the instructions below:

  1. Initialize Sendbird Chat SDK.
class AppDelegate {
    // ...

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // ...
        let initParams = InitParams(applicationId: "YOUR_APP_ID")
        SendbirdChat.initialize(
            params: initParams,
            migrationStartHandler: {
                // ...
        },
            completionHandler: { error in
                // ...
                SendbirdChat.setAppGroup("YOUR_APP_GROUP")
                // ...
        })
        // ...
    }
}
  1. Set the app group in AppDelegate.

  2. Implement the necessary method in the NotificationServiceExtension.

class NotificationService: UNNotificationServiceExtension {
    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?
    
    override func didReceive(
        _ request: UNNotificationRequest, 
        withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
    ) {
        self.bestAttemptContent = (request.content.mutableCopy()
              as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            SendbirdChat.setAppGroup("YOUR_APP_ID")
            SendbirdChat.markPushNotificationAsDelivered(
                remoteNotificationPayload: bestAttemptContent.userInfo
            ) { error in
                
            }
           
            // Always call the completion handler when done.
            contentHandler(bestAttemptContent)
        }    
    }
    // ...
}

Track clicked

Copy link

Similar to in-app messages, tracking when a push notification is clicked provides insights into how users interact with notifications and which messages prompt action. Call the methods below when a push notification banner is clicked

Implement the userNotificationCenter (_:didReceive:withCompletionHandler:) method in AppDelegate. This is called when a user clicks on a push notification.

class AppDelegate {
    // ...

    public func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Swift.Void
    ) {
        let userInfo = response.notification.request.content.userInfo
        
        SendbirdChat.markPushNotificationAsClicked(remoteNotificationPayload: userInfo)
        // ...

    }

    // ...
}

If you implemented your app to receive sendbird push notifications in the foreground as well, please note the following. Sendbird SDK marks delivered when receiving push notifications from AppDelegate regardless of whether an app is in the foreground or background, so it can be delivered even if a user does not see the push banner. If the app can receive a push in the foreground but does not display it, please add a condition called markPushNotificationAsDelivered method so that it does not deliver in the foreground.