In-app messages

Incorporate in-app messages to send dynamic, personalized content to people using your app. With in-app messages, you can speak directly to your app’s users when they use your app.

This page is part of a setup flow for the SDK. Before you continue, make sure you've implemented previous features—i.e. you can't receive in-app notifications before you identify people!

graph LR getting-started(Install SDK) -->B(Initialize SDK) B --> identify(identify people) identify -.-> track-events(Send events) identify -.-> push(Receive push) identify -.-> rich-push(Receive Rich Push) track-events --> test-support(Write tests) push --> test-support rich-push --> test-support identify -.-> in-app(Receive in-app) in-app --> test-support click getting-started href "/docs/sdk/android/getting-started/#install" click B href "/docs/sdk/android/getting-started/#initialize-the-sdk" click identify href "/docs/sdk/android/identify" click track-events href "/docs/sdk/android/track-events/" click register-token href "/docs/sdk/android/push" click push href "/docs/sdk/android/push" click rich-push href "/docs/sdk/android/rich-push" click in-app href "/docs/sdk/android/in-app" click test-support href "/docs/sdk/android/test-support" style in-app fill:#B5FFEF,stroke:#007069

How it works

An in-app message is a message that people see within the app. To set up in app messaging, install and initialize the tracking and messaging-in-app packages.

People won’t see your in-app messages until they open your app. If you set an expiry period for your message, and that time elapses before someone opens your app, they won’t see your message.

You can also set page rules to display your in-app messages when people visit specific pages in your app. However, to take advantage of page rules, you need to implement screen tracking features. Screen tracking tells us the names of your pages and which page a person is on, so we can display in-app messages on the correct pages in your app.

graph LR a[app user triggers
in-app message]-->d{is the app open?} d-->|yes|f[user gets message] d-->|no|e[hold message
until app opens] e-->g{did the message
expire?} g-->|no, wait for user
to open the app|d g-->|yes|h[user doesn't
get the message]

Install the SDK and in-app module

  1. Make sure that you add update your repositories in the settings.gradle file to include the in-app SDK.

    dependencyResolutionManagement {
       repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
       repositories {
          google()
          mavenCentral()
          // only needed for in-app messaging in SDK versions below 3.6.1
          // maven { url 'https://maven.gist.build' }
       }
    }
  2. Implement the messaging-in-app package.

    implementation "io.customer.android:messaging-in-app:<version-here>"

Initialize the SDK with the in-app module

Simply initialize the SDK with the MessagingInApp module and your app will be able to receive in-app messages. Create a campaign and send your first in-app message to test your implementation!

CustomerIO.Builder(
   siteId = "siteId",
   apiKey = "apiKey",
   appContext = application,
).apply {
   // Setup In-app messaging
   addCustomerIOModule(ModuleMessagingPushFCM())
   addCustomerIOModule(ModuleMessagingInApp())
   setLogLevel(CioLogLevel.DEBUG)
   // For fragment-based apps or Jetpack Compose, disable this and use manual screen tracking
   autoTrackScreenViews(true)
   setRequestTimeout(8000L)
   setRegion(Region.US)
   build()
}

// `ModuleMessagingInApp` takes in optional configuration options.
// One option is an event listener to get notified when a message is shown, dismissed, or an action is taken.
ModuleMessagingInApp(config = MessagingInAppModuleConfig.Builder()
   .setEventListener(object : InAppEventListener {
      override fun errorWithMessage(message: InAppMessage) {}
      override fun messageActionTaken(message: InAppMessage, actionValue: String, actionName: String) {}
      override fun messageDismissed(message: InAppMessage) {}
      override fun messageShown(message: InAppMessage) {}
   })
   .build()
)

Page rules

You can set page rules when you create an in-app message. A page rule determines the page that your audience must visit in your app to see your message. However, before you can take advantage of page rules, you need to:

  1. Enable screen tracking in the SDK. If you are using a view(xml)-based() UI with activities, you can enable automatic screen tracking by calling autoTrackScreenViews(true) during SDK initialization. However, if your app is fragment-based or utilizes Jetpack Compose, we recommend utilizing manual screen tracking with the screen method.
  2. Provide page names to whomever sets up in-app messages in fly.customer.io.

The SDK automatically uses label in your manifest file as the page/screen name. If your screens don’t have labels, you won’t be able to set up page rules and screenview events will have an empty event name.

You should inform anybody creating in-app messages about page names if you want to set up page rules, to make sure that your messages appear on the right pages of your app. If we don’t recognize the page that you set for a page rule, your audience will never see your message.

Set up page rules to limit in app messages by page
Set up page rules to limit in app messages by page

Keep in mind: page rules are case sensitive. If you’re targeting your mobile app, make sure your page rules match the casing of the name in your screen events. If you’re targeting your website, your page rules should always be lowercase.

The first page rule is Web contains /dashboard. The second page rule is iOS contains Dashboard.
The first page rule is Web contains /dashboard. The second page rule is iOS contains Dashboard.

Targeting people with in-app messages

Whoever composes messages in your system needs to know how you identify people—whether you recognize people by email address or ID.

When you set up a message in Customer.io, you’ll set a To field. This field is the identifierThe attributes you use to add, modify, and target people. Each unique identifier value represents an individual person in your workspace. that your app uses to identify people in Customer.io. When a person in your campaign or broadcast is identified by the value in the To field, they’ll receive your message. If your app doesn’t identify people using the value you select, we won’t deliver your message to the person. Your messages will appear as Sent, but never Opened or Clicked.

Handle responses to messages (event listeners)

You can set up event listeners to handle your audience’s response to your messages. For example, you might run different code in your app when your audience taps a button in your message or when they dismiss the message without tapping a button.

You can listen for four different events:

  • messageShown: a message is “sent” and appears to a user
  • messageDismissed: the user closes the message (by tapping an element that uses the close action)
  • errorWithMessage: the message itself produces an error—this probably prevents the message from appearing to the user
  • messageActionTaken: the user performs an action in the message.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
CustomerIO.Builder(
   siteId = "siteId",
   apiKey = "apiKey",
   appContext = application,
).apply {
   addCustomerIOModule(ModuleMessagingInApp())
   build()
}

ModuleMessagingInApp(config = MessagingInAppModuleConfig.Builder()
   .setEventListener(object : InAppEventListener {
      override fun errorWithMessage(message: InAppMessage) {}
      override fun messageActionTaken(message: InAppMessage, actionValue: String, actionName: String) {}
      override fun messageDismissed(message: InAppMessage) {}
      override fun messageShown(message: InAppMessage) {}
   })
   .build()
)

Handling custom actions

When you set up an in-app message, you can determine the “action” to take when someone taps a button, taps your message, etc. In most cases, you’ll want to deep link to a screen, etc. But, in some cases, you might want to execute some custom action or code—like requesting that a user opts into push notifications or enables a particular setting.

In these cases, you’ll want to use the messageActionTaken event listener and listen for custom action names or values to execute code. While you’ll have to write custom code to handle custom actions, the SDK helps you listen for in-app message events including your custom action, so you know when to execute your custom code.

  1. When you add an action to an in-app message in Customer.io, select Custom Action and set your Action’s Name and value. The Name corresponds to the actionName, and the value represents the actionValue in your event listener.
    Set up a custom in-app action
    Set up a custom in-app action
  2. Register an event listener for MessageActionTaken, and listen for the actionName or actionValue you set up in the previous step.

     Use names and values exactly as entered

    We don’t modify your action’s name or value, so you’ll need to match the case of names or values exactly as entered in your Custom Action.

  3. When someone receives a message and invokes the action (tapping a button, tapping a message, etc), your app will perform the custom action.

Dismiss in-app message

You can dismiss the currently display in-app message with the following method. This can be particularly useful to dismiss in-app messages when your audience clicks or taps custom actions.

    CustomerIO.instance().inAppMessaging().dismissMessage()
Copied to clipboard!
  Contents
Current release
 3.11.1
Is this page helpful?
Chat with AI