FIRAnalytics
@interface FIRAnalytics : NSObject
The top level Firebase Analytics singleton that provides methods for logging events and setting user properties. See the developer guides for general information on using Firebase Analytics in your apps.
Note
The Analytics SDK uses SQLite to persist events and other app-specific data. Calling certain thread-unsafe global SQLite methods likesqlite3_shutdown() can result in
unexpected crashes at runtime.
-
Logs an app event. The event can have up to 25 parameters. Events with the same name must have the same parameters. Up to 500 event names are supported. Using predefined events and/or parameters is recommended for optimal reporting.
The following event names are reserved and cannot be used:
- ad_activeview
- ad_click
- ad_exposure
- ad_impression
- ad_query
- adunit_exposure
- app_clear_data
- app_remove
- app_update
- error
- first_open
- in_app_purchase
- notification_dismiss
- notification_foreground
- notification_open
- notification_receive
- os_update
- session_start
- user_engagement
Declaration
Objective-C
+ (void)logEventWithName:(nonnull NSString *)name parameters:(nullable NSDictionary<NSString *, id> *)parameters;Parameters
nameThe name of the event. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. 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 are case-sensitive and that logging two events whose names differ only in case will result in two distinct events. To manually log screen view events, use the
screen_viewevent name.parametersThe dictionary of event parameters. Passing nil indicates that the event has no parameters. Parameter names can be up to 40 characters long and must start with an alphabetic character and contain only alphanumeric characters and underscores. Only NSString and NSNumber (signed 64-bit integer and 64-bit floating-point number) parameter types are supported. NSString parameter values can be up to 100 characters long. The “firebase_”, “google_”, and “ga_” prefixes are reserved and 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:(nullable NSString *)value forName:(nonnull NSString *)name;Parameters
valueThe value of the user property. Values can be up to 36 characters long. Setting the value to nil removes the user property.
nameThe name of the user property to set. Should contain 1 to 24 alphanumeric characters or 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 with Google’s Privacy Policy
Declaration
Objective-C
+ (void)setUserID:(nullable NSString *)userID;Parameters
userIDThe user ID to ascribe to the user of this app on this device, which must be non-empty and no more than 256 characters long. Setting userID to nil removes the user ID.
-
This method was deprecated in Firebase 6.29.0.
Sets the current screen name, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app. Must be called on the main thread.
Note that screen reporting is enabled automatically and records the class name of the current UIViewController for you without requiring you to call this method. The class name can optionally be overridden by calling this method in the viewDidAppear callback of your UIViewController and specifying the screenClassOverride parameter.
setScreenName:screenClass:must be called after[super viewDidAppear:].If your app does not use a distinct UIViewController for each screen, you should call this method and specify a distinct screenName each time a new screen is presented to the user.
The screen name and screen class remain in effect until the current UIViewController changes or a new call to setScreenName:screenClass: is made.
Warning
If you override
viewDidAppear:in your UIViewController but do not call[super viewDidAppear:], that screen class will not be tracked.Declaration
Objective-C
+ (void)setScreenName:(nullable NSString *)screenName screenClass:(nullable NSString *)screenClassOverride;Parameters
screenNameThe name of the current screen. Should contain 1 to 100 characters. Set to nil to clear the current screen name.
screenClassOverrideThe name of the screen class. Should contain 1 to 100 characters. By default this is the class name of the current UIViewController. Set to nil to revert to the default class name.
-
Sets whether analytics collection is enabled for this app on this device. This setting is persisted 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 default value is 1800 seconds (30 minutes).
Declaration
Objective-C
+ (void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval;Parameters
sessionTimeoutIntervalThe custom time of inactivity in seconds before the current session terminates.
-
The unique ID for this instance of the application.
Declaration
Objective-C
+ (nonnull NSString *)appInstanceID; -
Clears all analytics data for this instance from the device and resets the app instance ID. FIRAnalyticsConfiguration values will be reset to the default values.
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 event parameters. These parameters persist across app runs. They are of lower precedence than event parameters, so if an event parameter and a parameter set using this API have the same name, the value of the event parameter will be used. The same limitations on event parameters apply to default event parameters.
Declaration
Objective-C
+ (void)setDefaultEventParameters: (nullable NSDictionary<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 existing parameter with the same name. Valid parameters are NSString and NSNumber (signed 64-bit integer and 64-bit floating-point number). Setting a key’s value to [NSNull null] will clear that parameter. Passing in a nil dictionary will clear all parameters.
-
Handles events related to a URL session that are waiting to be processed.
For optimal use of Firebase Analytics, call this method from the [UIApplicationDelegate application:handleEventsForBackgroundURLSession:completionHandler] method of the app delegate in your app.
Declaration
Objective-C
+ (void)handleEventsForBackgroundURLSession:(nonnull NSString *)identifier completionHandler: (nullable void (^)(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 is updated and a new snapshot can be taken.
-
Handles the event when the app is launched by a URL.
Call this method from [UIApplicationDelegate application:openURL:options:] (on iOS 9.0 and above), or [UIApplicationDelegate application:openURL:sourceApplication:annotation:] (on iOS 8.x and below) in your app.
Declaration
Objective-C
+ (void)handleOpenURL:(nonnull NSURL *)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 a Universal Link (on iOS 9.0 and above).
Call this method from [UIApplication continueUserActivity:restorationHandler:] in your app delegate (on iOS 9.0 and above).
Declaration
Objective-C
+ (void)handleUserActivity:(nonnull id)userActivity;Parameters
userActivityThe activity object containing the data associated with the task the user was performing.