Catch up on everything announced at Firebase Summit, and learn how Firebase can help you accelerate app development and run your app with confidence. Learn More

Log events

Stay organized with collections Save and categorize content based on your preferences.

This guide shows you how to log events in your app.

Analytics automatically logs some events for you; you don't need to add any code to receive them. If your app needs to collect additional data, you can log up to 500 different Analytics Event types in your app. There is no limit on the total volume of events your app logs. Note that event names are case-sensitive and that logging two events whose names differ only in case will result in two distinct events.

Before you begin

Make sure that you've set up your project and can access Analytics as described in Get Started with Analytics.

Log events

After you have created a FirebaseAnalytics instance, you can use it to log events with the library's log- methods.

Predefined events

To help you get started, the Analytics SDK defines a number of recommended events that are common among different types of apps, including retail and ecommerce, travel, and gaming apps. To learn more about these events and when to use them, browse the Events and properties articles in the Firebase Help Center.

You can find the log methods for the recommended event types in the API reference.

The following example demonstrates how to log a select_content event:

await FirebaseAnalytics.instance.logSelectContent(
    contentType: "image",
    itemId: itemId,
);

Alternatively, you can log the same event using logEvent():

await FirebaseAnalytics.instance.logEvent(
    name: "select_content",
    parameters: {
        "content_type": "image",
        "item_id": itemId,
    },
);

This can be useful if you want to specify additional parameters other than the prescribed (required) parameters. You can add the following parameters to any event:

  • Custom parameters: Custom parameters can be used as dimensions or metrics in Analytics reports. You can use custom dimensions for non-numerical event parameter data and custom metrics for any parameter data better represented numerically. Once you've logged a custom parameter using the SDK, register the dimension or metric to ensure those custom parameters appear in Analytics reports. Do this via: Analytics > Events > Manage Custom Definitions > Create Custom Dimensions

    Custom parameters can be used in audience definitions that may be applied to every report. Custom parameters are also included in data exported to BigQuery if your app is linked to a BigQuery project. Find sample queries and much more at Google Analytics 4 BigQuery Export.

  • value parameter: a general purpose parameter that is useful for accumulating a key metric that pertains to an event. Examples include revenue, distance, time, and points.

Custom events

If your application has specific needs not covered by a recommended event type, you can log your own custom events as shown in this example:

await FirebaseAnalytics.instance.logEvent(
    name: "share_image",
    parameters: {
        "image_name": name,
        "full_text": text,
    },
);

Set default event parameters

You can log parameters across events using setDefaultEventParameters(). Default parameters are associated with all future events that are logged.

As with custom parameters, register the default event parameters to ensure they appear in Analytics reports.

// Not supported on web
await FirebaseAnalytics.instance
  .setDefaultEventParameters({
    version: '1.2.3'
  });

If a parameter is specificed in the logEvent() or log- method, that value is used instead of the default.

To clear a default parameter, call the setDefaultEventParameters() method with the parameter set to null.

View events in the dashboard

You can view aggregated statistics about your events in the Firebase console dashboards. These dashboards update periodically throughout the day. For immediate testing, use the logcat output as described in the previous section.

You can access this data from the Events dashboard in the Firebase console. This dashboard shows the event reports that are automatically created for each distinct type of event logged by your app.