Google Analytics for Firebase Triggers
Google Analytics for Firebase provides event reports that help you understand how users interact with your app. With Cloud Run functions, you can access conversion events you have logged from Apple and Android devices and trigger functions based on those events.
Event types
Google Analytics for Firebase triggers the log
event. This is
a powerful event type, since any action that a user takes in your app can be
logged and in turn trigger a function.
Event Type | Trigger |
---|---|
providers/google.firebase.analytics/eventTypes/event.log
|
Triggered when a conversion event is logged. |
Cloud Run functions can respond to the logging of a Google Analytics for
Firebase conversion event. For instance, if a user makes an in-app purchase, an
in_app_purchase
conversion event is logged and can be consumed by
Cloud Run functions.
Event structure
This trigger invokes your function with an event similar to the one shown below:
{ "eventDim": [ // Contains a single event { "date": "20090213", "name": "screen_view", "params": { "firebase_conversion": { "intValue": "1" }, "firebase_event_origin": { "stringValue": "auto" }, "firebase_previous_class": { "stringValue": "MainActivity" }, "firebase_previous_id": { "intValue": "1928209043426257906" }, "firebase_previous_screen": { "stringValue": "id-D-D" }, "firebase_screen": { "stringValue": "id-C-C" }, "firebase_screen_class": { "stringValue": "MainActivity" }, "firebase_screen_id": { "intValue": "1234567890000" } }, "previousTimestampMicros": "1234567890000", "timestampMicros": "1234567890000" } ], "userDim": { // A UserDimensions object } }
User information such as application information or device information can be
found in the userDim
property. Information about the logged
event can be found in the eventDim
array. The objects contained in that array
include a name
field that holds the conversion event name (such as
in_app_purchase
). Custom fields set up in Google Analytics for Firebase
also appear here.
Code sample
Use the following snippet to process this response:
Node.js
Python
Go
C#
Ruby
PHP
Deploying your function
To deploy your function, specify the event type and the project in which you
have Firebase Auth configured. In the console, there is a field for Event
Type which contains log
—the only option—and Log Event Name, which is the
conversion event that will trigger the function.
On the command line, specific strings must be used to specify these parameters. The following Google Cloud CLI command deploys a function that triggers when a user makes an in-app purchase:
gcloud functions deploy FUNCTION_NAME \ --no-gen2 \ --entry-point ENTRY_POINT \ --trigger-event providers/google.firebase.analytics/eventTypes/event.log \ --trigger-resource projects/YOUR_PROJECT_ID/events/in_app_purchase \ --runtime RUNTIME
Argument | Description |
---|---|
FUNCTION_NAME |
The registered name of the Cloud Run function you are deploying.
This can either be the name of a function in your
source code, or an arbitrary string. If FUNCTION_NAME is an
arbitrary string, then you must include the
--entry-point flag.
|
--entry-point ENTRY_POINT |
The name of a function or class in your source code. Optional, unless
you did not use FUNCTION_NAME
to specify the
function in your source code to be executed during deployment. In that
case, you must use --entry-point to supply the name of the
executable function.
|
--trigger-event NAME |
The name of the event type that the function wishes to receive. For
Google Analytics for Firebase, this is always
providers/google.firebase.analytics/eventTypes/event.log.
|
--trigger-resource NAME |
The fully qualified Google Analytics event name, including your project
information. This should take the form:
projects/YOUR_PROJECT_ID/events/CONVERSION_EVENT_NAME
|
--runtime RUNTIME |
The name of the runtime you are using. For a complete list, see the
gcloud reference.
|