Skip to main content

Using Firebase In-App Messaging

Once installed, you can access the firebase_in_app_messaging plugin by importing it in your Dart code:

import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';

Before using Firebase In-App Messaging, ensure that you have initialized FlutterFire.

To use the plugin with the default Firebase App, call the instance getter on FirebaseInAppMessaging:

FirebaseInAppMessaging fiam = FirebaseInAppMessaging.instance;
info

Currently, FlutterFire In-App Messaging only supports creating an instance for the default Firebase App, you can't initialize an instance for a secondary Firebase App.

Once the plugin is set up, you're ready to receive messages from the console campaigns. Click here to learn how to create In-App Messaging campaigns.

Sending In-App Test Messages#

As stated in the Firebase official docs, you can send in-app messages on 2 frequencies:

  1. One message per device
  2. No more than one message in a minimum period of 1 day

So if you want to test your implementation, you can use the testing option in Firebase Console. First, you need to get the Firebase Installation ID of your app, by setting up firebase_installation plugin. Then, copy it and use it to send a test message.

note

You will not see the test message until you close the app, and reopen again on the testing device.

Trigger In-App Messages with Analytics Events#

You can trigger In-App Messages to be sent once an Analytics event is triggered.

  1. Setup Firebase Analytics in your app by following this guide.
  2. Trigger an Analytics event.
FirebaseAnalytics analytics = FirebaseAnalytics.instance;
analytics.logEvent('some_event');

The name of the Analytics event should also be added when creating the Firebase In-App Messaging campaign from the console.

Trigger In-App Messages Programmatically#

FlutterFire In-App Messaging plugin also allows you to trigger message programmatically:

fiam.triggerEvent('some_event');

You can specify the name of the event by adding it while creating your campaign.