Log events

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

Events provide insight on what is happening in your app, such as user actions, system events, or errors.

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 configured the firebase.analytics() instance, you can begin to log events with the logEvent() method. If you're already familiar with Google Analytics, this method is equivalent to using the event command in gtag.js.

To help you get started, the Analytics SDK defines a number of suggested 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.

Note: To get the maximum detail in reports, log the suggested events that make sense for your app and their prescribed parameters. This also ensures that you benefit from the latest Google Analytics features as they become available.

You can find implementation details for several events and their parameters in the gtag.js event reference.

The following example demonstrates how to log a select_content event:

analytics.logEvent('select_content', {
  content_type: 'image',
  content_id: 'P12453',
  items: [{ name: 'Kittens' }]
});

In addition to the prescribed parameters, you can add the following parameters to any event:

  • Custom parameters: Custom parameters can be registered for reporting in your Analytics reports. They can also be used as filters in audience definitions that can be applied to every report. Custom parameters are also included in data exported to BigQuery if your app is linked to a BigQuery project.
  • value parameter: value is a general purpose parameter that is useful for accumulating a key metric that pertains to an event. Examples include revenue, distance, time, and points.

If your application has specific needs not covered by a suggested event type, you can log your own custom events. For example, if you're developing a game and want to track when a player completes a particular goal, you could log an event similar to the following example:

analytics.logEvent('goal_completion', { name: 'lever_puzzle'});

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.