Log in-app message data
Learn how to log in-app message (IAM) data through the Braze SDK.
Prerequisites
Before you can use this feature, you’ll need to integrate the Web Braze SDK.
Logging message data
Logging in-app message impressions and clicks is performed automatically when you use the showInAppMessage or automaticallyShowInAppMessage method.
If you do not use either method and opt to manually display the message using your own UI code, use the following methods to log analytics:
1
2
3
4
5
6
7
8
// Registers that a user has viewed an in-app message with the Braze server.
braze.logInAppMessageImpression(inAppMessage);
// Registers that a user has clicked on the specified in-app message with the Braze server.
braze.logInAppMessageClick(inAppMessage);
// Registers that a user has clicked a specified in-app message button with the Braze server.
braze.logInAppMessageButtonClick(button, inAppMessage);
// Registers that a user has clicked on a link in an HTML in-app message with the Braze server.
braze.logInAppMessageHtmlClick(inAppMessage, buttonId?, url?)
Prerequisites
Before you can use this feature, you’ll need to integrate the Flutter Braze SDK.
Logging message data
To log analytics using your BrazeInAppMessage, pass the instance into the desired analytics function:
logInAppMessageClickedlogInAppMessageImpressionlogInAppMessageButtonClicked(along with the button index)
For example:
1
2
3
4
5
6
// Log a click
braze.logInAppMessageClicked(inAppMessage);
// Log an impression
braze.logInAppMessageImpression(inAppMessage);
// Log button index `0` being clicked
braze.logInAppMessageButtonClicked(inAppMessage, 0);
Accessing message data
To access in-app message data in your Flutter app, the BrazePlugin supports sending in-app message data using Dart Streams.
The BrazeInAppMessage object supports a subset of fields available in the native model objects, including uri, message, header, buttons, extras, and more.
Listen for in-app message data in the Dart layer
To receive in-app message data in the Dart layer, use the code below to create a StreamSubscription and call braze.subscribeToInAppMessages(). Remember to cancel() the stream subscription when it is no longer needed.
1
2
3
4
5
6
7
8
9
// Create stream subscription
StreamSubscription inAppMessageStreamSubscription;
inAppMessageStreamSubscription = braze.subscribeToInAppMessages((BrazeInAppMessage inAppMessage) {
// Handle in-app messages
}
// Cancel stream subscription
inAppMessageStreamSubscription.cancel();
For an example, see main.dart in the Braze Flutter SDK sample application.
Forward in-app message data from the native layer
In-app message data is automatically forwarded from both the Android and iOS native layers. No additional setup is required.
If you’re using Flutter SDK 17.1.0 or earlier, in-app message data forwarding from the iOS native layer requires manual setup. Your application likely contains one of the following. To migrate to Flutter SDK 18.0.0, remove the BrazePlugin.processInAppMessage(_:) call—data forwarding is now handled automatically.
Remove the BrazePlugin.processInAppMessage(_:) call from your willPresent delegate implementation.
Remove the BrazePlugin.processInAppMessage(message) call from your custom presenter’s present(message:) implementation:
1
2
3
4
5
6
7
8
9
class CustomInAppMessagePresenter: BrazeInAppMessageUI {
override func present(message: Braze.InAppMessage) {
// Pass in-app message data to the Dart layer.
BrazePlugin.processInAppMessage(message)
// If you want the default UI to display the in-app message.
super.present(message: message)
}
}
Replaying the callback for in-app messages (optional)
To store any in-app messages triggered before the callback is available and replay them after it is set, add the following entry to the customConfigs map when initializing the BrazePlugin:
1
BrazePlugin braze = new BrazePlugin(customConfigs: {replayCallbacksConfigKey: true});
Prerequisites
Before you can use this feature, you’ll need to integrate the Android Braze SDK.
Logging message data
You will need to make sure certain functions are called to handle the analytics for your campaign.
Displayed messages
When a message is displayed or seen, log an impression:
1
LogInAppMessageImpression(in_app_message.id, brazetask)
Clicked messages
Once a user clicks on the message, log a click and then process in_app_message.click_action:
1
LogInAppMessageClick(in_app_message.id, brazetask)
Clicked buttons
If the user clicks on a button, log the button click and then process inappmessage.buttons[selected].click_action:
1
LogInAppMessageButtonClick(inappmessage.id, inappmessage.buttons[selected].id, brazetask)
After processing a message
After processing an in-app message, you should clear the field:
1
m.BrazeTask.BrazeInAppMessage = invalid
Subscribing to in-app messages
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 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.
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);
}
}
}
Logging message data
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.

