In-app messaging integration
This reference article covers in-app messaging configuration guidelines for the Unity platform.
Configuring default in-app message behavior
On Android, in-app messages from Braze are automatically displayed natively. To disable this functionality, deselect Automatically Display In-App Messages in the Braze configuration editor.
You may alternatively set com_braze_inapp_show_inapp_messages_automatically
to false
in your Unity project’s braze.xml
.
The initial in-app message display operation can be set in Braze config via the “In App Message Manager Initial Display Operation”.
On iOS, in-app messages from Braze are automatically displayed natively. To disable this functionality, set game object listeners in the Braze configuration editor and ensure Braze Displays In-App Messages is not selected.
Configuring in-app message display behavior
You may optionally change the display behavior of in-app messages at runtime via the following:
1
2
3
4
5
6
7
8
// Sets in-app messages to display immediately when triggered.
Appboy.AppboyBinding.SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType.IAM_DISPLAY_NOW);
// Sets in-app messages to display at a later time and be saved in a stack.
Appboy.AppboyBinding.SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType.IAM_DISPLAY_LATER);
// Sets in-app messages to be discarded after being triggered.
Appboy.AppboyBinding.SetInAppMessageDisplayAction(BrazeUnityInAppMessageDisplayActionType.IAM_DISCARD);
Displaying in-app messages on demand
You may display the next available in-app message in the stack via the DisplayNextInAppMessage()
method. Messages are added to this stack of saved messages if DISPLAY_LATER
or BrazeUnityInAppMessageDisplayActionType.IAM_DISPLAY_LATER
is chosen as the in-app message display action.
1
Appboy.AppboyBinding.DisplayNextInAppMessage();
Receiving in-app message data in Unity
You may register Unity game objects to be notified of incoming in-app messages. We recommend setting game object listeners from the Braze configuration editor. In the configuration editor, listeners must be set separately for Android and iOS.
If you need to configure your game object listener at runtime, use AppboyBinding.ConfigureListener()
and specify BrazeUnityMessageType.IN_APP_MESSAGE
.
Parsing in-app messages
Incoming string
messages received in your in-app message game object callback can be parsed into our pre-supplied model objects for convenience.
Use InAppMessageFactory.BuildInAppMessage()
to parse your in-app message. The resulting object will either be an instance of IInAppMessage.cs
or IInAppMessageImmersive.cs
depending on its type.
Example in-app message callback
1
2
3
4
5
6
7
8
9
10
// Automatically logs a button click, if present.
void InAppMessageReceivedCallback(string message) {
IInAppMessage inApp = InAppMessageFactory.BuildInAppMessage(message);
if (inApp is IInAppMessageImmersive) {
IInAppMessageImmersive inAppImmersive = inApp as IInAppMessageImmersive;
if (inAppImmersive.Buttons != null && inAppImmersive.Buttons.Count > 0) {
inAppImmersive.LogButtonClicked(inAppImmersive.Buttons[0].ButtonID);
}
}
}
Analytics
Clicks and impressions must be manually logged for in-app messages not displayed directly by Braze.
Use LogClicked()
and LogImpression()
on IInAppMessage
to log clicks and impressions on your message.
Use LogButtonClicked(int buttonID)
on IInAppMessageImmersive
to log button clicks. Note that buttons are represented as lists ofInAppMessageButton
instances, each of which contains a ButtonID
.