Skip to main content

Push Notification

Push Notifications allow you to deliver messages to your contacts even when they're not actively using your application, helping you maintain contact engagement and deliver timely information.

info

Push Notifications are powered by Firebase Cloud Messaging (FCM) and fully managed through your User.com Panel, providing a seamless way to create, target, and analyze notification campaigns.

User.com Push Notification


Displaying notification​

SDK comes with predefined methods that allow you to display default styled Push and In-App notifications. In order to build notification you must call buildNotification(); method.

FirebaseMessaging.onMessage.listen(
(message) {
if (UserComSDK.instance.isUserComMessage(message.data)) {
UserComSDK.instance.buildNotification(
context: context,
message: message,
onTap: (type, link) {
if (type == NotificationType.push) {
// Define here what to do on notification tap
// For example launchUrl and dismiss notification
}
},
);
}
},
);

ArgumentRequiredDescription
contextYesApplication build context
messageYesFirebase Remote Message
onTapYesVoid callback to handle interaction with a message

Customize notification​

SDK also allows to customize UI of notifications. Define inside pushMessageBuilder what to do with incoming data. You can save them to storage or display custom Widget.

if (UserComSDK.instance.isUserComMessage(event.data)) {
// Displaying messages in [buildNotification]
context: context,
message: event,
onTap: (type, link) {},
pushMessageBuilder: (pushMessage) {
// Custom push message builder
// You can use it to display push message in your own way
},
}

Handle interactions​

Note that when you are using builder, then onTap will have no effect and you must also implement notificationClickedEvent(); and notificationDisplayed(); methods. If Contact interacts with notification, trigger notificationClickedEvent(); method and pass it's id and notificationType.

UserComSDK.instance.notificationClickedEvent(id: 'notificationID', type: NotificationType.inApp)

In order to show notifications to contact, you must call the proper function. Note that context is required. buildNotificationOnMessageReceived(); trigger default UI of Push Notifications.

UserComSDK.instance.buildNotificationOnMessageReceived(context: context);
REMEMBER

Push Notifications are presented when your App is in background.


Next step​

Read more about Notifications usage: