Events and Triggers
These are the basic Firebase and Google Cloud Platform events and triggers.
Events
Events are things that happen within your cloud environment that you might want to take action on. These might be changes to data in a database, files added to a storage system, or a new virtual machine instance is created. Currently, Cloud Functions supports events from the following providers:
Firebase (Realtime Database, Storage, Analytics, Auth)
Cloud Logging—forward log entries to a Pub/Sub topic by creating a sink. You can then trigger the function.
For more information about Events, check here.
Cloud Firestore triggers:
Events:
onCreate: triggered when a document is written to for the first time.
onUpdate: triggered when a document already exists and has any value changed.
onDelete: triggered when a document with data is deleted.
onWrite: triggered when onCreate, onUpdate or onDelete is triggered.
For more information about Firestore events check here, and for Cloud Firestore over here.
Realtime Database triggers
Events:
onWrite(): triggered when data is created, updated, or deleted in the Realtime Database.
onCreate(): which triggered when new data is created in the Realtime Database.
onUpdate():which triggered when data is updated in the Realtime Database.
onDelete(): which triggered when data is deleted from the Realtime Database.
For more information about Realtime Database triggers, check here.
Remote Config triggers
You can trigger a function in response to Firebase Remote Config events, including the publication of a new config version or the rollback to an older version.
For more information about Remote Config triggers, check here.
Firebase Authentication triggers
Firebase accounts will trigger user creation events for Cloud Functions when:
A user creates an email account and password.
A user signs in for the first time using a federated identity provider.
The developer creates an account using the Firebase Admin SDK.
A user signs in to a new anonymous auth session for the first time.
For more information about Firebase Authentication triggers, check here.
Google Analytics triggers
Cloud Functions supports the Google Analytics AnalyticsEvent. This event is triggered whenever user activity generates a conversion event. For example, you could write a function that triggers when the in_app_purchase event is generated, indicating that an in-app purchase has occurred. You must specify the Analytics event that you want to trigger your function using the functions.analytics.event() method, and handle the event within the onLog() event handler.
For more information about Google Analytics triggers, check here.
Cloud Storage triggers
Events:
onArchive: Only sent when a bucket has enabled object versioning. This event indicates that the live version of an object has become an archived version, either because it was archived or because it was overwritten by the upload of an object of the same name.
onDelete: Sent when an object has been permanently deleted. This includes objects that are overwritten or are deleted as part of the bucket's lifecycle configuration. For buckets with object versioning enabled, this is not sent when an object is archived (see onArchive), even if archival occurs via the storage.objects.delete method.
onFinalize: Sent when a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object. A failed upload does not trigger this event.
onMetadataUpdate: Sent when the metadata of an existing object changes.
For more information about Cloud Storage triggers, check here.
Pub/Sub triggers
You can trigger a function whenever a new Pub/Sub message is sent to a specific topic. You must specify the Pub/Sub topic name that you want to trigger your function, and set the event within the onPublish() event handler.
For more information about Pub/Sub triggers, check here.
Firebase Test Lab triggers
Create a new function that triggers when a TestMatrix completes with the event handler functions.testLab.testMatrix().onComplete().
For more information about Pub/Sub triggers, check here.
Cloud functions. EventContext
Type of event. Possible values are:
google.analytics.event.log
google.firebase.auth.user.create
google.firebase.auth.user.delete
google.firebase.database.ref.write
google.firebase.database.ref.create
google.firebase.database.ref.update
google.firebase.database.ref.delete
google.firestore.document.write
google.firestore.document.create
google.firestore.document.update
google.firestore.document.delete
google.pubsub.topic.publish
google.firebase.remoteconfig.update
google.storage.object.finalize
google.storage.object.archive
google.storage.object.delete
google.storage.object.metadataUpdate
google.testing.testMatrix.complete
For more information about Cloud functions-EventContext, check here and over here.
Last updated