Back to Firebase Js Sdk

remote-config package

docs-devsite/remote-config.md

12.12.117.3 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

remote-config package

The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environment.

Functions

FunctionDescription
<b>function(app, ...)</b>
getRemoteConfig(app, options)
<b>function(remoteConfig, ...)</b>
activate(remoteConfig)Makes the last fetched config available to the getters.
ensureInitialized(remoteConfig)Ensures the last activated config are available to the getters.
fetchAndActivate(remoteConfig)Performs fetch and activate operations, as a convenience.
fetchConfig(remoteConfig)Fetches and caches configuration from the Remote Config service.
getAll(remoteConfig)Gets all config.
getBoolean(remoteConfig, key)Gets the value for the given key as a boolean.<!-- -->Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
getNumber(remoteConfig, key)Gets the value for the given key as a number.<!-- -->Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
getString(remoteConfig, key)Gets the value for the given key as a string. Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
getValue(remoteConfig, key)Gets the Value for the given key.
onConfigUpdate(remoteConfig, observer)Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the Remote Config backend when they are available.
setCustomSignals(remoteConfig, customSignals)Sets the custom signals for the app instance.
setLogLevel(remoteConfig, logLevel)Defines the log level to use.
<b>function()</b>
isSupported()This method provides two different checks:<!-- -->1. Check if IndexedDB exists in the browser environment. 2. Check if the current browser context allows IndexedDB <code>open()</code> calls.

Interfaces

InterfaceDescription
ConfigUpdateContains information about which keys have been updated.
ConfigUpdateObserverObserver interface for receiving real-time Remote Config update notifications.<!-- -->NOTE: Although an <code>complete</code> callback can be provided, it will never be called because the ConfigUpdate stream is never-ending.
CustomSignalsDefines the type for representing custom signals and their values.<p>The values in CustomSignals must be one of the following types:<ul> <li><code>string</code> <li><code>number</code> <li><code>null</code> </ul>
FetchResponseDefines a successful response (200 or 304).<p>Modeled after the native <code>Response</code> interface, but simplified for Remote Config's use case.
FirebaseExperimentDescriptionDefines experiment and variant attached to a config parameter.
FirebaseRemoteConfigObjectDefines a self-descriptive reference for config key-value pairs.
RemoteConfigThe Firebase Remote Config service interface.
RemoteConfigOptionsOptions for Remote Config initialization.
RemoteConfigSettingsDefines configuration options for the Remote Config SDK.
ValueWraps a value with metadata and type-safe getters.

Type Aliases

Type AliasDescription
FetchStatusSummarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.<ul> <li>"no-fetch-yet" indicates the RemoteConfig instance has not yet attempted to fetch config, or that SDK initialization is incomplete.</li> <li>"success" indicates the last attempt succeeded.</li> <li>"failure" indicates the last attempt failed.</li> <li>"throttle" indicates the last attempt was rate-limited.</li> </ul>
FetchTypeIndicates the type of fetch request.<ul> <li>"BASE" indicates a standard fetch request.</li> <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li> </ul>
LogLevelDefines levels of Remote Config logging.
UnsubscribeA function that unsubscribes from a real-time event stream.
ValueSourceIndicates the source of a value.<ul> <li>"static" indicates the value was defined by a static constant.</li> <li>"default" indicates the value was defined by default config.</li> <li>"remote" indicates the value was defined by fetched config.</li> </ul>

function(app, ...)

getRemoteConfig(app, options) {:#getremoteconfig_61d368f}

<b>Signature:</b>

typescript
export declare function getRemoteConfig(app?: FirebaseApp, options?: RemoteConfigOptions): RemoteConfig;

Parameters

ParameterTypeDescription
appFirebaseAppThe FirebaseApp instance.
optionsRemoteConfigOptionsOptional. The RemoteConfigOptions with which to instantiate the Remote Config instance.

<b>Returns:</b>

RemoteConfig

A RemoteConfig instance.

function(remoteConfig, ...)

activate(remoteConfig) {:#activate_722a192}

Makes the last fetched config available to the getters.

<b>Signature:</b>

typescript
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.

<b>Returns:</b>

Promise<boolean>

A Promise which resolves to true if the current call activated the fetched configs. If the fetched configs were already activated, the Promise will resolve to false.

ensureInitialized(remoteConfig) {:#ensureinitialized_722a192}

Ensures the last activated config are available to the getters.

<b>Signature:</b>

typescript
export declare function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.

<b>Returns:</b>

Promise<void>

A Promise that resolves when the last activated config is available to the getters.

fetchAndActivate(remoteConfig) {:#fetchandactivate_722a192}

Performs fetch and activate operations, as a convenience.

<b>Signature:</b>

typescript
export declare function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.

<b>Returns:</b>

Promise<boolean>

A Promise which resolves to true if the current call activated the fetched configs. If the fetched configs were already activated, the Promise will resolve to false.

fetchConfig(remoteConfig) {:#fetchconfig_722a192}

Fetches and caches configuration from the Remote Config service.

<b>Signature:</b>

typescript
export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.

<b>Returns:</b>

Promise<void>

getAll(remoteConfig) {:#getall_722a192}

Gets all config.

<b>Signature:</b>

typescript
export declare function getAll(remoteConfig: RemoteConfig): Record<string, Value>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.

<b>Returns:</b>

Record<string, Value<!-- -->>

All config.

getBoolean(remoteConfig, key) {:#getboolean_476c09f}

Gets the value for the given key as a boolean.

Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.

<b>Signature:</b>

typescript
export declare function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
keystringThe name of the parameter.

<b>Returns:</b>

boolean

The value for the given key as a boolean.

getNumber(remoteConfig, key) {:#getnumber_476c09f}

Gets the value for the given key as a number.

Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.

<b>Signature:</b>

typescript
export declare function getNumber(remoteConfig: RemoteConfig, key: string): number;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
keystringThe name of the parameter.

<b>Returns:</b>

number

The value for the given key as a number.

getString(remoteConfig, key) {:#getstring_476c09f}

Gets the value for the given key as a string. Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.

<b>Signature:</b>

typescript
export declare function getString(remoteConfig: RemoteConfig, key: string): string;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
keystringThe name of the parameter.

<b>Returns:</b>

string

The value for the given key as a string.

getValue(remoteConfig, key) {:#getvalue_476c09f}

Gets the Value for the given key.

<b>Signature:</b>

typescript
export declare function getValue(remoteConfig: RemoteConfig, key: string): Value;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
keystringThe name of the parameter.

<b>Returns:</b>

Value

The value for the given key.

onConfigUpdate(remoteConfig, observer) {:#onconfigupdate_8b13b26}

Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the Remote Config backend when they are available.

If a connection to the Remote Config backend is not already open, calling this method will open it. Multiple listeners can be added by calling this method again, but subsequent calls re-use the same connection to the backend.

<b>Signature:</b>

typescript
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
observerConfigUpdateObserverThe ConfigUpdateObserver to be notified of config updates.

<b>Returns:</b>

Unsubscribe

An Unsubscribe function to remove the listener.

setCustomSignals(remoteConfig, customSignals) {:#setcustomsignals_aeeb95e}

Sets the custom signals for the app instance.

<b>Signature:</b>

typescript
export declare function setCustomSignals(remoteConfig: RemoteConfig, customSignals: CustomSignals): Promise<void>;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
customSignalsCustomSignalsMap (key, value) of the custom signals to be set for the app instance. If a key already exists, the value is overwritten. Setting the value of a custom signal to null unsets the signal. The signals will be persisted locally on the client.

<b>Returns:</b>

Promise<void>

setLogLevel(remoteConfig, logLevel) {:#setloglevel_039a45b}

Defines the log level to use.

<b>Signature:</b>

typescript
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: RemoteConfigLogLevel): void;

Parameters

ParameterTypeDescription
remoteConfigRemoteConfigThe RemoteConfig instance.
logLevelRemoteConfigLogLevelThe log level to set.

<b>Returns:</b>

void

function()

isSupported() {:#issupported}

This method provides two different checks:

  1. Check if IndexedDB exists in the browser environment. 2. Check if the current browser context allows IndexedDB open() calls.

<b>Signature:</b>

typescript
export declare function isSupported(): Promise<boolean>;

<b>Returns:</b>

Promise<boolean>

A Promise which resolves to true if a RemoteConfig instance can be initialized in this environment, or false if it cannot.

FetchStatus

Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.

<ul> <li>"no-fetch-yet" indicates the [RemoteConfig](./remote-config.remoteconfig.md#remoteconfig_interface) instance has not yet attempted to fetch config, or that SDK initialization is incomplete.</li> <li>"success" indicates the last attempt succeeded.</li> <li>"failure" indicates the last attempt failed.</li> <li>"throttle" indicates the last attempt was rate-limited.</li> </ul>

<b>Signature:</b>

typescript
export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';

FetchType

Indicates the type of fetch request.

<ul> <li>"BASE" indicates a standard fetch request.</li> <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li> </ul>

<b>Signature:</b>

typescript
export type FetchType = 'BASE' | 'REALTIME';

LogLevel

Defines levels of Remote Config logging.

<b>Signature:</b>

typescript
export type LogLevel = 'debug' | 'error' | 'silent';

Unsubscribe

A function that unsubscribes from a real-time event stream.

<b>Signature:</b>

typescript
export type Unsubscribe = () => void;

ValueSource

Indicates the source of a value.

<ul> <li>"static" indicates the value was defined by a static constant.</li> <li>"default" indicates the value was defined by default config.</li> <li>"remote" indicates the value was defined by fetched config.</li> </ul>

<b>Signature:</b>

typescript
export type ValueSource = 'static' | 'default' | 'remote';