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.
The initial in-app message display operation can be set in Braze config via the “In App Message Manager Initial Display Operation”.
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);
}
}
}
GIF Support
You can add animated GIFs to your in-app messages using the native Braze Android SDK. By default, the Android SDK uses HTML in-app messages to display GIFs.
For all other in-app message types, you’ll need to use a custom image library. To learn more, see Android In-App Messaging: GIFs.
You can add animated GIFs to your in-app messages using the native Braze Swift SDK. By default, all Braze in-app messages support GIFs. For a full walkthrough, see Tutorial: GIF Support for Swift In-App Messages.
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
.
Custom action listeners
If you require more control over how a user interacts with in-app messages, use a BrazeInAppMessageListener
and assign it to Appboy.AppboyBinding.inAppMessageListener
. For any delegates you don’t want to use, you can simply leave them as null
.
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
BrazeInAppMessageListener listener = new BrazeInAppMessageListener() {
BeforeInAppMessageDisplayed = BeforeInAppMessageDisplayed,
OnInAppMessageButtonClicked = OnInAppMessageButtonClicked,
OnInAppMessageClicked = OnInAppMessageClicked,
OnInAppMessageHTMLClicked = OnInAppMessageHTMLClicked,
OnInAppMessageDismissed = OnInAppMessageDismissed,
};
Appboy.AppboyBinding.inAppMessageListener = listener;
public void BeforeInAppMessageDisplayed(IInAppMessage inAppMessage) {
// Executed before an in-app message is displayed.
}
public void OnInAppMessageButtonClicked(IInAppMessage inAppMessage, InAppMessageButton inAppMessageButton) {
// Executed whenever an in-app message button is clicked.
}
public void OnInAppMessageClicked(IInAppMessage inAppMessage) {
// Executed whenever an in-app message is clicked.
}
public void OnInAppMessageHTMLClicked(IInAppMessage inAppMessage, Uri uri) {
// Executed whenever an HTML in-app message is clicked.
}
public void OnInAppMessageDismissed(IInAppMessage inAppMessage) {
// Executed whenever an in-app message is dismissed without a click.
}