awesome_notifications_braze

Awesome Notifications

Flutter Discord

Open Source Love pub package Full tests workflow codecov badge

Braze pushes shown by awesome_notifications, on Android and iOS.

Keep the official braze_plugin for everything Braze offers: users, attributes, in-app messages, content cards, analytics. This package only changes how Braze's pushes are displayed. Each one becomes a notification of the core, with its channels, layouts, images, buttons and events, also while the app is terminated. Both plugins see what the user does with it:

  • the core's onActionReceived, onNotificationCreated, onNotificationDisplayed, onDismissActionReceived and getInitialNotificationAction;
  • braze_plugin's push events, Braze's deep links and Braze's push analytics (received, opened, button clicks).

Key Features:

  • Every Braze campaign, the core's look: the title, body, image, buttons, accent color, badge and key-value pairs a campaign sets in the Braze dashboard are mapped to the core's notification.
  • Awesome payloads from Braze: key-value pairs carrying awesome sections (content, actionButtons, schedule, localizations…) take priority, as in an FCM push. Any layout of the core can come from a Braze campaign.
  • All app states: on Android through the Braze SDK's notification factory (no Flutter engine needed); on iOS through your app's Notification Service Extension.
  • Both plugins keep their events: the core's events and listeners, and Braze's analytics, push events and deep links, for the same notification.

πŸ“¦ The awesome_notifications family

Every package of the family, and where each one runs:

Package Push Android iOS macOS Windows Linux Web
awesome_notifications (the core) πŸ”— βœ… βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_schedules πŸ”— βœ… βœ… βœ… πŸ§ͺ πŸ§ͺ ❌
awesome_notifications_localizations πŸ”— βœ… βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_fcm βœ… βœ… βœ… βœ… ❌ ❌ πŸ§ͺ
awesome_notifications_wns βœ… ❌ ❌ ❌ πŸ§ͺ ❌ ❌
awesome_notifications_unifiedpush βœ… πŸ§ͺ ❌ ❌ ❌ πŸ§ͺ ❌
awesome_notifications_onesignal βœ… πŸ§ͺ πŸ§ͺ ❌ ❌ ❌ ❌
awesome_notifications_braze (this package) πŸ§ͺ πŸ§ͺ πŸ§ͺ ❌ ❌ ❌ ❌
awesome_notifications_airship βœ… πŸ§ͺ πŸ§ͺ ❌ ❌ ❌ ❌
awesome_notifications_chat πŸ”— βœ… βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_media ❌ βœ… βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_calls πŸ”— βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_live_activities πŸ”— βœ… βœ… πŸ§ͺ πŸ§ͺ πŸ§ͺ πŸ§ͺ
awesome_notifications_foreground_service ❌ βœ… ❌ ❌ ❌ ❌ ❌

βœ… supported Β· πŸ”— works with push Β· πŸ§ͺ preview (implemented, still being validated) Β· ⏳ planned Β· ❌ not available on this platform


πŸš€ Getting started

dependencies:
  awesome_notifications: ^1.0.0-dev.10
  awesome_notifications_braze: ^1.0.0-dev.10
  braze_plugin: ^24.0.0

Set up braze_plugin as its own documentation says (API key, endpoint, Firebase on Android), then initialize the core, then this package:

import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:awesome_notifications_braze/awesome_notifications_braze.dart';
import 'package:braze_plugin/braze_plugin.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 1. The core, with the channel of your Braze pushes.
  await AwesomeNotifications().initialize(null, [
    NotificationChannel(
      channelKey: 'braze',
      channelName: 'Braze campaigns',
      channelDescription: 'Notifications sent by Braze',
      importance: NotificationImportance.High,
    ),
  ]);
  await AwesomeNotifications().setListeners(
    onActionReceivedMethod: onActionReceived, // taps on Braze pushes too
  );

  // 2. This package, after the core: pushes without a channel use 'braze'.
  await AwesomeNotificationsBraze().initialize(defaultChannelKey: 'braze');

  // 3. braze_plugin, as before: its push events keep working.
  final braze = BrazePlugin(
    pushEventHandler: (event) => print('Braze: ${event.payloadType}'),
  );
  braze.initialize('<your API key>', '<your SDK endpoint>');

  runApp(const MyApp());
}

@pragma('vm:entry-point')
Future<void> onActionReceived(ReceivedAction action) async {
  if (AwesomeNotificationsBraze.isBrazeNotification(action)) {
    // A Braze campaign: its key-value pairs are in action.payload,
    // with 'cid' (the campaign) and 'uri' (its deep link).
  }
}
  • defaultChannelKey is kept natively: pushes received while the app is terminated use it. Create the channel with AwesomeNotifications().initialize before.
  • Ask the user's permission with the core (AwesomeNotifications().requestPermissionToSendNotifications()).
  • AwesomeNotificationsBraze.isPlatformSupported is false on the other platforms, where initialize answers false.

πŸ€– Android setup

  1. Set up Firebase Cloud Messaging for Braze as braze_plugin documents it: your project's google-services.json, the com.google.gms.google-services Gradle plugin and, in res/values/braze.xml:
    <bool translatable="false" name="com_braze_firebase_cloud_messaging_registration_enabled">true</bool>
    <string translatable="false" name="com_braze_firebase_cloud_messaging_sender_id">YOUR_SENDER_ID</string>
    
  2. Nothing else. This package declares Braze's Firebase messaging service (com.braze.push.BrazeFirebaseMessagingService) and installs its notification factory as the app process starts, so it also works while the app is terminated. The app's minSdk must be 24 or higher.

If your app sets its own Braze.customBrazeNotificationFactory, it replaces this package's: remove it. This package sets its factory only when none is set.


🍎 iOS setup

1. The Notification Service Extension (required)

The pushes are rebuilt by a Notification Service Extension. Without it, iOS shows them by itself and the core sees none of them. Follow the extension guide of awesome_notifications_fcm (the target, the App Group in both targets, mutable-content), with this package in place of the FCM one:

  • Swift Package Manager: add the local package ios/Flutter/ephemeral/Packages/.packages/awesome_notifications_braze and its product AwesomeNotificationsBrazeExtension to the extension's target.
  • CocoaPods: add the extension's target to ios/Podfile (Runner needs the IosAwnCore line of the core's iOS setup), then run pod install:
    target 'NotificationService' do
      use_frameworks!
      pod 'IosAwnCore', :path => '.symlinks/plugins/awesome_notifications/ios'
      pod 'AwesomeNotificationsBrazeExtension', :path => '.symlinks/plugins/awesome_notifications_braze/ios'
    end
    

The extension's NotificationService.swift:

import AwesomeNotificationsBrazeExtension

class NotificationService: AwesomeBrazeServiceExtension {}

This extension replaces Braze's BrazeNotificationService: one extension handles each push. Braze's rich-media image (JPEG, PNG, GIF, HEIC, WebP) becomes the core's big picture.

Turn on Mutable content in your Braze iOS push campaigns (the extension runs only for pushes with "mutable-content": 1).

2. The app delegate

Give this package the Braze instance braze_plugin creates, and turn Braze's push automation off (this package does what it would: the token, the received and opened pushes):

import BrazeKit
import awesome_notifications_braze
import braze_plugin

BrazePlugin.configure(
  { configuration in
    configuration.push.automation = false
  },
  postInitialization: { braze in
    AwesomeNotificationsBrazePlugin.attach(braze)
  }
)

Add the Push Notifications capability and Background Modes β†’ Remote notifications to Runner. The example app has everything set up (example/ios).


πŸ—ΊοΈ How a Braze push is mapped

The Braze fields are mapped first. Then the awesome sections found in the campaign's key-value pairs are merged over them (whole JSON strings such as content, or dot-flattened keys such as content.title); Android / iOS sections override them on their platform.

The notification keeps the push's original keys: on iOS in its userInfo, on Android in its extras and in the intent that opens the app.

Android

Braze (FCM data key) Core
title (t), body (a), summary (s) title, body, summary
image (ab_iu, or the legacy appboy_image_url key-value pair) bigPicture, BigPicture layout (else BigText, as Braze)
large icon (ab_li), accent color (ac), badge (ab_bc) largeIcon, color, badge
notification id (n) id (else a hash of the title and body, as Braze)
duration (nd, ms) timeoutAfter (seconds)
visibility (ab_vs: -1, 0, 1) privacy (Secret, Private, Public)
channel (ab_nc) channelKey, when that channel exists in the core
buttons (ab_a0_t…, up to 3) actionButtons: the key is the Braze button id; a "close" button (ab_none) is a SilentAction
key-value pairs (extra) payload
campaign (cid), deep link (uri), ab_use_webview, button fields kept in payload (to report the actions to Braze)
β€” payload['_ab'] = 'true' (see isBrazeNotification)

The channel is the first that exists of: the awesome content.channelKey, the campaign's channel (ab_nc), defaultChannelKey, the first channel of the core. With none, Braze shows the push itself.

Braze's push stories (ab_c) and conversational pushes (ab_cp) are still shown by Braze.

iOS

Braze (APNs payload) Core
aps.alert (title, body, or a text) title, body
aps.badge badge
rich media image (ab.att) bigPicture, BigPicture layout
category ab_cat_accept_decline, ab_cat_yes_no, ab_cat_confirm_cancel, ab_cat_more actionButtons keyed ab_pb_accept, ab_pb_decline… (the negative one is a SilentAction)
key-value pairs (top-level keys), deep link (ab_uri) payload
β€” payload['_ab'] = 'true'
the whole push (ab, aps…) kept in the notification, so Braze recognizes it when it is opened

The id is a hash of the push's identifier. The channel is the awesome content.channelKey, else defaultChannelKey (when it exists). With none, the push is shown as it arrived. Push stories (ab_cat_push_story_v2) are shown as they arrived (Braze's content extension draws them). Videos and audio aren't attached.

An awesome payload from Braze

Add key-value pairs to the campaign, for example:

Key Value
content {"channelKey":"promos","layout":"BigPicture","bigPicture":"https://example.com/sale.jpg","wakeUpScreen":true}
actionButtons [{"key":"SHOP","label":"Shop now"},{"key":"LATER","label":"Later","actionType":"SilentAction"}]

or flattened keys (content.channelKey = promos, actionButtons.0.key = SHOP…). The title and body of the campaign are kept unless content sets them.


πŸ‘† Taps, buttons and Braze analytics

Both plugins receive what the user does. When only one of them can answer, the core does: the tap opens the app as the core's notification does, and the core answers iOS's completion handlers.

Action Core Braze
Push shown onNotificationCreated, onNotificationDisplayed Android: delivery and campaign received logged, push received event. iOS: Braze sees the pushes presented while the app is in the foreground.
Tap onActionReceived, getInitialNotificationAction push opened (analytics, braze_plugin's push_opened event, the deep link when Braze handles them)
Button onActionReceived with buttonKeyPressed Android: button click logged, its deep link. iOS: Braze's response handling for its category buttons.
Swipe away onDismissActionReceived Android: push deleted event

Android: each intent of the notification (tap, Braze buttons, swipe) first does what the core's would, then hands Braze's own intent to the Braze SDK, as Braze's notification would. It works in every app state.

iOS: this package's notification-center delegate stands in front of the core's: Braze gets handleForegroundNotification and handleUserNotification for its pushes, then the core gets the same callbacks. A tap that launches the app before Braze starts is handed to Braze when attach is called.

What Braze doesn't get

  • Braze's presentation choice (iOS): the core decides how a push is presented in the foreground, and answers iOS's completion handlers. Braze gets the callbacks with completion handlers of its own, which iOS ignores.
  • The tap's own intent (Android): the core's intent opens the app first; Braze's deep link (when com_braze_handle_push_deep_links_automatically is on) opens after it, on top. Braze's trampoline activity isn't used.
  • Pushes the core doesn't show: when the core can't show a push (notifications disabled, the channel off), Braze doesn't show it either and no received event or delivery is logged for it.
  • Initialize order (iOS): call AwesomeNotificationsBraze().initialize after AwesomeNotifications().initialize. If the core is initialized again later, it takes the delegate back: taps still reach Braze (the core forwards them), but button clicks don't.
  • received event (iOS): braze_plugin reports only push_opened events on iOS (its own behavior).

Manual test checklist

Send a Braze campaign with a title, a body, an image, two buttons, a deep link and a key-value pair, to Android and iOS. For each app state (foreground, background, terminated):

  • The notification is the core's (its channel, image, buttons); onNotificationCreated and onNotificationDisplayed fire, with the key-value pair and _ab in the payload (terminated: when the app opens).
  • Tap: onActionReceived fires (terminated: also getInitialNotificationAction); braze_plugin's push_opened event arrives; Braze's dashboard counts the open; the deep link opens.
  • Button: onActionReceived with the button key; Braze counts the click (Android).
  • Swipe away: onDismissActionReceived fires.
  • Foreground on iOS: the push is presented as the core's channel says.
  • Android: Braze's dashboard counts the push's delivery.

πŸ” Idempotency

  • Android: the Braze SDK drops a push it already received (its push id) before this package sees it. A push with the same notification id (n, or the same title and body) replaces the one on screen.
  • iOS: iOS shows every push the extension receives. A push redelivered with the same identifier replaces the one on screen (same id).
  • Set content.id in the key-value pairs to replace a notification on purpose.

⚠️ Not with awesome_notifications_fcm or firebase_messaging

On Android, this package declares Braze's Firebase messaging service, and Android delivers each push to only one Firebase messaging service. Use this package or awesome_notifications_fcm, not both, and not with firebase_messaging. If you also need your own FCM pushes, send them through Braze, or route them in one service of your own.


πŸ”€ Migrating from braze_plugin alone

  • Dart: keep your braze_plugin code. Add the core's initialize and listeners, then AwesomeNotificationsBraze().initialize(defaultChannelKey: …).
  • Android: remove your declaration of BrazeFirebaseMessagingService (or of your own messaging service forwarding to Braze) and any customBrazeNotificationFactory. Keep braze.xml.
  • iOS: set configuration.push.automation = false; remove your own push code from the app delegate (register(deviceToken:), handleUserNotification, notification-center delegate); call AwesomeNotificationsBrazePlugin.attach(braze) in postInitialization; replace BrazeNotificationService with AwesomeBrazeServiceExtension.
  • Channels: Braze's Android notification channels aren't used; your pushes use the core's channels.

πŸ“± Platform support

Feature Android iOS
Braze pushes shown by the core πŸ§ͺ πŸ§ͺ (Notification Service Extension)
App terminated πŸ§ͺ πŸ§ͺ
Braze fields mapped (title, body, image, buttons…) πŸ§ͺ πŸ§ͺ
Awesome payload in key-value pairs πŸ§ͺ πŸ§ͺ
Core events (created, displayed, action, dismissed, initial action) πŸ§ͺ πŸ§ͺ
Braze open and button analytics, push events, deep links πŸ§ͺ πŸ§ͺ
Braze delivery analytics πŸ§ͺ ❌
Push stories, conversational pushes ❌ (shown by Braze) ❌ (shown as received)

βœ… supported Β· πŸ§ͺ preview (implemented, still being validated) Β· ⏳ planned Β· ❌ not available on this platform


πŸ”§ How it works

Layer Role
Dart initialize (the default channel, kept natively) and isBrazeNotification.
Android A content provider installs Braze.customBrazeNotificationFactory as the process starts. For each push, the factory builds the core's model and shows it through the core's native engine, then returns no notification to Braze, which then logs nothing twice. A decorator of the core's builder adds Braze's own intents after the core's to each notification.
iOS extension AwesomeBrazeServiceExtension (Flutter-free) registers a model provider: each Braze push is built by the core, keeping the push's keys.
iOS app The token, the background pushes, and a notification-center delegate in front of the core's: Braze gets its callbacks, the core answers them.

πŸ”— See also

Libraries

awesome_notifications_braze
Braze pushes built and shown by awesome_notifications, on Android and iOS.