Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firebase_in_app_messaging)!: federate & rework plugin #7345

Merged
merged 26 commits into from Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ca19a5a
chore: setup federated package
Ehesp Nov 9, 2021
0dedba8
chore: setup delegation flow
Ehesp Nov 9, 2021
c77960a
chore: match native channel names
Ehesp Nov 11, 2021
84e0933
Merge branch 'master' into @invertase/fiam-rework
Ehesp Nov 11, 2021
92dda96
chore: add tests
Ehesp Nov 15, 2021
9eae21b
fix: tests and ci
pr-Mais Nov 16, 2021
b6fdd01
chore: platform interface CHANGELOG
pr-Mais Nov 16, 2021
d35a0e2
fix: method channel delegateFor
pr-Mais Nov 16, 2021
6b004e3
fix: example app
pr-Mais Nov 16, 2021
97442c8
chore: remove training comma ignore
pr-Mais Nov 16, 2021
c909f0b
chore: remove duplicate license header
pr-Mais Nov 16, 2021
c014112
fix: required trainling comma
pr-Mais Nov 17, 2021
c56b85d
chore: example app formatting
pr-Mais Nov 17, 2021
d372954
docs: fiam overview
pr-Mais Nov 17, 2021
6f03996
feat: update Firebase example app
pr-Mais Nov 18, 2021
cbbc577
docs: usage
pr-Mais Nov 18, 2021
99461ad
docs: fix warnings
pr-Mais Nov 18, 2021
b9d34cc
docs: installation ID section
pr-Mais Nov 18, 2021
6d1400b
docs(in-app): update README.md
russellwheatley Dec 2, 2021
935a94d
Merge branch 'dev' of https://github.com/FirebaseExtended/flutterfire…
pr-Mais Dec 4, 2021
e306073
Restore project.pbxproj
Salakar Dec 4, 2021
c70c3d0
Delete GoogleService-Info.plist
Salakar Dec 4, 2021
ec5b3b7
Merge branch 'dev' into @invertase/fiam-rework
Salakar Dec 4, 2021
634a483
cleanup
Salakar Dec 6, 2021
b82888c
ci: setup ci workflow
Salakar Dec 6, 2021
3150cad
fix: native is sent a map for 2 methods, not bools
Salakar Dec 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/firebase_in_app_messaging.yaml
@@ -0,0 +1,63 @@
name: firebase_in_app_messaging

on:
pull_request:
paths:
- "packages/firebase_in_app_messaging/**"
- ".github/workflows/firebase_in_app_messaging.yaml"
# Ensure this workflow runs if the Firebase Android SDK version gets bumped.
- "packages/firebase_core/firebase_core/android/gradle.properties"
# Ensure this workflow runs if the Firebase iOS SDK version gets bumped.
- "packages/firebase_core/firebase_core/ios/firebase_sdk_version.rb"
push:
branches:
- master
paths-ignore:
- "docs/**"
- "**.md"

env:
FLUTTERFIRE_PLUGIN_SCOPE: "*firebase_in_app_messaging*"
FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE: "*firebase_in_app_messaging_example*"

jobs:
android:
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: "Install Tools"
run: ./.github/workflows/scripts/install-tools.sh
- name: "Build Example"
run: ./.github/workflows/scripts/build-example.sh android
- name: "Drive Example"
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
# Firebase Dynamic Links requires Google Play Services, so we use the `google_apis`
target: google_apis
profile: Nexus 5X
script: ./.github/workflows/scripts/drive-example.sh android

ios:
runs-on: macos-latest
timeout-minutes: 35
steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: "Install Tools"
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-macos-desktop
- name: "Build iOS Example"
run: ./.github/workflows/scripts/build-example.sh ios
- name: "Drive iOS Example"
run: ./.github/workflows/scripts/drive-example.sh ios
111 changes: 111 additions & 0 deletions docs/in-app-messaging/overview.mdx
@@ -0,0 +1,111 @@
---
title: In-App Messaging
sidebar_label: Overview
---

## What does it do?

Firebase In-App Messaging helps you engage your app's active users by sending them targeted,
contextual messages that encourage them to use key app features. For example, you could send
an in-app message to get users to subscribe, watch a video, complete a level, or buy an item.
You can customize messages as cards, banners, modals, or images, and set up triggers so that
they appear exactly when they'd benefit your users most.
Use Firebase In-App Messaging to encourage exploration and discovery: highlight a sale or
coupon in your ecommerce app, give clues or tips in your game, or prompt a like or share in
your social media app.

<YouTube id="5MRKpvKV2pg" />

## Installation

Before installing the In-App Messaging for Firebase plugin, ensure that you have followed the [Getting Started](../overview.mdx) documentation
and have initialized FlutterFire.

<Tabs
groupId="legacy-or-nullsafe"
defaultValue="legacy"
values={[
{ label: "Legacy", value: "legacy" },
{ label: "Null safety", value: "null-safe" },
]}
>
<TabItem value="legacy">

For legacy package imports, place the following ignore comment to hide Dart analyzer warnings:

```dart
// ignore: import_of_legacy_library_into_null_safe
import 'package:firebase-in-app-messaging/firebase-in-app-messaging.dart';
```

</TabItem>
<TabItem value="null-safe">

Ensure you're using the Flutter `stable` channel:

```bash
$ flutter channel stable
```

If your app is mixing legacy and null-safe packages, use the `--no-sound-null-safety` flag:

```bash
$ flutter run --no-sound-null-safety
```

</TabItem>
</Tabs>

### 1. Add dependency

<Tabs
groupId="legacy-or-nullsafe"
defaultValue="legacy"
values={[
{ label: "Legacy", value: "legacy" },
{ label: "Null safety", value: "null-safe" },
]}
>
<TabItem value="legacy">

```yaml {5} title="pubspec.yaml"
dependencies:
flutter:
sdk: flutter
firebase_core: '^{{ plugins.firebase_core }}'
firebase_in_app_messaging: '^{{ plugins.firebase_in_app_messaging }}'
```

</TabItem>
<TabItem value="null-safe">

```yaml {5} title="pubspec.yaml"
dependencies:
flutter:
sdk: flutter
firebase_core: '^{{ plugins.firebase_core_ns }}'
firebase_in_app_messaging: '^{{ plugins.firebase_in_app_messaging_ns }}'
```

</TabItem>
</Tabs>

### 2. Download dependency

```
$ flutter pub get
```

### 3. Rebuild your app

Once complete, rebuild your Flutter application:

```bash
$ flutter run
```

## Next Steps

Once installed, you're ready to start using In-App Messaging in your Flutter Project.

View the [Usage documentation](usage.mdx) to get started.
63 changes: 62 additions & 1 deletion docs/in-app-messaging/usage.mdx
Expand Up @@ -3,4 +3,65 @@ title: In-App Messaging
sidebar_label: Usage
---

In-App Messaging 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 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](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.
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](../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.
7 changes: 6 additions & 1 deletion docs/sidebars.js
Expand Up @@ -110,7 +110,12 @@ module.exports = {
],
// "Dynamic Links": ["dynamic-links/usage", toReferenceAPI("firebase_dynamic_links")],
// "Instance ID": ["iid/usage", toReferenceAPI("firebase_in_app_messaging")],
// "In-App Messaging": ["in-app-messaging/usage", toReferenceAPI("firebase_in_app_messaging")],
"In-App Messaging": [
"in-app-messaging/overview",
"in-app-messaging/usage",
toReferenceAPI("firebase_in_app_messaging"),
toGithubExample("firebase_in_app_messaging"),
],
// "ML Kit Natural Language": ["ml-language/usage"],
// "ML Kit Vision": ["ml-vision/usage", toReferenceAPI("firebase_ml_vision")],
"Remote Config": [
Expand Down
@@ -1,92 +1,24 @@
# firebase_in_app_messaging plugin
# Firebase In-App Messaging Plugin for Flutter

A Flutter plugin to use the [Firebase In-App Messaging API](https://firebase.google.com/products/in-app-messaging).
A Flutter plugin to use the [Firebase In-App Messaging API](https://firebase.google.com/docs/in-app-messaging/).

For Flutter plugins for other Firebase products, see [README.md](https://github.com/FirebaseExtended/flutterfire/blob/master/README.md).
To learn more about Firebase In-App Messaging, please visit the [Firebase website](https://firebase.google.com/products/in-app-messaging)

## Usage

### Import the firebase_in_app_messaging plugin
To use the firebase_in_app_messaging plugin, follow the [plugin installation instructions](https://pub.dev/packages/firebase_in_app_messaging#pub-pkg-tab-installing).

### Android integration

There are a few extra steps required for the Android integration. Enable the Google services by configuring the Gradle scripts as such.

1. Add the classpath to the `[project]/android/build.gradle` file.
```gradle
dependencies {
// Example existing classpath
classpath 'com.android.tools.build:gradle:3.5.4'
// Add the google services classpath
classpath 'com.google.gms:google-services:4.3.4'
}
```

2. Add the apply plugin to the `[project]/android/app/build.gradle` file.
```gradle
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
```

*Note:* If this section is not completed you will get an error like this:
```
java.lang.IllegalStateException:
Default FirebaseApp is not initialized in this process [package name].
Make sure to call FirebaseApp.initializeApp(Context) first.
```

*Note:* When you are debugging on Android, use a device or AVD with Google Play services.
Otherwise you will not be able to use Firebase In-App Messaging.

### Use the plugin

To show In-App Messages in your app, no extra setup is required - just import the plugin and you
are good to go. However, to modify message behavior (as documented [here](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior)), the plugin provides the following methods -

First off, add the following imports to your Dart code:
```dart
import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';
```
[![pub package](https://img.shields.io/pub/v/cloud_firestore.svg)](https://pub.dev/packages/firebase_in_app_messaging)

#### Programmatic Triggers ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#trigger_in-app_messages_programmatically))
## Getting Started

To trigger in-app messages programmatically
To get started with Firebase In-App Messaging for Flutter, please [see the documentation](https://firebase.flutter.dev/docs/in-app-messaging/overview).

```dart
FirebaseInAppMessaging.instance.triggerEvent('eventName');
```

#### Temporarily disable in-app messages ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#temporarily_disable_in-app_messages))

If you'd like to suppress message displays for any reason, for example to avoid interrupting a sequence of payment processing screens, you can do that the following

```dart
FirebaseInAppMessaging.instance.setMessagesSuppressed(true);


// To re-enable
FirebaseInAppMessaging.instance.setMessagesSuppressed(false);
```

#### Enable opt-out message delivery ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#enable_opt-out_message_delivery))

First, follow the step outlined [here](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior#enable_opt-out_message_delivery) for both iOS and Android. Then add the following code in your app:

```dart
FirebaseInAppMessaging.instance.setAutomaticDataCollectionEnabled(false);
```

## Example
## Usage

See the [example application](https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_in_app_messaging/example) source
for a complete sample app using the Firebase In-App Messaging.
To use this plugin, please visit the [Firebase In-App Messaging Usage documentation](https://firebase.flutter.dev/docs/in-app-messaging/usage)

## Issues and feedback

Please file FlutterFire specific issues, bugs, or feature requests in our [issue tracker](https://github.com/FirebaseExtended/flutterfire/issues/new).

Plugin issues that are not specific to Flutterfire can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).
Plugin issues that are not specific to FlutterFire can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).

To contribute a change to this plugin,
please review our [contribution guide](https://github.com/FirebaseExtended/flutterfire/blob/master/CONTRIBUTING.md)
Expand Down
Expand Up @@ -45,23 +45,23 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
@Override
public void onMethodCall(MethodCall call, Result result) {
switch (call.method) {
case "triggerEvent":
case "FirebaseInAppMessaging#triggerEvent":
{
String eventName = call.argument("eventName");
instance.triggerEvent(eventName);
result.success(null);
break;
}
case "setMessagesSuppressed":
case "FirebaseInAppMessaging#setMessagesSuppressed":
{
Boolean suppress = (Boolean) call.arguments;
Boolean suppress = (Boolean) call.argument("suppress");
instance.setMessagesSuppressed(suppress);
result.success(null);
break;
}
case "setAutomaticDataCollectionEnabled":
case "FirebaseInAppMessaging#setAutomaticDataCollectionEnabled":
{
Boolean enabled = (Boolean) call.arguments;
Boolean enabled = (Boolean) call.argument("enabled");
instance.setAutomaticDataCollectionEnabled(enabled);
result.success(null);
break;
Expand Down
@@ -1,4 +1,4 @@
# firebase_in_app_messaging_example

Demonstrates how to use the firebase_in_app_messaging plugin.
Demonstrates how to use the `firebase_in_app_messaging` plugin.