FirebaseAnalytics Framework Reference Stay organized with collections Save and categorize content based on your preferences.
FIRAnalytics
@interfaceFIRAnalytics:NSObjectThe top level Firebase Analytics singleton that provides methods for logging events and settinguser properties. Seethe developer guides for generalinformation on using Firebase Analytics in your apps.
Note
The Analytics SDK uses SQLite to persist events and other app-specific data. Callingcertain thread-unsafe global SQLite methods likesqlite3_shutdown() can result inunexpected crashes at runtime.Logs an app event. The event can have up to 25 parameters. Events with the same name must havethe same parameters. Up to 500 event names are supported. Using predefined events and/orparameters is recommended for optimal reporting.
The following event names are reserved - events with these names will be dropped, and instead anerror event will be logged:
- ad_activeview
- ad_click
- ad_exposure
- ad_query
- ad_reward
- adunit_exposure
- app_clear_data
- app_exception
- app_remove
- app_store_refund
- app_store_subscription_cancel
- app_store_subscription_convert
- app_store_subscription_renew
- app_update
- app_upgrade
- dynamic_link_app_open
- dynamic_link_app_update
- dynamic_link_first_open
- error
- firebase_campaign
- first_open
- first_visit
- notification_dismiss
- notification_foreground
- notification_open
- notification_receive
- os_update
- session_start
- session_start_with_rollout
- user_engagement
Declaration
Objective-C
+(void)logEventWithName:(nonnullNSString*)nameparameters:(nullableNSDictionary<NSString*,id>*)parameters;Parameters
nameThe name of the event. Should contain 1 to 40 alphanumeric characters orunderscores. The name must start with an alphabetic character. Some event names arereserved. See FIREventNames.h for the list of reserved event names. The “firebase_”,“google_”, and “ga_” prefixes are reserved and should not be used. Note that event names arecase-sensitive and that logging two events whose names differ only in case will result intwo distinct events. To manually log screen view events, use the
screen_viewevent name.parametersThe dictionary of event parameters. Passing
nilindicates that the event hasno parameters. Parameter names can be up to 40 characters long and must start with analphabetic character and contain only alphanumeric characters and underscores. Only String,Int, and Double parameter types are supported. String parameter values can be up to 100characters long for standard Google Analytics properties, and up to 500 characters long forGoogle Analytics 360 properties. The “firebase_”, “google_”, and “ga_” prefixes are reservedand should not be used for parameter names.Sets a user property to a given value. Up to 25 user property names are supported. Once set,user property values persist throughout the app lifecycle and across sessions.
The following user property names are reserved and cannot be used:
- first_open_time
- last_deep_link_referrer
- user_id
Declaration
Objective-C
+(void)setUserPropertyString:(nullableNSString*)valueforName:(nonnullNSString*)name;Parameters
valueThe value of the user property. Values can be up to 36 characters long. Setting thevalue to
nilremoves the user property.nameThe name of the user property to set. Should contain 1 to 24 alphanumeric charactersor underscores and must start with an alphabetic character. The “firebase_”, “google_”, and“ga_” prefixes are reserved and should not be used for user property names.
Sets the user ID property. This feature must be used in accordance withGoogle’s Privacy Policy
Declaration
Objective-C
+(void)setUserID:(nullableNSString*)userID;Parameters
userIDThe user ID to ascribe to the user of this app on this device, which must benon-empty and no more than 256 characters long. Setting userID to
nilremoves the user ID.Sets whether analytics collection is enabled for this app on this device. This setting ispersisted across app sessions. By default it is enabled.
Declaration
Objective-C
+(void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled;Parameters
analyticsCollectionEnabledA flag that enables or disables Analytics collection.
Sets the interval of inactivity in seconds that terminates the current session. The defaultvalue is 1800 seconds (30 minutes).
Declaration
Objective-C
+(void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval;Parameters
sessionTimeoutIntervalThe custom time of inactivity in seconds before the currentsession terminates.
Asynchronously retrieves the identifier of the current app session.
The session ID retrieval could fail due to Analytics collection disabled, app session expired,etc.
Declaration
Objective-C
+(void)sessionIDWithCompletion:(nonnullvoid(^)(int64_t,NSError*_Nullable))completion;Parameters
completionThe completion handler to call when the session ID retrieval is complete. Thishandler is executed on a system-defined global concurrent queue.This completion handler takes the following parameters:sessionID The identifier of the current app session. The value is undefined if the request failed.error An error object that indicates why the request failed, or
nilif the request was successful.Returns the unique ID for this instance of the application or
nilifConsentType.analyticsStoragehas been set toConsentStatus.denied.See
FIRAnalytics+Consent.hDeclaration
Objective-C
+(nullableNSString*)appInstanceID;Clears all analytics data for this instance from the device and resets the app instance ID.
Declaration
Objective-C
+(void)resetAnalyticsData;Adds parameters that will be set on every event logged from the SDK, including automatic ones.The values passed in the parameters dictionary will be added to the dictionary of default eventparameters. These parameters persist across app runs. They are of lower precedence than eventparameters, so if an event parameter and a parameter set using this API have the same name, thevalue of the event parameter will be used. The same limitations on event parameters apply todefault event parameters.
Declaration
Objective-C
+(void)setDefaultEventParameters:(nullableNSDictionary<NSString*,id>*)parameters;Parameters
parametersParameters to be added to the dictionary of parameters added to every event.They will be added to the dictionary of default event parameters, replacing any existingparameter with the same name. Valid parameters are String, Int, and Double. Setting a key’svalue to
NSNull()will clear that parameter. Passing in anildictionary will clear allparameters.Unavailable
Unavailable.
Declaration
Objective-C
-(nonnullinstancetype)init;
Handles events related to a URL session that are waiting to be processed.
If SwiftUI lifecycle is adopted, call this method from
UIApplicationDelegate.application(_:handleEventsForBackgroundURLSession:completionHandler:)in your app delegate.If SwiftUI lifecycle is not adopted, Firebase Analytics does not require delegationimplementation from the AppDelegate. If you choose instead to delegate manually, you can setFirebaseAppDelegateProxyEnabled to boolean
NOin your app’s Info.plist and call this methodfromUIApplicationDelegate.application(_:handleEventsForBackgroundURLSession:completionHandler:)in your app delegate.
Declaration
Objective-C
+(void)handleEventsForBackgroundURLSession:(nonnullNSString*)identifiercompletionHandler:(nullablevoid(^)(void))completionHandler;Parameters
identifierThe identifier of the URL session requiring attention.
completionHandlerThe completion handler to call when you finish processing the events.Calling this completion handler lets the system know that your app’s user interface isupdated and a new snapshot can be taken.
Handles the event when the app is launched by a URL (custom URL scheme or universal link).
If SwiftUI lifecycle is adopted, use
onOpenURL(perform:)to register a handler and callthis method in the handler.If UIScene lifecycle is adopted, call this method from
UISceneDelegate.scene(_:willConnectTo:options:)andUISceneDelegate.scene(_:openURLContexts:)when the URL contexts are available.If neither SwiftUI nor UIScene lifecycle is adopted, Firebase Analytics does not requiredelegation implementation from the AppDelegate. If you choose instead to delegate manually, youcan set FirebaseAppDelegateProxyEnabled to boolean
NOin your app’s Info.plist and call thismethod fromUIApplicationDelegate.application(_:open:options:)in your app delegate.
Declaration
Objective-C
+(void)handleOpenURL:(nonnullNSURL*)url;Parameters
urlThe URL resource to open. This resource can be a network resource or a file.
Handles the event when the app receives data associated with user activity that includes aUniversal Link.
If SwiftUI lifecycle is adopted, use
onOpenURL(perform:)to register a handler and callAnalytics.handleOpen(_:)instead in the handler.If UIScene lifecycle is adopted, call this method from
UISceneDelegate.scene(_:willConnectTo:options:)andUISceneDelegate.scene(_:continue:)whenNSUserActivity is available. See theAppledoc formore details.If neither SwiftUI nor UIScene lifecycle is adopted, Firebase Analytics does not requiredelegation implementation from the AppDelegate. If you choose instead to delegate manually, youcan set FirebaseAppDelegateProxyEnabled to boolean
NOin your app’s Info.plist and call thismethod fromUIApplication.application(_:continue:restorationHandler:)in your app delegate.
Declaration
Objective-C
+(void)handleUserActivity:(nonnullid)userActivity;Parameters
userActivityThe activity object containing the data associated with the task the userwas performing.
Sets the applicable end user consent state (e.g. for device identifiers) for this app on thisdevice. Use the consent settings to specify individual consent type values. Settings arepersisted across app sessions. By default consent types are set to
ConsentStatus.granted.Declaration
Objective-C
+(void)setConsent:(nonnullNSDictionary<FIRConsentType,FIRConsentStatus>*)consentSettings;Parameters
consentSettingsA Dictionary of consent types. Supported consent type keys are
ConsentType.adStorage,ConsentType.analyticsStorage,ConsentType.adUserData, andConsentType.adPersonalization. Valid values areConsentStatus.grantedandConsentStatus.denied.
Initiates on-device conversion measurement given a user email address. Requires dependencyGoogleAdsOnDeviceConversion fromhttps://github.com/googleads/google-ads-on-device-conversion-ios-sdk/ to be linked in, otherwiseit is a no-op.
Declaration
Objective-C
+(void)initiateOnDeviceConversionMeasurementWithEmailAddress:(nonnullNSString*)emailAddress;Parameters
emailAddressUser email address. Include a domain name for all email addresses(e.g. gmail.com or hotmail.co.jp).
Initiates on-device conversion measurement given a phone number in E.164 format. Requiresdependency GoogleAdsOnDeviceConversion fromhttps://github.com/googleads/google-ads-on-device-conversion-ios-sdk/ to be linked in, otherwiseit is a no-op.
Declaration
Objective-C
+(void)initiateOnDeviceConversionMeasurementWithPhoneNumber:(nonnullNSString*)phoneNumber;Parameters
phoneNumberUser phone number. Must be in E.164 format, which means it must belimited to a maximum of 15 digits and must include a plus sign (+) prefix and country codewith no dashes, parentheses, or spaces.
Initiates on-device conversion measurement given a sha256-hashed user email address. Requiresdependency GoogleAdsOnDeviceConversion fromhttps://github.com/googleads/google-ads-on-device-conversion-ios-sdk/ to be linked in, otherwiseit is a no-op.
Declaration
Objective-C
+(void)initiateOnDeviceConversionMeasurementWithHashedEmailAddress:(nonnullNSData*)hashedEmailAddress;Parameters
hashedEmailAddressUser email address as a UTF8-encoded string normalized and hashedaccording to the instructions athttps://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3.
Initiates on-device conversion measurement given a sha256-hashed phone number in E.164 format.Requires dependency GoogleAdsOnDeviceConversion fromhttps://github.com/googleads/google-ads-on-device-conversion-ios-sdk/ to be linked in, otherwiseit is a no-op.
Declaration
Objective-C
+(void)initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:(nonnullNSData*)hashedPhoneNumber;Parameters
hashedPhoneNumberUTF8-encoded user phone number in E.164 format and then hashedaccording to the instructions athttps://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-28 UTC.