Plugins
In App Messaging
@nativescript/firebase-in-app-messaging β
Contents β
- Intro
- Set up your app for Firebase
- Add the Firebase In-App Messaging SDK to your app
- Firebase In-App Messaging limitations
- Create message campaigns
- Control messages display
- Trigger contextual messages
- API
- License
Intro β
This plugin allows you to use the Firebase In-App Messaging SDK in your NativeScript app.
Set up your app for Firebase β
You need to set up your app for Firebase before you can use the Firebase in-app messaging. To set up and initialize Firebase for your NativeScript app, follow the instructions on the documentation of the @nativescript/firebase-core plugin.
Add the Firebase In-App Messaging SDK to your app β
To add the Firebase In-App Messaging SDK to your app follow these steps:
- Install the
@nativescript/firebase-in-app-messaging
plugin by running the following command in the root directory of your project.
npm install @nativescript/firebase-in-app-messaging
- Add the SDK by importing the
@nativescript/firebase-in-app-messaging
module in your app's main file (e.g.app.ts
ormain.ts
).
import'@nativescript/firebase-in-app-messaging'
Firebase In-App Messaging limitations β
According to a github issue https://github.com/firebase/firebase-ios-sdk/issues/4768, Firebase In-App Messaging allows only 1 campaign per day on app foreground or app launch. This limit is to prevent you from accidentally overwhelming your users with non-contextually appropriate messages. However, if you use contextual triggers (for example Analytics events or programmatically triggered in-app-messaging campaigns), there is no daily rate limit.
Create message campaigns β
To create a message campaign, go to the In-App Messaging
page in the Firebase Console and follow the instructions there. You can create campaigns and customize elements such as Image, Banner, Modal & Cards to appear on predefined events (e.g. purchase).
Any published campaigns from the Firebase Console are automatically handled and displayed on your user's device.
Control messages display β
To control whether to display messages or not, set the isMessagesDisplaySuppressed
property of the InAppMessaging
instance to true
or false
. The InAppMessaging
instance is returneb calling the inAppMessaging()
on the FirebaseApp instance. By default, isMessagesDisplaySuppressed
is set to false
which means messages will be displayed.
import { firebase } from'@nativescript/firebase-core'
import'@nativescript/firebase-in-app-messaging'
asyncfunctionbootstrap() {
firebase().inAppMessaging().isMessagesDisplaySuppressed =true
}
asyncfunctiononSetup(user) {
awaitsetupUser(user)
// Allow user to receive messages now setup is complete
firebase().inAppMessaging().isMessagesDisplaySuppressed =false
}
Note
The suppressed state is not persisted between restarts, so ensure it is called as early as possible ideally in the app bootstrapping file(app.ts
or main.ts
).
Trigger contextual messages β
To trigger contextual messages, call the triggerEvent()
method of the InAppMessaging
instance with the event name as a parameter. This triggers the display of any messages that are configured on the Firebase Console.
import { firebase } from'@nativescript/firebase-core'
firebase().inAppMessaging().triggerEvent('purchase')
API β
InAppMessaging class β
app β
inAppMessagingApp =firebase().inAppMessaging().app
The app
property returns the FirebaseApp
instance that the current InAppMessaging
instance is associated with.
isAutomaticDataCollectionEnabled β
firebase().inAppMessaging().isAutomaticDataCollectionEnabled =true
For the description of this property, see isAutomaticDataCollectionEnabled on the Firebase documentation.
isMessagesDisplaySuppressed β
firebase().inAppMessaging().isMessagesDisplaySuppressed =true
// or
firebase().inAppMessaging().isMessagesDisplaySuppressed =false
For the description of this property, see areMessagesSuppressed on the Firebase documentation.
triggerEvent() β
firebase().inAppMessaging().triggerEvent(eventId)
Parameter | Type | Description |
---|---|---|
eventId | string | The name of the event to trigger. |
For the description of this method, see triggerEvent on the Firebase documentation.
License β
Apache License Version 2.0
- Previous
- Functions
- Next
- Installations