Skip to content

Commit

Permalink
docs: usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pr-Mais committed Nov 18, 2021
1 parent 6f03996 commit cbbc577
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
56 changes: 56 additions & 0 deletions docs/in-app-messaging/usage.mdx
Expand Up @@ -4,3 +4,59 @@ sidebar_label: Usage
---

# Using Firebase In-App Messaging

Once installed, you can access the [`firebase_in_app_messaging`](!firebase_in_app_messaging) plugin by importing it in your Dart code:

```dart
import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';
```

Before using Firebase In-App Messaging, ensure that you have [initialized FlutterFire](../overview.mdx#initializing-flutterfire).

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

```dart
FirebaseInAppMessaging fiam = FirebaseInAppMessaging.instance;
```

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

Once the plugin is setup, you're ready to receive messages from the console campaigns.
**[Click here to learn how to create In-App Messaging campaigns](https://firebase.google.com/docs/in-app-messaging/compose-campaign)**.

## Sending In-App Test Messages

As stated in the [Firebase official docs](https://firebase.google.com/docs/in-app-messaging/get-started?authuser=0&platform=android#send_a_test_message), 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,
using the **Firebase Installation ID** which will show in console when you run your app in debug mode.

## Trigger In-App Messages with Analytics Events

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

1. Setup Firebae Analytics in your app by following [this guide](../analytics/overview.mdx#initializing-flutterfire).
2. Trigger an Analytics event.

```dart
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:

```dart
fiam.triggerEvent('some_event');
```

You can specify the name of the event by adding it while creating your campaign.
Expand Up @@ -19,7 +19,6 @@ Future<void> main() async {
class MyApp extends StatelessWidget {
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
static FirebaseInAppMessaging fiam = FirebaseInAppMessaging.instance;

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down Expand Up @@ -64,11 +63,13 @@ class ProgrammaticTriggersExample extends StatelessWidget {
const Text('Manually trigger events programmatically '),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () {
MyApp.fiam.triggerEvent('chicken_event');
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Triggering event: chicken_event'),
));
onPressed: () async {
await MyApp.fiam.triggerEvent('awesome_event');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Triggering event: awesome_event'),
),
);
},
style: ElevatedButton.styleFrom(primary: Colors.blue),
child: Text(
Expand All @@ -88,7 +89,7 @@ class AnalyticsEventExample extends StatelessWidget {
await MyApp.analytics.logEvent(
name: 'awesome_event',
parameters: <String, dynamic>{
'int': 42, // not required?
//'id': 1, // not required?
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions website/dictionary.js
Expand Up @@ -90,4 +90,6 @@ module.exports = [
'web.firebase_cdn',
'xml',
'yaml',
'fiam',
'ecommerce'
];

0 comments on commit cbbc577

Please sign in to comment.