Customizing In-App Notifications
To make in-app notifications more engaging, you might want to implement your own user experience so that your in-app messaging can blend into the look and feel of your UI.
To do so, override the following callback methods, and return false
, which ensures that Marigold SDK default interface isn't displayed. At this point you can trigger your own in-app notification interface using the Message object.
//On iOS, using Objective-C
- (BOOL)shouldPresentInAppNotificationForMessage:(MARMessage *)message {
// Do something with the message
// Register an impression *if* you are displaying the notification yourself.
[[MARMessageStream new] registerImpressionWithType:MARImpressionTypeInAppNotificationView forMessage:message];
return NO;
}
//Be sure to assign your delegate to MARMessageStream
[[MARMessageStream new] setDelegate:self]
//On iOS, using Swift
func shouldPresentInAppNotificationForMessage(message: MARMessage) -> Bool {
return false
}
//Be sure to assign your delegate to MARMessageStream
MARMessageStream().setDelegate(self)
//On Android, using Java
new MessageStream().setOnInAppNotificationDisplayListener(new
MessageStream.OnInAppNotificationDisplayListener() {
@Override
public boolean shouldPresentInAppNotification(Message message) {
return false;
}
});
//On Android, using Kotlin
MessageStream().setOnInAppNotificationDisplayListener(object : MessageStream.OnInAppNotificationDisplayListener {
override fun shouldPresentInAppNotification(message: Message?): Boolean {
return false
}
})
//On React Native
MessageStream.useDefaultInAppNotification(false);
myModuleEvt.addListener('inappnotification', (data) => {
console.log('Received message:', data);
alert(data.title);
MessageStream.notifyInAppHandled(true);
});
Not available in Unity
Due to limitations of current plugin architecture in Unity, it is not currently possible to override the stock experience for in-app notifications. Rest assured, you can still deliver these notifications, but you won't be able to customize their UX. We hope to bring customization to these platforms in the near future.
Registering an impression event
In order to support impression analytics in your custom in-app notification, you will need to ensure you register an impression event when it is shown.
//On iOS, using Objective-C
[[MARMessageStream new] registerImpressionWithType:MARImpressionTypeInAppNotificationView forMessage:message];
//On iOS, using Swift
MARMessageStream().registerImpressionWithType(MARImpressionType.InAppNotificationView, forMessage: message)
//On Android, using Java
new MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message);
//On Android, using Kotlin
MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_IN_APP_VIEW, message)
//On React Native
MessageStream.registerMessageImpression(MessageStream.MessageImpressionType.InAppView, messages);
Updated about 1 month ago