Firebase Remote Config Triggers

Cloud Functions can be triggered in response to changes in Firebase Remote Config. This makes it possible to change the behavior and appearance of your app without publishing an app update.

Event types

Firebase Remote Config can trigger functions in response to the remoteconfig.update event.

Event Type Trigger
remoteconfig.update Triggered when the remote config template is updated.

Event structure

Event data is provided as a transformed remoteConfig object.

For example:

{
  "updateType": "FORCED_UPDATE",
  "updateOrigin": "CONSOLE",
  "versionNumber": 1
}

Sample code

Node.js

/**
 * Triggered by a change to a Firebase Remote Config value.
 *
 * @param {object} data The Cloud Functions event data.
 */
exports.helloRemoteConfig = event => {
  const {data} = event;

  console.log(`Update type: ${data.updateType}`);
  console.log(`Origin: ${data.updateOrigin}`);
  console.log(`Version: ${data.versionNumber}`);
};

Python

def hello_remote_config(data, context):
    """ Triggered by a change to a Firebase Remote Config value.
     Args:
            data (dict): The event payload.
            context (google.cloud.functions.Context): Metadata for the event.
    """
    print(f'Update type: {data["updateType"]}')
    print(f'Origin: {data["updateOrigin"]}')
    print(f'Version: {data["versionNumber"]}')

Go


// Package helloworld provides a set of Cloud Functions samples.
package helloworld

import (
	"context"
	"log"
)

// A RemoteConfigEvent is an event triggered by Firebase Remote Config.
type RemoteConfigEvent struct {
	UpdateOrigin string `json:"updateOrigin"`
	UpdateType   string `json:"updateType"`
	UpdateUser   struct {
		Email    string `json:"email"`
		ImageURL string `json:"imageUrl"`
		Name     string `json:"name"`
	} `json:"updateUser"`
	VersionNumber string `json:"versionNumber"`
}

// HelloRemoteConfig handles Firebase Remote Config events.
func HelloRemoteConfig(ctx context.Context, e RemoteConfigEvent) error {
	log.Printf("Update type: %v", e.UpdateType)
	log.Printf("Origin: %v", e.UpdateOrigin)
	log.Printf("Version: %v", e.VersionNumber)
	return nil
}

Deploying your function

To deploy your function, you need to specify the event type providers/firebase.remoteConfig.

The following gcloud command deploys a function that is triggered by a Firebase Remote Config event:

gcloud functions deploy YOUR_FUNCTION_NAME \
  --trigger-event providers/firebase.remoteConfig \
  --runtime RUNTIME
Argument Description
--trigger-event providers/firebase.remoteConfig The Firebase Remote Config event name that triggers the function.
--runtime RUNTIME The name of the runtime you are using. For a complete list, see the gcloud reference.
Was deze pagina nuttig? Laat ons weten hoe goed we u hebben geholpen:

Feedback verzenden over...

Cloud Functions Documentation