Reporting APIs for custom notification statistics (4.x)

Updated at:

This topic describes how to report notification click and deletion events when your application uses passthrough messages to create its own notifications.

Note

This topic applies to Mobile Push Android SDK 4.x. The APIs and examples are based on version 4.0.0. If your application uses SDK 3.x, see the corresponding 3.x API documentation.

Use cases

If your application creates a custom notification or dialog from a passthrough message received in the onMessage(Context, CPushMessage) method, you must call the following APIs to report when a user clicks or deletes that content. Statistics for notifications created and handled by the SDK are reported automatically.

Note

Both APIs accept the original CPushMessage object from the onMessage callback. Retain this object, including its messageId and traceInfo fields, and pass it to your click or deletion handling logic.

Initialize the push service by calling PushServiceFactory.init in the application process that performs the reporting. In the following examples, originalMessage is the original CPushMessage object from the onMessage callback. Call the relevant example method from your custom notification's click or deletion handler.

Click event (clickMessage)

Call this API when a user clicks your custom notification or its corresponding dialog. Report this event only once per message. The API returns void and has no callback.

API definition

void clickMessage(CPushMessage message);

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

message

CPushMessage

Yes

The original message object received in the onMessage callback. This parameter cannot be null, and its messageId must not be empty. Preserve the messageId and traceInfo from this object for reporting.

Return value and callback

The method returns void and has no callback. This API call submits the click event, but it does not confirm whether the server received or stored the data for statistics.

Code example

public void reportCustomNotificationClick(CPushMessage originalMessage) {
    if (originalMessage == null || originalMessage.getMessageId() == null
            || originalMessage.getMessageId().isEmpty()) {
        return;
    }
    PushServiceFactory.getCloudPushService().clickMessage(originalMessage);
}
fun reportCustomNotificationClick(originalMessage: CPushMessage?) {
    if (originalMessage?.messageId.isNullOrEmpty()) return
    PushServiceFactory.getCloudPushService().clickMessage(originalMessage)
}

Dismissal event (dismissMessage)

Call this API from your custom notification's deletion handler when a user dismisses it. Report this event only once per message.

API definition

void dismissMessage(CPushMessage message);

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

message

CPushMessage

Yes

The original message object received in the onMessage callback. This parameter cannot be null, and its messageId must not be empty. Preserve the messageId and traceInfo from this object for reporting.

Return value and callback

The method returns void and has no callback. This API call submits the dismissal event, but it does not confirm whether the server received or stored the data for statistics.

Code example

public void reportCustomNotificationDismiss(CPushMessage originalMessage) {
    if (originalMessage == null || originalMessage.getMessageId() == null
            || originalMessage.getMessageId().isEmpty()) {
        return;
    }
    PushServiceFactory.getCloudPushService().dismissMessage(originalMessage);
}
fun reportCustomNotificationDismiss(originalMessage: CPushMessage?) {
    if (originalMessage?.messageId.isNullOrEmpty()) return
    PushServiceFactory.getCloudPushService().dismissMessage(originalMessage)
}

Message object and validation

CPushMessage implements Parcelable, allowing it to be passed between Android components. This is crucial for handling notification clicks after the system kills your application process, as you must be able to restore the original message and its statistical identifiers. Additionally, sanitize any message data before writing it to a log.

Method

Description

getMessageId()

The message identifier. You must preserve this for reporting.

getTraceInfo()

The statistical tracking information from the SDK. This information must be preserved and passed with the original message for reporting.

getAppId()

The application identifier associated with the message.

getTitle()

The message title. You can use this value to construct the content for your custom notification.

getContent()

The message content. You can use this value to construct the content for your custom notification.

Test the complete flow, from receiving the passthrough message to displaying the custom notification and handling click and deletion events. Afterward, check the statistics on the server to verify successful reporting.

Related documents

For integration instructions, see Integrate Android SDK (4.x).

For applications that use SDK 3.x, see Reporting APIs for Custom Notification Statistics (3.x).