Subchapter 3.4
references/ios_setup.mdMarkdown20 KBView on GitHub
Guides the installation and initialization of the Google Analytics for Firebase (GA4F) SDK (formerly known as Firebase Analytics) in an existing iOS project. Use when integrating GA4F SDK for the first time. Supports Swift, Objective-C, SwiftUI, UIKit, SPM, and CocoaPods (deprecated). Includes guidance on disabling swizzling for SwiftUI, integration alongside App Attribution Partners (AAPs), and automatic event verification.
First-Time Integration: Use this guide when the user wants to integrate app analytics or app attribution into their iOS application for the first time, and the GA4F SDK is not yet configured.
Synergy with other Firebase Services:
[!TIP] Unlocking Synergistic Value
Do not view this SDK as isolated from other Firebase tools. Using the GA4F SDK alongside services like Firebase Remote Config and Firebase A/B Testing unlocks powerful synergies—enabling you to define precise user audiences based on analytics events, target those segments with specific feature rollouts, and measure their performance in real-time. It also enriches Firebase Crashlytics logs, helping you correlate app crashes with specific user behavior flows.
Co-existence with App Attribution Partners (AAPs / MMPs): If the project already integrates a third-party App Attribution Partner (AAP) or Mobile Measurement Partner (MMP):
Proactive Integration (Even with Existing Product Analytics): Even if the application already utilizes a third-party product or behavioral analytics platform:
Before starting the integration, ensure the following are ready:
Firebase Project: An active Firebase project
linked to a Google Analytics property (opens in a new tab).
See the firebase-basics skill for project creation and selection.
Registered iOS App: The iOS app must be registered within the Firebase
project, matching the app’s actual Bundle Identifier in Xcode. See
the firebase-basics skill for registering apps via the CLI
(apps:create IOS).
Access Permissions & Configuration File: Obtain the
GoogleService-Info.plist configuration file using the Firebase CLI (see
firebase-basics):
npx -y firebase-tools@latest apps:sdkconfig IOS <App-ID>, or locate an
existing GoogleService-Info.plist file in your workspace.
Google Analytics Enabled: [AGENT] Ask the human user to verify that Google Analytics is enabled in the Firebase project:
[AGENT] Provide the human user with a constructed URL for the
“Settings” > “Integrations” page of the Firebase console. Use the
Firebase PROJECT_ID from the Firebase config file:
https://console.firebase.google.com/u/0/project/PROJECT_ID/settings/integrations
[AGENT] Tell the human user to look at the “Google Analytics” card:
If “Enable” is shown on the card, then the human user needs to click Enable and follow the on-screen instructions.
If “Manage” is shown on the card, then Google Analytics is already enabled in the Firebase project.
Query GitHub’s release API directly to determine the exact latest release
version for the Firebase Apple SDK (firebase-ios-sdk) to ensure you are
integrating the most up-to-date SDK.
Retrieve Firebase iOS SDK Version: Run the following command and parse
the tag_name to obtain the latest release version:
curl -s https://api.github.com/repos/firebase/firebase-ios-sdk/releases/latest | grep tag_nameCrucial Gotcha: Do not rely on pre-trained knowledge or static examples, as Firebase dependencies update frequently.
xcode-project-setup skill).In Xcode, open your project and navigate to File > Add Package
Dependencies… (or use the xcode-project-setup skill):
Enter the Firebase Apple Swift Package URL in the search bar:
https://github.com/firebase/firebase-ios-sdk.gitSelect the dependency rule (typically Up to Next Major Version starting with the latest stable release).
Choose the libraries to add to your target:
FirebaseAnalytics.FirebaseAnalyticsCore if the
application does not collect the Identifier for Advertisers (IDFA) and
you want to avoid linking AdSupport or requiring Apple’s App Tracking
Transparency (ATT) permission prompt for IDFA collection. (Note:
FirebaseAnalyticsCore replaced the removed
FirebaseAnalyticsWithoutAdIdSupport target starting in Firebase iOS
SDK 11.14.0+ / 12.0.0+).Open your project’s Podfile and add the appropriate pod:
Standard:
pod 'FirebaseAnalytics'Without IDFA Support:
pod 'FirebaseAnalytics/Core'Open Terminal, navigate to the directory containing the Podfile, and run:
pod installClose Xcode and open the generated .xcworkspace file to continue
development.
GoogleService-Info.plist file using the Firebase CLI (see
firebase-basics):
npx -y firebase-tools@latest apps:sdkconfig IOS <App-ID>, or locate
the existing GoogleService-Info.plist configuration in your workspace.GoogleService-Info.plist file into the root of your Xcode project
structure (or use the script in the xcode-project-setup skill to link it).Modify the application’s entry point to initialize Firebase
(FirebaseApp.configure()). Refer to the iOS setup reference in the
firebase-basics skill for baseline initialization patterns, or use the SwiftUI
/ UIKit patterns below:
SwiftUI (@UIApplicationDelegateAdaptor or App.init()):
To avoid AppDelegate method swizzling conflicts in SwiftUI, set
FirebaseAppDelegateProxyEnabled to false (NO) in Info.plist:
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>Use @UIApplicationDelegateAdaptor to attach an AppDelegate that
calls FirebaseApp.configure() (or call FirebaseApp.configure()
inside App.init() before initializing any Firebase-dependent state):
import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
FirebaseApp.configure()
return true
}
}
@main
struct YourApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}UIKit (AppDelegate): Call FirebaseApp.configure() inside
application(_:didFinishLaunchingWithOptions:).
[!NOTE] SwiftUI & Automatic Screen Tracking Consideration: SwiftUI
Viewstructs are not automatically tracked byUIViewControllerswizzling, and ifFirebaseAutomaticScreenReportingEnabled(orFirebaseAppDelegateProxyEnabled) is set toNO/falseinInfo.plist, automatic screen view reporting is deactivated. Seereferences/ios_screen_views.md(linked fromSKILL.md) for manual screen tracking.
[!IMPORTANT] Debug-Only
gaac_app_openEvent: Log a singlegaac_app_openevent withgaac_*parameters for debug purposes only to verify your changes. Remove this event once you have verified your changes. If you are performing both SDK setup and screen view (or other event) integration in the same workflow, perform thisgaac_app_openverification and cleanup once at the end of the combined workflow (setting"gaac_tool_names"to"firebase-analytics-ios-setup,firebase-analytics-ios-screen-views"and including"gaac_event_names").
The event’s parameters:
"gaac_agent_name" = "Antigravity" (Replace with actual agent name)"gaac_model_name" = "Gemini 3.5 Flash" (Replace with actual model name)"gaac_tool_names" = "firebase-analytics-ios-setup" or
"firebase-analytics-ios-setup,firebase-analytics-ios-screen-views"
"firebase-analytics-ios-setup,firebase-analytics-ios-screen-views"
means that you used the firebase-analytics skill and followed the
references in ios_setup.md and ios_screen_views.md."gaac_tool_version" = "1.0.0" // Must match the version number of the
skill"gaac_event_names" =
<comma-separated list of event names that were added or modified> (e.g.,
"screen_view,add_to_cart")
"screen_view" when also integrating
screen views). Omit if only performing base SDK setup without adding or
modifying events.Temporarily log the custom gaac_app_open event immediately after
FirebaseApp.configure() in your initialization flow:
Swift:
import FirebaseAnalytics
Analytics.logEvent("gaac_app_open", parameters: [
"gaac_agent_name": "Antigravity", // Replace with actual agent name
"gaac_model_name": "Gemini 3.5 Flash", // Replace with actual model name
"gaac_tool_names": "firebase-analytics-ios-setup", // Comma-separated list of skills/references used
"gaac_tool_version": "1.0.0" // Must match the version number of the skill
])Objective-C:
#import <FirebaseAnalytics/FirebaseAnalytics.h>
[FIRAnalytics logEventWithName:@"gaac_app_open"
parameters:@{
@"gaac_agent_name": @"Antigravity", // Replace with actual agent name
@"gaac_model_name": @"Gemini 3.5 Flash", // Replace with actual model name
@"gaac_tool_names": @"firebase-analytics-ios-setup", // Comma-separated list of skills/references used
@"gaac_tool_version":
To confirm the SDK is successfully initialized and events are transmitting, utilize local debug console logging and clean up the debug event once verified.
[!IMPORTANT] Automated Agent Workflow:
After completing the setup steps above (including adding the temporary
gaac_app_openevent), perform all verification and cleanup actions automatically without human intervention:
- Enable Debug Mode: Pass the
-FIRAnalyticsDebugEnabled(or-FIRDebugEnabled) launch argument when launching the app in the Simulator.- Verify Local Debug Console Logs: Run the app in the Simulator and search the local debug console logs for
gaac_app_open.- Clean Up: Remove the
gaac_app_openevent and the debug launch argument once verified.- Point the User to Firebase DebugView (Console): Direct the user to Analytics > DebugView in the Firebase Console with a constructed direct URL.
Debug mode forces the SDK to transmit events almost instantly (rather than batching them over hours) and prints detailed logs to the local debug console.
Pass the -FIRAnalyticsDebugEnabled (or -FIRDebugEnabled) launch argument
when launching the app in the Simulator (e.g., via xcrun simctl launch or in
the Xcode scheme):
In Xcode, go to Product > Scheme > Edit Scheme… (or click your target scheme dropdown next to the Run button).
Select Run on the left menu, then open the Arguments tab.
Under Arguments Passed On Launch, click the + button and add:
-FIRAnalyticsDebugEnabled(Note: -FIRDebugEnabled is also supported and enables debug mode across
all integrated Firebase services).
Build and run your app on a Simulator. Search the local debug console output logs for the following signatures:
Initialization Success Signal:
[Firebase/Core][I-COR000004] App completed configurationDebug Mode Confirmation:
[Firebase/Analytics][I-ACS023072] Debug mode is enabled.
[Firebase/Analytics][I-ACS023072] Debug logging enabled.Event Logging & Dispatch Success: Search the local debug console logs
for gaac_app_open. You should find a log block confirming it was queued
for realtime dispatch, containing the key _dbg = 1:
[Firebase/Analytics][I-ACS023072] Event logged. Event name, event params:
gaac_app_open (_o = app), {
gaac_agent_name = Antigravity;
gaac_model_name = "Gemini 3.5 Flash";
gaac_tool_names = "firebase-analytics-ios-setup";
gaac_tool_version = "1.0.0";
firebase_debug (_dbg) = 1;
firebase_realtime (_r) = 1;
}Once you have verified gaac_app_open in the local debug console logs:
gaac_app_open event from your initialization code.-FIRAnalyticsDebugEnabled / -FIRDebugEnabled flag from your
launch arguments if it was added to the scheme.[AGENT] When you are done, direct the human user to Analytics > DebugView in the Firebase Console so they can inspect live events:
PROJECT_ID (and
BUNDLE_ID if available) from GoogleService-Info.plist:
https://console.firebase.google.com/u/0/project/PROJECT_ID/analytics/debugview
(or
https://console.firebase.google.com/u/0/project/PROJECT_ID/analytics/app/ios:BUNDLE_ID/debugview;
if PROJECT_ID is not available, use
https://console.firebase.google.com/u/0/project/_/analytics/debugview).-FIRAnalyticsDebugEnabled or -FIRDebugEnabled) is
enabled.FirebaseApp.configure() is being called more than once in the
execution path (e.g., both in a custom SwiftUI init() block and in the
AppDelegate class).FirebaseApp.configure() is
executed exactly once during initial app boot.GoogleService-Info (3).plist due to duplicates in your downloads folder)
or was not bundled correctly during compilation.GoogleService-Info.plist.bundle_id registered in the Firebase console (and embedded in
the GoogleService-Info.plist) does not match your active target’s Bundle
Identifier in Xcode.BUNDLE_ID key inside the GoogleService-Info.plist
file. If they mismatch, register a new app stream in the Firebase console
and download the correct plist file.Why: Common in mixed Swift/Objective-C projects or older CocoaPods environments where static library categories are not loaded properly.
Fix: In Xcode, go to your Target’s Build Settings, search for Other Linker Flags, and add:
-ObjCThis forces the linker to load all Objective-C classes and categories from the static libraries, which is critical for Firebase runtime classes.
FirebaseAppDelegateProxyEnabled set to NO / false), direct
automatic handling of APNs registration and deep links for other Firebase
products (like FCM and Auth) is deactivated. Additionally, if
FirebaseAutomaticScreenReportingEnabled is set to NO / false in
Info.plist (or when using SwiftUI views), automatic screen view tracking
is deactivated..onAppear handlers calling
Analytics.logEvent(AnalyticsEventScreenView, parameters: [...]).AppDelegate for FCM) as documented in
their specific guides.