This Firebase quickstart is written in Swift and showcases how Firebase Analytics can provide insight on app usage and user engagement. You can read more about Google Analytics for Firebase here!
The iOS, iPadOS, and Catalyst versions are powered by UIKit. The tvOS and macOS versions are powered by SwiftUI. Note that Catalyst, macOS, and tvOS support for Google Analytics for Firebase are in beta as of version 8.9.0.
To view the older Objective-C and Swift quickstarts, view the
LegacyAnalyticsQuickstart
directory.
Google Analytics for Firebase offers multiple ways to understand how users are engaging with your app. In this quickstart, we demonstrate how you can use Google Analytics for Firebase to log in-app events and set user properties.
Ready? Let's get started! 🚀
Clone this project and cd
into the AnalyticsExample
directory.
Run pod install
. This command will install all of the required cocoapods
for this quickstart and generate a .xcworkspace
project. Go ahead and
open the AnalyticsExample.xcworkspace
project.
git clone https://github.com/firebase/quickstart-ios.git
cd analytics/
pod install --repo-update
open AnalyticsExample.xcworkspace
We will need to connect our quickstart with the Firebase Console. For an in depth explanation, you can read more about adding Firebase to your iOS Project.
-
Visit the Firebase Console and create a new app.
-
Add an iOS app to the project. Make sure the
Bundle Identifier
you set for this iOS App matches that of the one in this quickstart. This should be the same for all platforms. -
Download the
GoogleService-Info.plist
when prompted. -
Drag the downloaded
GoogleService-Info.plist
into the opened quickstart app. In Xcode, you can also add this file to the project by going toFile
→Add Files to 'AnalyticsExample'
and selecting the downloaded.plist
file. Be sure to add the.plist
file to all targets. -
At this point, you can build and run the quickstart! 🎉
When running the quickstart on macOS or macCatalyst, a prompt may be presented that requests keychain access. This occurs because these platforms do not use a sandboxed keychain and instead use the primary keychain. To dismiss the prompt, enter the requested password and select
Always allow
. Note: this prompt can be avoided entirely by signing your application.
Google Analytics for Firebase is a great way to log user related events or set user properties. This quickstart features a number of different UI controls that a user can interact with. Depending on the control, Google Analytics for Firebase is used to either set a user property or log an appropriate event.
Sometimes it is helpful to view debug logging when working with
Google Analytics for Firebase. This can easily be enabled in Xcode by
specifying -FIRAnalyticsDebugEnabled
as a runtime argument.
Using Xcode's menu bar, navigate to Product
→ Scheme
→ Edit Scheme...
.
Using the vertical menu on the left, select the Run scheme.
Then click Arguments and add -FIRAnalyticsDebugEnabled
as an
argument passed on launch. Done! ✓
Firebase Console DebugView
As you interact with the controls in the quickstart, analytics data will be sent to the Firebase Console. To view and interact with this stream, navigate to the project you set up for this quickstart on the Firebase Console. Select DebugView under the Analytics on the vertical menu on the left. From here, you can interact with the quickstart and see the related analytics data show up live on the Firebase Console.
Copyright 2020 Google LLC
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.