Skip to content

Push notification integration

This reference article covers how to set push notifications for React Native. Integrating push notifications requires setting up each native platform separately. Follow the respective guides listed to finish the installation.

Step 1: Complete the initial setup

Prerequisites

Before you can use Expo for push notifications, you’ll need to set up the Braze Expo plugin.

Step 1.1: Update your app.json file

Next update your app.json file for Android and iOS:

  • Android: Add the enableFirebaseCloudMessaging option.
  • iOS: Add the enableBrazeIosPush option.

Step 1.2: Add your Google Sender ID

First, go to Firebase Console, open your project, then select  Settings > Project settings.

The Firebase project with the "Settings" menu open.

Select Cloud Messaging, then under Firebase Cloud Messaging API (V1), copy the Sender ID to your clipboard.

The Firebase project's "Cloud Messaging" page with the "Sender ID" highlighted.

Next, open your project’s app.json file and set your firebaseCloudMessagingSenderId property to the Sender ID in your clipboard. For example:

1
"firebaseCloudMessagingSenderId": "693679403398"

Step 1.3: Add the path to your Google Services JSON

In your project’s app.json file, add the path to your google-services.json file. This file is required when setting enableFirebaseCloudMessaging: true in your configuration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
  "expo": {
    "android": {
      "googleServicesFile": "PATH_TO_GOOGLE_SERVICES"
    },
    "plugins": [
      [
        "@braze/expo-plugin",
        {
          "androidApiKey": "YOUR-ANDROID-API-KEY",
          "iosApiKey": "YOUR-IOS-API-KEY",
          "enableBrazeIosPush": true,
          "enableFirebaseCloudMessaging": true,
          "firebaseCloudMessagingSenderId": "YOUR-FCM-SENDER-ID",
          "androidHandlePushDeepLinksAutomatically": true
        }
      ],
    ]
  }
}

Note that you will need to use these settings instead of the native setup instructions if you are depending on additional push notification libraries like Expo Notifications.

If you are not using the Braze Expo plugin, or would like to configure these settings natively instead, register for push by referring to the following steps from the Native Android push integration guide:

  1. Add Firebase to your project.
  2. Add Cloud Messaging to your dependencies.
  3. Create a service account.
  4. Generate JSON credentials.
  5. Upload your JSON credentials to Braze.

If you are not using the Braze Expo plugin, or would like to configure these settings natively instead, register for push by referring to the following steps from the Native iOS push integration guide:

Step 1.1: Request for push permissions

If you don’t plan on requesting push permissions when the app is launched, omit the requestAuthorizationWithOptions:completionHandler: call in your AppDelegate. Then, skip to Step 2. Otherwise, follow the native iOS integration guide.

Step 1.2 (Optional): Migrate your push key

If you were previously using expo-notifications to manage your push key, run expo fetch:ios:certs from your application’s root folder. This will download your push key (a .p8 file), which can then be uploaded to the Braze dashboard.

Step 2: Request push notifications permission

Use the Braze.requestPushPermission() method (available on v1.38.0 and up) to request permission for push notifications from the user on iOS and Android 13+. For Android 12 and below, this method is a no-op.

This method takes in a required parameter that specifies which permissions the SDK should request from the user on iOS. These options have no effect on Android.

1
2
3
4
5
6
7
8
const permissionOptions = {
  alert: true,
  sound: true,
  badge: true,
  provisional: false
};

Braze.requestPushPermission(permissionOptions);

Step 2.1: Listen for push notifications (optional)

You can additionally subscribe to events where Braze has detected and handled an incoming push notification. Use the listener key Braze.Events.PUSH_NOTIFICATION_EVENT.

1
2
3
4
Braze.addListener(Braze.Events.PUSH_NOTIFICATION_EVENT, data => {
  console.log(`Push Notification event of type ${data.payload_type} seen. Title ${data.title}\n and deeplink ${data.url}`);
  console.log(JSON.stringify(data, undefined, 2));
});

Push notification event fields

For a full list of push notification fields, refer to the table below:

Step 3: Enable deep linking (optional)

To enable Braze to handle deep links inside React components when a push notification is clicked, first implement the steps described in React Native Linking library, or with your solution of choice. Then, follow the additional steps below.

To learn more about what deep links are, see our FAQ article.

For Android, setting up deep links is identical to setting up deep links on native Android apps.

If you are using the Expo plugin and want Braze to handle push deep links automatically, set androidHandlePushDeepLinksAutomatically: true in your app.json.

Step 3.1: Add deep linking capabilities

For iOS, add populateInitialPayloadFromLaunchOptions to your AppDelegate’s didFinishLaunchingWithOptions method. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"BrazeProject";
  self.initialProps = @{};

  BRZConfiguration *configuration = [[BRZConfiguration alloc] initWithApiKey:apiKey endpoint:endpoint];
  configuration.triggerMinimumTimeInterval = 1;
  configuration.logger.level = BRZLoggerLevelInfo;
  Braze *braze = [BrazeReactBridge initBraze:configuration];
  AppDelegate.braze = braze;

  [self registerForPushNotifications];
  [[BrazeReactUtils sharedInstance] populateInitialPayloadFromLaunchOptions:launchOptions];

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

In addition to the base scenarios handled by React Native Linking, implement the Braze.getInitialPushPayload method to account for deep links from push notifications that open your app when it isn’t running. For example:

1
2
3
4
5
6
7
8
9
// Handles deep links when an iOS app is launched from a hard close via push click.
// This edge case is not handled in the React Native Linking library and is provided as a workaround by Braze.
Braze.getInitialPushPayload(pushPayload => {
  if (pushPayload) {
    console.log('Braze.getInitialPushPayload is ' + pushPayload);
    showToast('Initial URL is ' + pushPayload.url);
    handleOpenUrl({ pushPayload.url });
  }
});

Step 4: Test displaying push notifications

At this point, you should be able to send notifications to the devices. Adhere to the following steps to test your push integration.

  1. Set an active user in the React Native application by calling Braze.changeUserId('your-user-id') method.
  2. Head to Campaigns and create a new push notification campaign. Choose the platforms that you’d like to test.
  3. Compose your test notification and head over to the Test tab. Add the same user-id as the test user and click Send Test. You should receive the notification on your device shortly.

A Braze push campaign showing you can add your own user ID as a test recipient to test your push notification.

Advanced configurations with the Expo plugin

For certain advanced cases that need to be configured in the native Android and iOS SDKs, Braze provides special configurations via the Expo plugin to handle those push notifications behaviors.

Forwarding Android push to additional FMS

If you want to use an additional Firebase Messaging Service (FMS), you can specify a fallback FMS to call if your application receives a push that isn’t from Braze. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
  "expo": {
    "plugins": [
      [
        "@braze/expo-plugin",
        {
          ...
          "androidFirebaseMessagingFallbackServiceEnabled": true,
          "androidFirebaseMessagingFallbackServiceClasspath": "com.company.OurFirebaseMessagingService"
        }
      ]
    ]
  }
}

Enabling rich push notifications for iOS

To enable rich push notifications on iOS using Expo, configure the enableBrazeIosRichPush property to true in your expo.plugins object in app.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "expo": {
    "plugins": [
      [
        "@braze/expo-plugin",
        {
          ...
          "enableBrazeIosRichPush": true
        }
      ]
    ]
  }
}

Lastly, add the bundle identifier for this app extension to your project’s credentials configuration: <your-app-bundle-id>.BrazeExpoRichPush. For further details on this process, refer to Using app extensions with Expo Application Services.

Enabling Push Stories for iOS

To enable Push Stories on iOS using Expo, ensure you have an app group defined for your application. For more information, see Adding an App Group.

Next, configure the enableBrazeIosPushStories property to true and assign your app group ID to iosPushStoryAppGroup in your expo.plugins object in app.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
  "expo": {
    "plugins": [
      [
        "@braze/expo-plugin",
        {
          ...
          "enableBrazeIosPushStories": true,
          "iosPushStoryAppGroup": "group.com.company.myApp.PushStories"
        }
      ]
    ]
  }
}

Lastly, add the bundle identifier for this app extension to your project’s credentials configuration: <your-app-bundle-id>.BrazeExpoPushStories. For further details on this process, refer to Using app extensions with Expo Application Services.

Using app extensions with Expo Application Services

If you are using Expo Application Services (EAS) and have enabled enableBrazeIosRichPush or enableBrazeIosPushStories, you will need to declare the corresponding bundle identifiers for each app extension in your project. There are multiple ways you can approach this step, depending on how your project is configured to manage code signing with EAS.

One approach is to use the appExtensions configuration in your app.json file by following Expo’s app extensions documentation. Alternatively, you can set up the multitarget setting in your credentials.json file by following Expo’s local credentials documentation.

HOW HELPFUL WAS THIS PAGE?
New Stuff!