Server-side Event Triggering
By default in-app messages are triggered by custom events logged by the SDK. If you would like to trigger in-app messages by server sent events you are also able to achieve this.
To enable this feature, a silent push is sent to the device which allows a custom push receiver to log an SDK based event. This SDK event will subsequently trigger the user-facing in-app message.
Step 1: Register a Custom Broadcast Receiver to Log Custom Event
Register your custom
BroadcastReceiver to listen for a specific silent push within your AndroidManifest.xml. For more information on how to register a custom
BroadcastReceiver please review Braze’s push documentation.
Step 2: Create your BroadcastReceiver
Your receiver will handle the intent broadcast by the silent push and log an SDK event. Starting in SDK 2.0.0, events can be logged in the background without issue. All clients implementing this solution must be on SDK v2.0.0+.
It will subclass
BroadcastReceiver and override
onReceive(). For a detailed example, please see our EventBroadcastReceiver.java in the linked gist.
Two events will be logged for the in-app message to be delivered, one by the server and one from within your custom
BroadcastReceiver. To ensure the same event is not duplicated, the event logged from within your
BroadcastReceivershould be given a generic naming convention, for example “in-app message trigger event,” and not the same name as the server sent event. If this is not done segmentation and user data may be affected by duplicate events being logged for a single user action.
For further details on custom handling push receipts, opens, and key-value pairs please visit this section of our Documentation.
Step 3: Create a Push Campaign
Create a silent push campaign which is triggered via the server sent event. For details on how to create a silent push campaign please review this section of our Academy.
The push campaign must include key value pair extras which indicate that this push campaign is sent with the intention to log an SDK custom event. This event will be used to trigger the in-app message
The EventBroadcastReceiver.java recognizes the key value pairs and logs the appropriate SDK custom event.
Should you want to include any event properties to attach to your ‘In-App Message Trigger’ event, you can achieve this by passing these in the key value pairs of the push payload. In the example above the campaign name of the subsequent in-app message has been included. Your custom
BroadcastReceiver can then pass the value as the parameter of the event property when logging the custom event.
Step 4: Create an In-App Message Campaign
Create your user visible in-app message campaign from within Braze’s dashboard. This campaign should have an Action Based delivery, and be triggered from the custom event logged from within the custom EventBroadcastReceiver.java.
In the example below the specific in-app message to be triggered has been configured by sending the event property as part of the initial silent push.
If a server sent event is logged whilst the app is not in the foreground, the event will log but the in-app message will not be displayed. Should you want the event to be delayed until the application is in the foreground, a check must be included in your custom push receiver to dismiss or delay the event until the app has entered the foreground.