├── src ├── ios │ ├── FirebaseInappMessagingPlugin.h │ └── FirebaseInappMessagingPlugin.m └── android │ └── FirebaseInappMessagingPlugin.java ├── .github └── FUNDING.yml ├── types ├── index.d.ts └── FirebaseInappMessaging.d.ts ├── tsconfig.json ├── .gitignore ├── LICENSE ├── www └── FirebaseInappMessaging.js ├── package.json ├── plugin.xml └── README.md /src/ios/FirebaseInappMessagingPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface FirebaseInappMessagingPlugin : CDVPlugin 4 | 5 | @end -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K7CE5R3PAPT9A&source=url 4 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | interface CordovaPlugins { 2 | firebase: FirebasePlugins; 3 | } 4 | 5 | interface FirebasePlugins { 6 | inappmessaging: typeof import("./FirebaseInappMessaging"); 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "typedocOptions": { 3 | "out": "docs", 4 | "readme": "none", 5 | "entryPoints": "./types", 6 | "exclude": "./types/index.d.ts", 7 | "entryPointStrategy": "expand", 8 | "hideBreadcrumbs": true, 9 | "hideInPageTOC": true, 10 | "hidePageTitle": true, 11 | "hideMembersSymbol": true, 12 | "disableSources": true, 13 | "githubPages": false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | .DS_Store 40 | /docs 41 | -------------------------------------------------------------------------------- /types/FirebaseInappMessaging.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Enables, disables, or clears automatic data collection for Firebase In-App Messaging 3 | * @param {boolean} collectionEnabled Whether automatic collection is enabled 4 | * @returns {Promise} Callback when operation is completed 5 | * 6 | * @example 7 | * cordova.plugins.firebase.inappmessaging.setAutomaticDataCollectionEnabled(true); 8 | */ 9 | export function setAutomaticDataCollectionEnabled(collectionEnabled: boolean): Promise; 10 | /** 11 | * Enables or disables suppression of Firebase In App Messaging messages. 12 | * @param {boolean} messagesSupressed Whether messages are suppressed 13 | * @returns {Promise} Callback when operation is completed 14 | * 15 | * @example 16 | * cordova.plugins.firebase.inappmessaging.setMessagesSuppressed(true); 17 | */ 18 | export function setMessagesSuppressed(messagesSupressed: boolean): Promise; 19 | -------------------------------------------------------------------------------- /src/ios/FirebaseInappMessagingPlugin.m: -------------------------------------------------------------------------------- 1 | #import "FirebaseInappMessagingPlugin.h" 2 | 3 | @import FirebaseInAppMessaging; 4 | 5 | @implementation FirebaseInappMessagingPlugin 6 | 7 | - (void)setAutomaticDataCollectionEnabled:(CDVInvokedUrlCommand *)command { 8 | bool collectionEnabled = [[command.arguments objectAtIndex:0] boolValue]; 9 | 10 | [FIRInAppMessaging inAppMessaging].automaticDataCollectionEnabled = collectionEnabled; 11 | 12 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 13 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 14 | } 15 | 16 | - (void)setMessagesSuppressed:(CDVInvokedUrlCommand *)command { 17 | bool messagesSuppressed = [[command.arguments objectAtIndex:0] boolValue]; 18 | 19 | [FIRInAppMessaging inAppMessaging].messageDisplaySuppressed = messagesSuppressed; 20 | 21 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 22 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Maksim Chemerisuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/android/FirebaseInappMessagingPlugin.java: -------------------------------------------------------------------------------- 1 | package by.chemerisuk.cordova.firebase; 2 | 3 | import com.google.firebase.inappmessaging.FirebaseInAppMessaging; 4 | 5 | import org.apache.cordova.CallbackContext; 6 | import org.apache.cordova.CordovaArgs; 7 | import org.json.JSONException; 8 | 9 | import by.chemerisuk.cordova.support.CordovaMethod; 10 | import by.chemerisuk.cordova.support.ReflectiveCordovaPlugin; 11 | 12 | public class FirebaseInappMessagingPlugin extends ReflectiveCordovaPlugin { 13 | @CordovaMethod 14 | private void setAutomaticDataCollectionEnabled(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 15 | boolean collectionEnabled = args.getBoolean(0); 16 | FirebaseInAppMessaging.getInstance().setAutomaticDataCollectionEnabled(collectionEnabled); 17 | callbackContext.success(); 18 | } 19 | 20 | @CordovaMethod 21 | private void setMessagesSuppressed(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 22 | boolean messagesSuppressed = args.getBoolean(0); 23 | FirebaseInAppMessaging.getInstance().setMessagesSuppressed(messagesSuppressed); 24 | callbackContext.success(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /www/FirebaseInappMessaging.js: -------------------------------------------------------------------------------- 1 | var PLUGIN_NAME = "FirebaseInappMessaging"; 2 | // @ts-ignore 3 | var exec = require("cordova/exec"); 4 | 5 | exports.setAutomaticDataCollectionEnabled = 6 | /** 7 | * Enables, disables, or clears automatic data collection for Firebase In-App Messaging 8 | * @param {boolean} collectionEnabled Whether automatic collection is enabled 9 | * @returns {Promise} Callback when operation is completed 10 | * 11 | * @example 12 | * cordova.plugins.firebase.inappmessaging.setAutomaticDataCollectionEnabled(true); 13 | */ 14 | function(collectionEnabled) { 15 | return new Promise(function(resolve, reject) { 16 | exec(resolve, reject, PLUGIN_NAME, "setAutomaticDataCollectionEnabled", [collectionEnabled]); 17 | }); 18 | }; 19 | 20 | exports.setMessagesSuppressed = 21 | /** 22 | * Enables or disables suppression of Firebase In App Messaging messages. 23 | * @param {boolean} messagesSupressed Whether messages are suppressed 24 | * @returns {Promise} Callback when operation is completed 25 | * 26 | * @example 27 | * cordova.plugins.firebase.inappmessaging.setMessagesSuppressed(true); 28 | */ 29 | function(messagesSupressed) { 30 | return new Promise(function(resolve, reject) { 31 | exec(resolve, reject, PLUGIN_NAME, "setMessagesSuppressed", [messagesSupressed]); 32 | }); 33 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-firebase-inappmessaging", 3 | "version": "8.0.0", 4 | "description": "Cordova plugin for Firebase In-App Messaging", 5 | "types": "./types/index.d.ts", 6 | "cordova": { 7 | "id": "cordova-plugin-firebase-inappmessaging", 8 | "platforms": [ 9 | "ios", 10 | "android" 11 | ] 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging.git" 16 | }, 17 | "author": "Maksim Chemerisuk (https://github.com/chemerisuk)", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging/issues" 21 | }, 22 | "homepage": "https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging#readme", 23 | "funding": "https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging?sponsor=1", 24 | "keywords": [ 25 | "cordova", 26 | "firebase", 27 | "in-app messaging", 28 | "ecosystem:cordova", 29 | "cordova-android", 30 | "cordova-ios" 31 | ], 32 | "scripts": { 33 | "preversion": "npm run docs && rm -rf docs", 34 | "version": "perl -i -pe 's/(version=)\"\\d+\\.\\d+\\.\\d+\"/$1\"'$npm_package_version'\"$2/' plugin.xml && git add .", 35 | "postversion": "git push && git push --tags", 36 | "predocs": "tsc www/* --declaration --allowJs --checkJs --lib es2015,dom --emitDeclarationOnly --outDir types", 37 | "docs": "typedoc && perl -i -pe 's/README.md#/#/g' ./docs/README.md", 38 | "postdocs": "perl -i -0pe 's/().*/$1\n\n/gms' README.md && cat ./docs/README.md >> README.md" 39 | }, 40 | "devDependencies": { 41 | "typedoc": "^0.23.9", 42 | "typedoc-plugin-markdown": "^3.13.4" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | cordova-plugin-firebase-inappmessaging 7 | Cordova plugin for Firebase In-App Messaging 8 | MIT 9 | cordova 10 | https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging 11 | https://github.com/chemerisuk/cordova-plugin-firebase-inappmessaging/issues 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 42 | $AUTOMATIC_DATA_COLLECTION_ENABLED 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cordova plugin for [Firebase In-App Messaging](https://firebase.google.com/docs/in-app-messaging) 2 | 3 | [![NPM version][npm-version]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![NPM total downloads][npm-total-downloads]][npm-url] [![PayPal donate](https://img.shields.io/badge/paypal-donate-ff69b4?logo=paypal)][donate-url] [![Twitter][twitter-follow]][twitter-url] 4 | 5 | | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)][donate-url] | Your help is appreciated. Create a PR, submit a bug or just grab me :beer: | 6 | |-|-| 7 | 8 | [npm-url]: https://www.npmjs.com/package/cordova-plugin-firebase-inappmessaging 9 | [npm-version]: https://img.shields.io/npm/v/cordova-plugin-firebase-inappmessaging.svg 10 | [npm-downloads]: https://img.shields.io/npm/dm/cordova-plugin-firebase-inappmessaging.svg 11 | [npm-total-downloads]: https://img.shields.io/npm/dt/cordova-plugin-firebase-inappmessaging.svg?label=total+downloads 12 | [twitter-url]: https://twitter.com/chemerisuk 13 | [twitter-follow]: https://img.shields.io/twitter/follow/chemerisuk.svg?style=social&label=Follow%20me 14 | [donate-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K7CE5R3PAPT9A&source=url 15 | 16 | ## Index 17 | 18 | 19 | 20 | - [Supported Platforms](#supported-platforms) 21 | - [Installation](#installation) 22 | - [Disabling automatic data collection](#disabling-automatic-data-collection) 23 | - [Adding required configuration files](#adding-required-configuration-files) 24 | - [Functions](#functions) 25 | - [setAutomaticDataCollectionEnabled](#setautomaticdatacollectionenabled) 26 | - [setMessagesSuppressed](#setmessagessuppressed) 27 | 28 | 29 | 30 | ## Supported Platforms 31 | 32 | - iOS 33 | - Android 34 | 35 | ## Installation 36 | 37 | cordova plugin add cordova-plugin-firebase-inappmessaging 38 | 39 | Use variables `IOS_FIREBASE_POD_VERSION` and `ANDROID_FIREBASE_BOM_VERSION` to override dependency versions for Firebase SDKs: 40 | 41 | $ cordova plugin add cordova-plugin-firebase-inappmessaging \ 42 | --variable IOS_FIREBASE_POD_VERSION="9.3.0" \ 43 | --variable ANDROID_FIREBASE_BOM_VERSION="30.3.1" 44 | 45 | ### Disabling automatic data collection 46 | By default, Firebase In-App Messaging automatically delivers messages to all app users you target in messaging campaigns. To deliver those messages, the Firebase In-App Messaging SDK uses Firebase installation IDs to identify each user's app. This means that In-App Messaging has to send client data, linked to the installation ID, to Firebase servers. If you'd like to give users more control over the data they send, disable automatic data collection and give them a chance to approve data sharing. 47 | 48 | Set variable `AUTOMATIC_DATA_COLLECTION_ENABLED` to `false` to prevent collecting any user data: 49 | 50 | $ cordova plugin add cordova-plugin-firebase-inappmessaging \ 51 | --variable AUTOMATIC_DATA_COLLECTION_ENABLED=false 52 | 53 | Later you can re-enable automatic data collection (for instance after getting end-user consent) using method [setAutomaticDataCollectionEnabled](#setautomaticdatacollectionenabled). Once you set a data collection preference manually, the value persists through app restarts, overriding the value in your `AndroidManifest.xml`. If you'd like to disable initialization again, for example if a user opts out of collection later, pass `false` to the `setAutomaticDataCollectionEnabled` method. 54 | 55 | ### Adding required configuration files 56 | 57 | Cordova supports `resource-file` tag for easy copying resources files. Firebase SDK requires `google-services.json` on Android and `GoogleService-Info.plist` on iOS platforms. 58 | 59 | 1. Put `google-services.json` and/or `GoogleService-Info.plist` into the root directory of your Cordova project 60 | 2. Add new tag for Android platform 61 | 62 | ```xml 63 | 64 | ... 65 | 66 | 67 | ... 68 | 69 | ... 70 | 71 | 72 | ``` 73 | 74 | This way config files will be copied on `cordova prepare` step. 75 | 76 | 77 | 78 | ## Functions 79 | 80 | ### setAutomaticDataCollectionEnabled 81 | 82 | **setAutomaticDataCollectionEnabled**(`collectionEnabled`): `Promise`<`void`\> 83 | 84 | Enables, disables, or clears automatic data collection for Firebase In-App Messaging 85 | 86 | **`Example`** 87 | 88 | ```ts 89 | cordova.plugins.firebase.inappmessaging.setAutomaticDataCollectionEnabled(true); 90 | ``` 91 | 92 | #### Parameters 93 | 94 | | Name | Type | Description | 95 | | :------ | :------ | :------ | 96 | | `collectionEnabled` | `boolean` | Whether automatic collection is enabled | 97 | 98 | #### Returns 99 | 100 | `Promise`<`void`\> 101 | 102 | Callback when operation is completed 103 | 104 | ___ 105 | 106 | ### setMessagesSuppressed 107 | 108 | **setMessagesSuppressed**(`messagesSupressed`): `Promise`<`void`\> 109 | 110 | Enables or disables suppression of Firebase In App Messaging messages. 111 | 112 | **`Example`** 113 | 114 | ```ts 115 | cordova.plugins.firebase.inappmessaging.setMessagesSuppressed(true); 116 | ``` 117 | 118 | #### Parameters 119 | 120 | | Name | Type | Description | 121 | | :------ | :------ | :------ | 122 | | `messagesSupressed` | `boolean` | Whether messages are suppressed | 123 | 124 | #### Returns 125 | 126 | `Promise`<`void`\> 127 | 128 | Callback when operation is completed 129 | --------------------------------------------------------------------------------