Push Callback

MoEngage's Flutter plugin optionally provides a callback on push clicks.

To register for the callback, call the setPushClickCallbackHandler() on the MoEngageFlutter object in your dart code.
This API takes a method as input with whose typedef is PushClickCallbackHandler(PushCampaignData data).

Dart
import 'package:moengage_flutter/moengage_flutter.dart';
import 'package:moengage_flutter/model/push/push_campaign_data.dart';
void _onPushClick(PushCampaignData message) {
    print("_onPushClick(): Push click callback from native to flutter. Payload " +
            message.toString());
  }
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_APP_ID);
_moengagePlugin.setPushClickCallbackHandler(_onPushClick);

Make sure this callback is set as soon as the application is initialized. Preferably in the initState() of your application widget.

warning

Warning

Make sure you are calling initialize() method of the MoEngage plugin after you set up these callbacks. Refer Initialise Flutter Component for more info.

Make sure the callback is set before calling the initialize () of the MoEngage Plugin.

Payload

NotificationPayload received in the callback is an PushCampaignData instance with the following definition:

Dart
class PushCampaignData {
  Platforms platform;
  AccountMeta accountMeta;
  PushCampaign data;
}

platform - Native platform from which callback is triggered. Possible values - androidios.

data - PushCampaignData object

Dart
class PushCampaign {
  bool isDefaultAction;
  Map<String, dynamic> clickedAction;
  Map<String, dynamic> payload;
}

isDefaultAction - This key is present only for the Android Platform. It's a boolean value indicating if the user clicked on the default content or not. true if the user clicks on the default content else false.

clickedAction - Action to be performed on notification click.

Payload Structure for clickedAction Map

JSON
{
  "clickedAction": {
    "type": "navigation/customAction",
    "payload": {
      "type": "screenName/deepLink/richLanding",
      "value": "",
      "kvPair": {
        "key1": "value1",
        "key2": "value2",
        ...
      }
    }
  }
}

clickedAction.type- Type of click action. Possible values navigation and customAction. Currently, customAction is supported only on Android.
clickAction.payload - Action payload for the clicked action.
clickedAction.payload.type - Type of navigation action defined. Possible values screenName, deepLink,  and richLanding.

Currently, in the case of iOS, rich landing and deep-link URLs are processed internally by the SDK and not passed in this callback; therefore possible value in the case of iOS is only screenName.
clickAction.value - value entered for navigation action or custom payload.
clickAction.kvPair - Custom key-value pair entered on the MoEngage Platform.
payload - Complete campaign payload.

Android Payload

If the user clicks on the default content of the notification, the key-value pair and campaign payload can be found inside the payload key. If the user clicks on the action button or a push template action, the action payload would be found inside clickedAction.
You can use the isDefaultAction key to check whether the user clicked on the default content and then parse the payload accordingly.

iOS Payload

In the case of iOS, you would always receive the key-value pairs for clicked action in the clickedAction property. Refer to this link to knowing the iOS notification payload structure.

Previous

Next

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

How can we improve this article?