This article shows you how to configure an application to use Google Analytics. To configure a website to use Analytics, see Set up Analytics for a website and/or app.
Before you begin
Add Firebase to your Apple project and make sure that Analytics is enabled in your Firebase project:
If you're creating a new Firebase project, enable Analytics during the project creation workflow.
If you're using an existing Firebase project that doesn't have Analytics enabled, go to the Integrations tab of your
to enable it. > Project settings When you enable Analytics in your project, your Firebase apps are linked to Analytics data streams.
(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
Use Swift Package Manager to install and manage Firebase dependencies.
- In Xcode, with your app project open, navigate to File > Add Packages.
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose the Analytics library.
- For an optimal experience with Analytics, we recommend enabling Google Analytics in your Firebase project and adding the Firebase SDK for Google Analytics to your app. You can select either the library without IDFA collection or with IDFA collection.
- When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
- When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
https://github.com/firebase/firebase-ios-sdk
Learn more about IDFA, the device-level advertising identifier, in Apple's User Privacy and Data Use and App Tracking Transparency documentation.
Next, perform some configuration steps:
- Import the Firebase module in your
UIApplicationDelegate
:Swift
import FirebaseCore import FirebaseAnalytics
Objective-C
@import FirebaseCore; @import FirebaseAnalytics;
- 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];
(Optional) Disable Apple ad network attribution registration
For your convenience, the SDK automatically
registers
your app with Apple for ad network attribution with
SKAdNetwork.
If you wish to disable this feature, set the value of
GOOGLE_ANALYTICS_REGISTRATION_WITH_AD_NETWORK_ENABLED
to NO
(Boolean) in
your app’s info.plist file.
Next steps
- Send events to Analytics.
- 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.