Modify behavior of Firebase In-App Messaging messages


With little to no coding effort, Firebase In-App Messaging allows you to create,configure and target rich user interactions, leveragingthe capabilities ofGoogle Analytics out of the boxto tie messaging events to actual user characteristics, activities, and choices.With some additionalFirebase In-App Messaging SDK integration, you can tailorthe behavior of in-app messages even further, responding when users interactwith messages, triggering message events outside theAnalyticsframework, and allowing users to control sharing of their personal data relatedto messaging interactions.

Respond when users interact with in-app messages

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

Your code can respond to basic interactions (clicks and dismissals), toimpressions (verified views of your messages), and to display errors logged andconfirmed by the SDK. For example, when your message is composed as a Cardmodal, you might want to track and follow-up on which of two URLs the userclicked on the Card.

Implement a DisplayDelegate to handle Card interactions

You can register an in-app messaging display delegate that will be calledwhenever there is any interaction with an in-app message. To do this, implementa class per theInAppMessagingDisplayDelegate protocol and set it as thedelegate property on theInAppMessaging instance.

Assuming again that you want to track which link a user clicked on a Card-stylemessage, define a class that implements themessageClicked method per theDisplayDelegate protocol, thereby providing you access to thelink clicked by the user.

Swift

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.

Refer to the Swiftdisplay delegate reference for the set of callback methods that can be implemented and their parameters, includingInAppMessagingAction.

// In CardActionFiamDelegate.swiftclassCardActionFiamDelegate:NSObject,InAppMessagingDisplayDelegate{funcmessageClicked(_inAppMessage:InAppMessagingDisplayMessage){// ...}funcmessageDismissed(_inAppMessage:InAppMessagingDisplayMessage,dismissType:InAppMessagingDismissType){// ...}funcimpressionDetected(forinAppMessage:InAppMessagingDisplayMessage){// ...}funcdisplayError(forinAppMessage:InAppMessagingDisplayMessage,error:Error){// ...}}// In AppDelegate.swift// Register the delegate with the InAppMessaging instanceletmyFiamDelegate=CardActionFiamDelegate()InAppMessaging.inAppMessaging().delegate=myFiamDelegate;

Objective-C

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.

Refer to the Objective-Cdisplay delegate reference for the set of callback methods that can be implemented and their parameters, includingFIRInAppMessagingDisplayMessage.

// In CardActionFiamDelegate.h@interfaceCardActionFiamDelegate :NSObject<FIRInAppMessagingDisplayDelegate>@end// In CardActionFiamDelegate.m@implementationCardActionFiamDelegate-(void)displayErrorForMessage:(nonnullFIRInAppMessagingDisplayMessage*)inAppMessageerror:(nonnullNSError*)error{// ...}-(void)impressionDetectedForMessage:(nonnullFIRInAppMessagingDisplayMessage*)inAppMessage{// ...}-(void)messageClicked:(nonnullFIRInAppMessagingDisplayMessage*)inAppMessage{// ...}-(void)messageDismissed:(nonnullFIRInAppMessagingDisplayMessage*)inAppMessagedismissType:(FIRInAppMessagingDismissType)dismissType{// ...}@end// In AppDelegate.mCardActionFiamDelegate*myFiamDelegate=[CardActionFiamDelegatenew];[FIRInAppMessaginginAppMessaging].delegate=myFiamDelegate;

Trigger in-app messages programmatically

Firebase In-App Messaging by default allows you to trigger in-app messages withGoogle Analytics for Firebase events, with no additional integration. You canalso manually trigger events programmatically with theFirebase In-App Messaging SDK’sprogrammatic triggers.

In the In-App Messaging campaign composer, create a new campaign or select anexisting campaign, and in the Scheduling step of the composer workflow, note theevent ID of a newly-created or existing messaging event. Once noted, instrumentyour app to trigger the event by its ID.

Swift

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.
// somewhere in the app's codeInAppMessaging.inAppMessaging().triggerEvent("exampleTrigger");

Objective-C

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.
// somewhere in the app's code[[FIRInAppMessaginginAppMessaging]triggerEvent:@"exampleTrigger"];

Use campaign custom metadata

In your campaigns, you can specify custom data in a series of key/value pairs.When users interact with messages, this data is available for you to, for example,display a promo code.

Swift

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.
classCardActionDelegate:NSObject,InAppMessagingDisplayDelegate{funcmessageClicked(_inAppMessage:InAppMessagingDisplayMessage){// Get data bundle from the inapp messageletappData=inAppMessage.appData// ...}}

Objective-C

Note: This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.
@implementationExampleCardActionDelegate-(void)messageClicked:(nonnullFIRInAppMessagingDisplayMessage*)inAppMessage{NSDictionary*appData=inAppMessage.appData;NSLog(@"Message data: %@",appData);// ...}@end

Temporarily disable in-app messages

By default,Firebase In-App Messaging renders messages whenever a triggering condition is satisfied, regardless of an app's current state. If you'd like to suppress message displays for any reason, for example to avoid interrupting a sequence of payment processing screens, use the SDK'smessageDisplaySuppressed property as illustrated here in Objective-C:

[FIRInAppMessaginginAppMessaging].messageDisplaySuppressed=YES;

Setting the property toYES preventsFirebase In-App Messaging from displaying messages, whileNO reenables message display. The SDK resets the property toNO on app restart. Suppressed messages are ignored by the SDK. Their trigger conditions must be met again while suppression is off, beforeFirebase In-App Messaging can display them.

Enable opt-out message delivery

By default,Firebase In-App Messaging automatically delivers messages to all app users you targetin messaging campaigns. To deliver those messages, theFirebase In-App Messaging SDK usesFirebase installation IDs to identify each user's app. This meansthatIn-App Messaging has to send client data, linked to theinstallation ID, to Firebase servers. If you'd like to give usersmore control over the data they send, disable automatic data collection and givethem a chance to approve data sharing.

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

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

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

    // Only needed if FirebaseInAppMessagingAutomaticDataCollectionEnabled is set to NO// in Info.plist[FIRInAppMessaginginAppMessaging].automaticDataCollectionEnabled=YES;

    Once you setautomaticDataCollectionEnabled toYES, the value persiststhrough app restarts, overriding the value in yourInfo.plist. If you'd liketo disable initialization again, for example if a user opts out ofcollection later, set the property toNO.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.