Inline in-app messages

Updated

Inline in-app messages help you send dynamic content into your app. The messages can look and feel like a part of your app, but provide fresh and timely content without requiring app updates.

How it works

An inline message targets a specific view in your app. Basically, you’ll create an empty placeholder view in your app’s UI, and we’ll fill it with the content of your message.

This makes it easy to show dynamic content in your app without development effort. You don’t need to force an update every time you want to talk to your audience. And, unlike push notifications, banners, toasts, and so on, in-line messages can look like natural parts of your app.

1. Add View to your app UI to support inline messages

You’ll need to include a UI element in your app UI to render inline messages. The view will automatically adjust its height when messages are loaded or interacted with.

 We’ve set up examples in our sample apps that might help if you want to see a real-world implementation of this feature.

Add the InlineInAppMessageView component to your React Native app:

import { InlineInAppMessageView } from 'customerio-reactnative';

function MyComponent() {
  return (
    <InlineInAppMessageView
      elementId="my-message"
      onActionClick={(message, actionValue, actionName) => {
        console.log('Action clicked:', { message, actionValue, actionName });
      }}
    />
  );
}

View layout

The InlineInAppMessageView automatically adjusts its height at runtime when messages load or users interact with them. You should avoid setting a fixed height on this component as it might interfere with message rendering.

You’re responsible for setting layout styles to position your view correctly (width, margins, padding, and so on). The component will handle its own height dynamically.

2. Build and send your message

When you add an in-app message to a broadcast or campaign in Customer.io:

  1. Set the Display to Inline and set the Element ID to the ID you set in your app. If the editor says that the inline display feature is Web/iOS only, don’t worry about that. We’re working on updating this UI.
  2. (Optional) If you send multiple messages to the same Element ID, you’ll also want to set the Priority. This determines which message we’ll show to your audience first, if there are multiple messages in the queue.

Then craft and send your message!

in-app message settings with the To field set to ID and the display setting set to inline
in-app message settings with the To field set to ID and the display setting set to inline

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.

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.

Follow the steps below to implement custom actions for inline messages:

1. Compose an in-app message with a custom action

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. Listen for events

There are two ways to listen for these click events in inline in-app messages.

  1. Register a callback with your inline view:

    import { InlineInAppMessageView } from 'customerio-reactnative';
    
    function MyComponent() {
      const handleActionClick = (message, actionValue, actionName) => {
        // Perform some logic when people tap an action button.
    
        // Example code handling button tap:
        switch (actionValue) { // use actionValue or actionName, depending on how you composed the in-app message.
          case "enable-auto-renew":
            // Perform the action to enable auto-renew
            enableAutoRenew(actionName);
            break;
    
          // You can add more cases here for other actions
          default:
            // Handle unknown actions or do nothing
            console.log("Unknown action:", actionValue);
        }
      };
    
      return (
        <InlineInAppMessageView
          elementId="my-message"
          onActionClick={handleActionClick}
        />
      );
    }
    
  2. Register a global SDK event listener.

    When you register an event listener with the SDK, we’ll call the messageActionTaken event listener. We call this event listener for both modal and inline in-app message types, so you can reuse logic for inline and non-inline messages if you want.

Handle responses to messages (event listeners)

Like modal in-app messages, you can set up event listeners to handle your audience’s response to your messages.

For inline messages, you can listen for three different events:

  • messageShown: a message is “sent” and appears to a user.
  • 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. As shown above, this is only called if the View instance doesn’t have an onActionClick callback set.

Unlike modal in-app messages, you’ll notice that there’s no messageDismissed event. This is because inline messages don’t really have a concept of dismissal like modal messages do. They’re meant to be a part of your app!

Copied to clipboard!
  Contents
Version
Is this page helpful?