Overview
In-app messages arrive in your app as data, not as finished screens. The SDK keeps a local inbox of each user’s messages up to date and calls your code when it changes. Your app picks the messages for a screen, lays them out with its own UI, and reports what the user did with them. Each message carries the fields from its template, such as a headline, an image URL, and a button label, keyed by the names your marketing team agreed with you. See What your app receives.Before you begin
- Push setup: Complete Set up Android push notifications through Identify users on login and logout. The SDK fetches a user’s messages only for a device that has an FCM token and has called
identify. - Android 5.0 or later: The SDK supports API level 21 and later. In-app messages need a version of
android-pushthat includesHightouchMessages. - A template: Agree with your marketing team on the templates your app supports, and the key of each field. See Build an in-app template.
Turn on in-app messages
Add aHightouchMessagesConfig to the HightouchPushConfig you already pass to HightouchPush.initialize, in your Application class’s onCreate:
Application.onCreate. If Android starts your app for a silent push and initialize hasn’t run, the SDK ignores the push.
HightouchMessagesConfig.Builder takes these options:
Turn on
setSyncOnForeground unless your app relies on silent pushes alone. Without it, the SDK doesn’t fetch new messages for a user who keeps the app in the background until the next launch or silent push.
To listen from a screen instead, call HightouchMessages.addListener when it starts and HightouchMessages.removeListener when it stops. Pass an object that the screen holds, not a lambda created inline, because the SDK keeps only a weak reference to each listener.
Keep the inbox up to date
The SDK fetches messages:- When the app launches, if sync on launch is on.
- When the app returns to the foreground, if sync on foreground is on.
- When a user logs in with
HightouchPush.identify. - When a silent push arrives from Hightouch, if the message has push apps selected. See Refresh inboxes right away.
FirebaseMessagingService, it must forward messages to the SDK. See Use the SDK alongside another FCM provider. Otherwise, inboxes refresh only on launch and foreground.
To fetch messages yourself, such as on pull to refresh, call sync:
Show messages in your app
Load the messages for a screen withloadMessages, which reads off the main thread and calls back on it. Filter by the template’s Location ID to get the messages for one placement:
val messages = HightouchMessages.loadMessages(HightouchMessageQuery()).
The SDK returns messages sorted by priority, then by most recent, and leaves out expired messages. A HightouchMessageQuery also takes variantSlug, the template’s key, to load only messages built from one template. HightouchMessages.messages(query) reads synchronously, but it can block right after startup, so prefer loadMessages on the main thread.
Read the fields from the message’s content, a JsonElement from kotlinx.serialization. Each element’s tag is a field key from the template:
elements. Give your views a fallback for every optional field.
Report impressions, clicks, and dismissals
The SDK doesn’t know when your app shows a message, so report each interaction yourself. These events power the Impressions, Clicked, and Dismissed metrics in Hightouch, and they’re written to your warehouse.identifier to trackClick to tell buttons apart in your warehouse data. It defaults to default.
trackDismissed removes the message from the device, and Hightouch removes it from the user’s other devices. The user doesn’t receive that message again, even if they leave and rejoin the audience.
Tips and troubleshooting
No messages arrive
The SDK skips a sync when the user isn’t identified or the device has no FCM token. Check that:- Your app calls
HightouchPush.identifyafter the user logs in. Users who aren’t logged in don’t receive in-app messages. - The user ID matches the primary key of the profile in your Delivery parent model.
- The profile is in the campaign’s audience, or has reached the journey’s Send in-app tile, and the campaign or journey is running.
HightouchMessages.sync(force = true) and check the outcome. If it returns Unchanged, the SDK either found no changes or skipped the sync because the user isn’t identified or the device has no FCM token.
A new message takes a while to appear
Without a push app on the message, a device picks it up on its next sync. Turn onsetSyncOnForeground, or ask your marketing team to select push apps on the message.
Messages stop updating after a while
The SDK keeps a weak reference to your listener. A lambda that nothing else holds is garbage collected, and your app stops hearing about changes. Store the listener in a field of a long-lived object, such as yourApplication.
Next steps
- Build an in-app template: the fields and keys your app reads.
- Send an in-app campaign: send a message to your test profile to check the integration end to end.