Push Notifications

These instructions are for integrating push with Firebase Cloud Messaging (FCM).

For ADM integration instructions, see our Unity ADM documentation.

Step 1: Enable Firebase

To get started, follow the instructions at Firebase Unity Setup Docs.

Note that integrating the Firebase Unity SDK may cause your AndroidManifest.xml to be overriden. If that occurs, make sure to revert it to its original self.

Step 2: Set Your Firebase Credentials

You need to input your Firebase Server Key and Sender ID into the Braze dashboard:

  • On the app settings page (where your API keys are located), select your Android app.
  • Enter your Firebase Server Key in the field labeled “Firebase Cloud Messaging Server Key” under the Push Notification Settings section.
  • Enter your Firebase Sender ID in the field labeled “Firebase Cloud Messaging Sender ID” under the Push Notification Settings section.

FCMKey

If you’re not familiar with the location of your Firebase Server Key and Sender ID, follow these steps:

  1. Login to the Firebase Developers Console

  2. Select your Firebase project

  3. Select Cloud Messaging under Settings and copy the Server Key and Sender ID: FirebaseServerKey

Step 3: Implement Automatic Push Integration

The Braze SDK can automatically handle push registration with the Firebase Cloud Messaging Servers in order to have devices receive push notifications.

AndroidPushSettings

  • “Automatic Firebase Cloud Messaging Registration Enabled”

Instructs the Braze SDK to automatically retrieve and send a FCM push token for a device.

  • “Firebase Cloud Messaging Sender ID”

The Sender ID from your Firebase console.

  • “Handle Push Deeplinks Automatically”

Whether the SDK should handle opening deeplinks or the opening the app when push notifications are clicked.

  • “Small Notification Icon Drawable”

The drawable that should be displayed as the small icon whenever a push notification is received. If no icon is given, the notification will use the application icon as the small icon.

Step 4: Set Push Listeners

If you would like to pass push notification payloads to Unity or take additional steps when a user receives a push notification, Braze provides the option of setting push notification listeners.

  • On the Settings page (where your API keys are located), select your Android app.
  • Enter your Firebase Server Key in the Firebase Cloud Messaging Server Key field, under the Push Notification Settings section.
  • Enter your Firebase Sender ID in the Firebase Cloud Messaging Sender ID field, under the Push Notification Settings section.

Push Received Listener

The Push Received listener is fired when a user receives a push notification. To send the push payload to Unity, set the name of your Game Object and Push Received listener callback method under the “Set Push Received Listener”.

Push Opened Listener

The Push Opened listener is fired when a user launches the app by clicking on a push notification. To send the push payload to Unity, set the name of your Game Object and Push Opened listener callback method under the “Set Push Opened Listener”.

Push Deleted Listener (Android Only)

The Push Deleted listener is fired when a user swipes away or dismisses a push notification. To send the push payload to Unity, set the name of your Game Object and Push Deleted listener callback method under the “Set Push Deleted Listener”.

Push Listener Implementation Example

The following example implements the BrazeCallback game object using a callback method name of PushNotificationReceivedCallback, PushNotificationOpenedCallback, and PushNotificationDeletedCallback respectively.

Game Object Linking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MainMenu : MonoBehaviour {
  void PushNotificationReceivedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationReceivedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification received: " + pushNotification);   
#elif UNITY_IOS
    ApplePushNotification pushNotification = new ApplePushNotification(message);
    Debug.Log("Push received Notification event: " + pushNotification);   
#endif  
  }

  void PushNotificationOpenedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationOpenedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification opened: " + pushNotification);  
#elif UNITY_IOS
    ApplePushNotification pushNotification = new ApplePushNotification(message);
    Debug.Log("Push opened Notification event: " + pushNotification);   
#endif  
  }

  void PushNotificationDeletedCallback(string message) {
#if UNITY_ANDROID
    Debug.Log("PushNotificationDeletedCallback message: " + message);
    PushNotification pushNotification = new PushNotification(message);
    Debug.Log("Push Notification dismissed: " + pushNotification);  
#endif
  }
}

Implementation Example

The sample project in the Braze Unity SDK repository contains a full working sample app that includes FCM.

Deep Linking to In-App Resources

Although Braze can handle standard deep links (such as website urls, Android uris, etc.) out of the box, creating custom deep links requires additional Manifest setup.

See Android’s documentation on “Deep Linking” to In-App Resources

WAS THIS PAGE HELPFUL?
New Stuff!