Capacitor plugin for Firebase Remote Config.
npm install @capacitor-firebase/remote-configUnofficial Capacitor plugin for Firebase Remote Config.[^1]
| Plugin Version | Capacitor Version | Status |
| -------------- | ----------------- | -------------- |
| 8.x.x | >=8.x.x | Active support |
| 7.x.x | 7.x.x | Deprecated |
| 6.x.x | 6.x.x | Deprecated |
| 5.x.x | 5.x.x | Deprecated |
``bash`
npm install @capacitor-firebase/remote-config firebase
npx cap sync
Add Firebase to your project if you haven't already (Android / iOS / Web).
Google Analytics is required for the conditional targeting of app instances to user properties and audiences. Make sure that you install the Capacitor Firebase Analytics plugin in your project.
#### Variables
If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:
- $firebaseConfigVersion version of com.google.firebase:firebase-config (default: 23.0.1)
This can be useful if you encounter dependency conflicts with other plugins in your project.
No configuration required for this plugin.
A working example can be found here: robingenz/capacitor-firebase-plugin-demo
The following starter templates are available:
`typescript
import { FirebaseRemoteConfig } from '@capacitor-firebase/remote-config';
const activate = async () => {
await FirebaseRemoteConfig.activate();
};
const fetchAndActivate = async () => {
await FirebaseRemoteConfig.fetchAndActivate();
};
const fetchConfig = async () => {
await FirebaseRemoteConfig.fetchConfig({
minimumFetchIntervalInSeconds: 1200,
});
};
const getBoolean = async () => {
const { value } = await FirebaseRemoteConfig.getBoolean({
key: 'is_sale',
});
return value;
};
const getNumber = async () => {
const { value } = await FirebaseRemoteConfig.getNumber({
key: 'upcoming_maintenance',
});
return value;
};
const getString = async () => {
const { value } = await FirebaseRemoteConfig.getString({
key: 'license_key',
});
return value;
};
const setSettings = async () => {
await FirebaseRemoteConfig.setSettings({
fetchTimeoutInSeconds: 10,
minimumFetchIntervalInSeconds: 0,
});
};
const addConfigUpdateListener = async () => {
const callbackId = await FirebaseRemoteConfig.addConfigUpdateListener(
(event, error) => {
if (error) {
console.error(error);
} else {
console.log(event);
}
}
);
return callbackId;
};
const removeConfigUpdateListener = async (callbackId: string) => {
await FirebaseRemoteConfig.removeConfigUpdateListener({
callbackId,
});
};
const removeAllListeners = async () => {
await FirebaseRemoteConfig.removeAllListeners();
};
`
* activate()
* fetchAndActivate()
* fetchConfig(...)
* getBoolean(...)
* getNumber(...)
* getString(...)
* getInfo()
* setMinimumFetchInterval(...)
* setSettings(...)
* addConfigUpdateListener(...)
* removeConfigUpdateListener(...)
* removeAllListeners()
* Interfaces
* Type Aliases
* Enums
`typescript`
activate() => Promise
Make the last fetched configuration available to the getters.
Since: 1.3.0
--------------------
`typescript`
fetchAndActivate() => Promise
Perform fetch and activate operations.
Since: 1.3.0
--------------------
`typescript`
fetchConfig(options?: FetchConfigOptions | undefined) => Promise
Fetch and cache configuration from the Remote Config service.
| Param | Type |
| ------------- | ----------------------------------------------------------------- |
| options | FetchConfigOptions |
Since: 1.3.0
--------------------
`typescript`
getBoolean(options: GetBooleanOptions) => Promise
Get the value for the given key as a boolean.
| Param | Type |
| ------------- | ------------------------------------------------- |
| options | GetOptions |
Returns: Promise<GetBooleanResult>
Since: 1.3.0
--------------------
`typescript`
getNumber(options: GetNumberOptions) => Promise
Get the value for the given key as a number.
| Param | Type |
| ------------- | ------------------------------------------------- |
| options | GetOptions |
Returns: Promise<GetNumberResult>
Since: 1.3.0
--------------------
`typescript`
getString(options: GetStringOptions) => Promise
Get the value for the given key as a string.
| Param | Type |
| ------------- | ------------------------------------------------- |
| options | GetOptions |
Returns: Promise<GetStringResult>
Since: 1.3.0
--------------------
`typescript`
getInfo() => Promise
Get information about the last fetch operation.
Returns: Promise<GetInfoResult>
Since: 7.5.0
--------------------
`typescript`
setMinimumFetchInterval(options: SetMinimumFetchIntervalOptions) => Promise
Set the minimum fetch interval.
Only available for Web.
| Param | Type |
| ------------- | ----------------------------------------------------------------------------------------- |
| options | SetMinimumFetchIntervalOptions |
Since: 1.3.0
--------------------
`typescript`
setSettings(options: SetSettingsOptions) => Promise
Set the remote config settings.
On Android, the settings values are persisted in SharedPreferences.
| Param | Type |
| ------------- | ----------------------------------------------------------------- |
| options | SetSettingsOptions |
Since: 6.2.0
--------------------
`typescript`
addConfigUpdateListener(callback: AddConfigUpdateListenerOptionsCallback) => Promise
Add a listener for the config update event.
Only available for Android and iOS.
| Param | Type |
| -------------- | --------------------------------------------------------------------------------------------------------- |
| callback | AddConfigUpdateListenerOptionsCallback |
Returns: Promise<string>
Since: 5.4.0
--------------------
`typescript`
removeConfigUpdateListener(options: RemoveConfigUpdateListenerOptions) => Promise
Remove a listener for the config update event.
Only available for Android and iOS.
| Param | Type |
| ------------- | ----------------------------------------------------------------------------------------------- |
| options | RemoveConfigUpdateListenerOptions |
Since: 5.4.0
--------------------
`typescript`
removeAllListeners() => Promise
Remove all listeners for this plugin.
Since: 5.4.0
--------------------
#### FetchConfigOptions
| Prop | Type | Description | Default | Since |
| ----------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| minimumFetchIntervalInSeconds | number | Define the maximum age in seconds of an entry in the config cache before it is considered stale. During development, it's recommended to set a relatively low minimum fetch interval. Only available for Android and iOS. | 43200 | 1.3.0 |
#### GetBooleanResult
| Prop | Type | Description | Since |
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| value | boolean | The value for the given key as a boolean. | 1.3.0 |
| source | GetValueSource | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
#### GetOptions
| Prop | Type | Description | Since |
| --------- | ------------------- | ---------------------------- | ----- |
| key | string | The key of the value to get. | 1.3.0 |
#### GetNumberResult
| Prop | Type | Description | Since |
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| value | number | The value for the given key as a number. | 1.3.0 |
| source | GetValueSource | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
#### GetStringResult
| Prop | Type | Description | Since |
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| value | string | The value for the given key as a string. | 1.3.0 |
| source | GetValueSource | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
#### GetInfoResult
| Prop | Type | Description | Since |
| --------------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----- |
| lastFetchTime | number | The Unix timestamp in milliseconds of the last successful fetch, or -1 if no fetch has occurred or initialization is incomplete. | 7.5.0 |
| lastFetchStatus | LastFetchStatus | The status of the last fetch attempt. | 7.5.0 |
#### SetMinimumFetchIntervalOptions
| Prop | Type | Description | Default | Since |
| ----------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| minimumFetchIntervalInSeconds | number | Define the maximum age in seconds of an entry in the config cache before it is considered stale. During development, it's recommended to set a relatively low minimum fetch interval. | 43200 | 1.3.0 |
#### SetSettingsOptions
| Prop | Type | Description | Default | Since |
| ----------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| fetchTimeoutInSeconds | number | Defines the maximum amount of milliseconds to wait for a response when fetching configuration from the Remote Config server. | 60 | 6.2.0 |
| minimumFetchIntervalInSeconds | number | Define the maximum age in seconds of an entry in the config cache before it is considered stale. During development, it's recommended to set a relatively low minimum fetch interval. | 43200 | 6.2.0 |
#### AddConfigUpdateListenerOptionsCallbackEvent
| Prop | Type | Description | Since |
| ----------------- | --------------------- | ---------------------------------------------------------------------------------- | ----- |
| updatedKeys | string[] | Parameter keys whose values have been updated from the currently activated values. | 5.4.0 |
#### RemoveConfigUpdateListenerOptions
| Prop | Type | Description | Since |
| -------- | ------------------------------------------------- | --------------------------------- | ----- |
| id | CallbackId | The id of the listener to remove. | 5.4.0 |
#### GetBooleanOptions
#### GetNumberOptions
#### GetStringOptions
#### AddConfigUpdateListenerOptionsCallback
(event: AddConfigUpdateListenerOptionsCallbackEvent | null, error: any): void
#### CallbackId
string
#### GetValueSource
| Members | Value | Description | Since |
| ------------- | -------------- | --------------------------------------------------------------------------------------- | ----- |
| Static | 0 | Indicates that the value returned is the static default value. | 1.3.0 |
| Default | 1 | Indicates that the value returned was retrieved from the defaults set by the client. | 1.3.0 |
| Remote | 2 | Indicates that the value returned was retrieved from the Firebase Remote Config Server. | 1.3.0 |
#### LastFetchStatus
| Members | Value |
| ---------------- | -------------- |
| NoFetchYet | 0 |
| Success | 1 |
| Failure | 2 |
| Throttled` | 3 |
See CHANGELOG.md.
See LICENSE.
[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.