Google 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 user base, 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.
Before you begin
If you're creating a new project, Add Firebase to your iOS project and follow the steps to set up Google Analytics for your project during project creation.
If you have an existing project and did not configure Google Analytics, you can link Google Analytics to your project from the Integrations tab of your > Project settings.
(Recommended). Add the AdSupport framework to your project to enable additional features such as audiences and campaign attribution.
Add the Analytics SDK to your app
- Add the dependency for Firebase to your Podfile:
pod 'Firebase/Analytics'
- Run
pod install
and open the created.xcworkspace
file. - Import the Firebase module in your
UIApplicationDelegate
:Swift
import Firebase
Objective-C
@import Firebase;
- Configure a
FirebaseApp
shared instance, typically in your app'sapplication:didFinishLaunchingWithOptions:
method:Swift
// Use Firebase library to configure APIs FirebaseApp.configure()
Objective-C
// Use Firebase library to configure APIs [FIRApp configure];
Start logging events
After you have configured the FirebaseApp
instance, you can begin to log
events with the
logEvent()
method.
Certain events are recommended for all apps; others are recommended for specific business types or verticals. You should send suggested events along with their prescribed parameters, to ensure maximum available detail in your reports and to benefit from future features and integrations as they become available. This section demonstrates logging a pre-defined event, for more information on logging events, see Log events.
The following example demonstrates how to log a recommended event to indicate a user has clicked on a specific element in your app:
Swift
Analytics.logEvent(AnalyticsEventSelectContent, parameters: [ AnalyticsParameterItemID: "id-\(title!)", AnalyticsParameterItemName: title!, AnalyticsParameterContentType: "cont" ])
Objective-C
[FIRAnalytics logEventWithName:kFIREventSelectContent parameters:@{ kFIRParameterItemID:[NSString stringWithFormat:@"id-%@", self.title], kFIRParameterItemName:self.title, kFIRParameterContentType:@"image" }];
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
- Use the DebugView to verify your events.
- Explore your data in the Firebase console.
- Explore the guides on events and user properties.
- Learn how to export your data to BigQuery.