Firebase Analytics collects usage and behavior data for your app. The SDK logs two primary types of information:
- Events: What is happening in your app, such as user actions, system events, or errors.
- User properties: Attributes you define to describe segments of your userbase, such as language preference or geographic location.
Analytics automatically logs some events and user properties; you don't need to add any code to enable them.
Prerequisites
- Add Firebase to your iOS project.
- (Recommended). Add the AdSupport framework to your project to enable additional features such as audiences and campaign attribution.
Add Analytics to your app
- Add the dependency for Firebase to your Podfile:
pod 'Firebase/Core'
- Run
pod install
and open the created.xcworkspace
file. - Import the Firebase module:
Objective-C
@import Firebase;
Swift
import Firebase
- Configure a
FIRApp
shared instance, typically in your application'sapplication: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 explore the
predefined events and parameters in the FIREventNames.h
and
FIRParameterNames.h
header files.
The following example demonstrates how to log a suggested
kFIREventShare
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" ])
To view this event in the Xcode debug console, enable Analytics debugging:
- In Xcode, select Product > Scheme > Edit scheme...
- Select Run from the left menu.
- Select the Arguments tab.
- In the Arguments Passed On Launch section, add
-FIRAnalyticsDebugEnabled
.
Next Steps
- See your data refresh periodically in the Firebase console.
- Explore the guides on events and user properties.