Customize your Firebase In-App Messaging messages

ios

android

Add an action to your message

With actions you can use your in-app messages to direct users to a website or a specific screen in your app.

ios

Firebase In-App Messaging uses deep link handlers to process actions. The SDK is able to use a number of handlers, so if your app already has one, Firebase In-App Messaging can use that without any further setup. If you don't yet have a handler, you can use Firebase Dynamic Links. To learn more, read Create Dynamic Links on iOS.

android

Firebase In-App Messaging uses deep link handlers to process actions. The SDK is able to use a number of handlers, so if your app already has one, Firebase In-App Messaging can use that without any further setup. If you don't yet have a handler, you can use Firebase Dynamic Links. To learn more, read Create Dynamic Links on Android.

Add the action to your message using the Firebase console

Once your app has a deep link handler, you're ready to compose a campaign with an action. Open the Firebase console to In-App Messaging, and start a new campaign or edit an existing campaign. In that campaign, provide a Button text and Button action, an Image action, or a Banner action, where the action is a relevant deep link.

The action's format depends on which message layout you choose. Modals get action buttons with customizable button text content, text color, and background color. Images and top banners, on the other hand, become interactive and invoke the specified action when tapped.

Enable opt-in message delivery

By default, Firebase In-App Messaging automatically delivers messages to all of your app's users. To deliver those messages, the Firebase In-App Messaging SDK uses Firebase Instance IDs to identify each user's app. This means that In-App Messaging has to send client data, linked to the Instance ID, to Firebase servers. If you'd like to give users more control over the data they send, enable opt-in data collection and give them a chance to approve data sharing.

To do that, you have to disable automatic initialization for Firebase In-App Messaging, and initialize the service manually for opt-in users:

ios

  1. Turn off automatic initialization with a new key in your Info.plist file:

    • Key: FirebaseInAppMessagingAutomaticDataCollectionEnabled
    • Value: NO
  2. Initialize Firebase In-App Messaging for selected users manually:

    [FIRInAppMessaging inAppMessaging].automaticDataCollectionEnabled = YES;
    

Once you set automaticDataCollectionEnabled to YES, the value persists through app restarts, overriding the value in your Info.plist. If you'd like to disable initialization again, for example, if a user opts-out of collection later, set the property to NO.

android

  1. Turn off automatic initialization with a meta-data tag in your AndroidManifest.xml file:

    <meta-data
    android:name="firebase_inapp_messaging_auto_data_collection_enabled"
    android:value="false" />
    

  2. Initialize Firebase In-App Messaging for selected users manually:

    FirebaseInAppMessaging.setAutomaticDataCollectionEnabled(true);
    

Once you set a data collection preference manually, the value persists through app restarts, overriding the value in your AndroidManifest.xml. If you'd like to disable initialization again, if a user opts-out of collection later, for example, pass false to the setAutomaticDataCollectionEnabled method.

Temporarily disable messages

ios

By default, Firebase In-App Messaging renders messages whenever a triggering condition is satisfied, regardless an app's current state. If you'd like to suppress FIAM message displays for any reason, you can do that with the SDK's messageDisplaySuppressed property:

[FIRInAppMessaging inAppMessaging].messageDisplaySuppressed = YES;

Setting the property to YES prevents Firebase In-App Messaging from displaying messages, while NO reenables message display. The SDK resets the property to NO on app restart. Suppressed messages are ignored by the SDK. Their trigger conditions must be met again while suppression is off, before Firebase In-App Messaging can display them.

android

By default, Firebase In-App Messaging renders messages whenever a triggering condition is satisfied, regardless an app's current state. If you'd like to suppress FIAM message displays for any reason, you can do that with the SDK's setMessagesSuppressed method:

FirebaseInAppMessaging.setMessagesSuppressed(true);

Passing true to the method prevents Firebase In-App Messaging from displaying messages, while false reenables message display. The SDK turns off message suppression on app restart. Suppressed messages are ignored by the SDK. Their trigger conditions must be met again while suppression is off before Firebase In-App Messaging can display them.

Modify message displays

ios

Firebase In-App Messaging lets you customize message displays to change the way your app renders messages' layout, font styles, button shapes, and other details. There are two ways to modify message displays: modify the default Firebase In-App Messaging displays or create your own message display library from scratch.

Modify default displays

The most straightforward way customize your messages is to build off of Firebase In-App Messaging's default message display code.

Clone the firebase-ios-sdk repo

To get started, clone the firebase-ios-sdk repo, and open the InAppMessagingDisplay directory.

Select message types to modify

With the repo cloned, you can modify any or all of the Firebase In-App Messaging message types: Modal, Banner, and ImageOnly. Each type corresponds to a message layout in the Firebase In-App Messaging campaign creation flow.

Accordingly, each type has access to a different set of data, determined by campaign customization options in the Firebase console:

Type titleText bodyText textColor backgroundColor imageData actionButton
Modal check check check check check check
Banner check check check check check
ImageOnly check

Modify the message display rendering code

With the message type limitations in mind, you're free to modify them however you'd like. You can create a banner that displays at the bottom of your app, move around the action button on a modal, or any other modification that would make the messages' look and feel fit your app.

There are two main things to pay attention to when modifying message displays:

Modify files in your preferred message types' directories and the corresponding sections of the .storyboard to create your custom message displays.

Update your podfile to use your modified InAppMessagingDisplay

To get Firebase In-App Messaging to use your modified message displays instead of the default displays, update your podfile to use your customized InAppMessagingDisplay:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'YourProject' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for YourProject
pod 'Firebase'

# Remove the default InAppMessagingDisplay pod:
# pod 'Firebase/InAppMessagingDisplay'

# Overwrite it with a version that points to your local copy:
pod `FirebaseInAppMessagingDisplay', :path => '~/Path/To/The/Cloned/Repo/'

end
With that done, you can update your pods, rebuild your app, and see your new, customized message displays.

Create your own message display library

You're not limited to working from the InAppMessagingDisplay library to create a UI for displaying messages. You can also write your own code from scratch.

Build a class that implements the FIRInAppMessagingRendering interface

Firebase In-App Messaging uses the FIRInAppMessaging class to handle communications between Firebase servers and your app. That class, in turn, uses the FIRInAppMessagingRendering protocol to display the messages it receives. To build your own display library, write a class that implements the protocol.

The protocol definition and documentation on how to conform to it are in the FIRInAppMessagingRendering.h file of the InAppMessaging library. If you've already set up Firebase In-App Messaging, you can find the file under your Xcode project directory:

FirebaseInAppMessaging > Frameworks > FirebaseInAppMessaging.framework > Headers > FIRInAppMessagingRendering.h.

Set messageDisplayComponent to use your message display library

FIRInAppMessaging uses its messageDisplayComponent property to determine which object to use when displaying messages. Set that property to an object of your custom message display class, so Firebase In-App Messaging knows to use your library to render messages:

[FIRInAppMessaging inAppMessaging].messageDisplayComponent = yourFIRInAppMessagingRenderingInstance;

Modify your podfile to use the headless version of Firebase In-App Messaging

The default Firebase In-App Messaging pod, Firebase/InAppMessagingDisplay, automatically assigns itself as your app's messageDisplayComponent. To get around that, use the headless Firebase/InAppMessaging pod instead:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'YourProject' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for YourProject
pod 'Firebase'

# Remove the default InAppMessagingDisplay pod:
# pod 'Firebase/InAppMessagingDisplay'

# Include the headless pod instead:
pod `Firebase/InAppMessaging'

end
With that done, you can update your pods, rebuild your app, and see your new, customized message displays.

android

Use the Firebase In-App Messaging display SDK for Android to customize how In-App Messaging displays your messages, available now on the Firebase GitHub repo.

Creating your own display is a two step process:

  1. Write your own implementation of the FirebaseInAppMessagingDisplay class.
  2. Register that implemenation with the headless Firebase In-App Messaging SDK.

To get started, check out the Firebase In-App Messaging team's implementation in FirebaseInAppMessagingDisplayImpl.java.

Send feedback about...

Need help? Visit our support page.