Log events

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.

Before you begin

If this is your first time adding Analytics to your app, complete the following steps:

Connect your app in the Firebase console

  1. Install the Firebase SDK.
  2. In the Firebase console, add your app to your Firebase project.

Add Analytics to your app

  1. Add the dependency for Firebase to your Podfile:
    pod 'Firebase/Core'
  2. Run pod install and open the created .xcworkspace file.
  3. Import the Firebase module:

    Objective-C

    @import Firebase;
    

    Swift

    import Firebase
    
  4. Configure a FIRApp shared instance, typically in your application's application:didFinishLaunchingWithOptions: method:

    Objective-C

    // Use Firebase library to configure APIs
    [FIRApp configure];
    

    Swift

    // Use Firebase library to configure APIs
    FIRApp.configure()
    

Log events

After you have configured the FIRApp instance, you can begin to log events with the logEventWithName() method. You can find implementation details in the following locations:

  • Suggested events: see the FIREventNames.h header file.
  • Prescribed parameters: see the FIRParameterNames.h header file.

The following example demonstrates how to log a suggested kFIRSelectContent event to indicate a user has shared content:

Objective-C

[FIRAnalytics logEventWithName:kFIREventSelectContent parameters:@{
    kFIRParameterContentType:@"cont",
    kFIRParameterItemID:@"1"
}];

Swift

FIRAnalytics.logEventWithName(kFIREventSelectContent, parameters: [
  kFIRParameterContentType:"cont",
  kFIRParameterItemID:"1"
  ])

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

  • Custom parameters: Although these custom parameters are not represented directly in your Analytics reports, they can 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.

  • kFIRParameterValue parameter: kFIRParameterValue 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 as shown in this example:

Objective-C

 [FIRAnalytics logEventWithName:@"share_image"
                         parameters:@{
                                      @"name": name,
                                      @"full_text": text
                                      }];

Swift

FIRAnalytics.logEventWithName("share_image", parameters: [
  "name": name,
  "full_text": text
  ])

View events in the Xcode debug console

You can enable verbose logging to monitor logging of events by the SDK to help verify that events are being logged properly. This includes both automatically and manually logged events.

You can enable verbose logging as follows:

  1. In Xcode, select Product > Scheme > Edit scheme...
  2. Select Run from the left menu.
  3. Select the Arguments tab.
  4. In the Arguments Passed On Launch section, add -FIRAnalyticsDebugEnabled.

The next time you run your app, your events will display in the Xcode debug console, helping you immediately verify that events are being sent.

View events in the dashboard

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

You can access this data in the Firebase console as follows:

  1. In the Firebase console, open your project.
  2. Select Analytics from the menu to view the Analytics reporting dashboard.

The Events tab shows the event reports that are automatically created for each distinct type of Analytics event logged by your app. Read more about the Analytics reporting dashboard in the Firebase Help Center.

Send feedback about...

Need help? Visit our support page.