FIRAnalytics.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #import <Foundation/Foundation.h>
  2. #import "FIREventNames.h"
  3. #import "FIRParameterNames.h"
  4. #import "FIRUserPropertyNames.h"
  5. NS_ASSUME_NONNULL_BEGIN
  6. /// The top level Firebase Analytics singleton that provides methods for logging events and setting
  7. /// user properties. See <a href="http://goo.gl/gz8SLz">the developer guides</a> for general
  8. /// information on using Firebase Analytics in your apps.
  9. ///
  10. /// @note The Analytics SDK uses SQLite to persist events and other app-specific data. Calling
  11. /// certain thread-unsafe global SQLite methods like `sqlite3_shutdown()` can result in
  12. /// unexpected crashes at runtime.
  13. NS_SWIFT_NAME(Analytics)
  14. @interface FIRAnalytics : NSObject
  15. /// Logs an app event. The event can have up to 25 parameters. Events with the same name must have
  16. /// the same parameters. Up to 500 event names are supported. Using predefined events and/or
  17. /// parameters is recommended for optimal reporting.
  18. ///
  19. /// The following event names are reserved and cannot be used:
  20. /// <ul>
  21. /// <li>ad_activeview</li>
  22. /// <li>ad_click</li>
  23. /// <li>ad_exposure</li>
  24. /// <li>ad_query</li>
  25. /// <li>ad_reward</li>
  26. /// <li>adunit_exposure</li>
  27. /// <li>app_clear_data</li>
  28. /// <li>app_exception</li>
  29. /// <li>app_remove</li>
  30. /// <li>app_store_refund</li>
  31. /// <li>app_store_subscription_cancel</li>
  32. /// <li>app_store_subscription_convert</li>
  33. /// <li>app_store_subscription_renew</li>
  34. /// <li>app_update</li>
  35. /// <li>app_upgrade</li>
  36. /// <li>dynamic_link_app_open</li>
  37. /// <li>dynamic_link_app_update</li>
  38. /// <li>dynamic_link_first_open</li>
  39. /// <li>error</li>
  40. /// <li>firebase_campaign</li>
  41. /// <li>first_open</li>
  42. /// <li>first_visit</li>
  43. /// <li>in_app_purchase</li>
  44. /// <li>notification_dismiss</li>
  45. /// <li>notification_foreground</li>
  46. /// <li>notification_open</li>
  47. /// <li>notification_receive</li>
  48. /// <li>os_update</li>
  49. /// <li>session_start</li>
  50. /// <li>session_start_with_rollout</li>
  51. /// <li>user_engagement</li>
  52. /// </ul>
  53. ///
  54. /// @param name The name of the event. Should contain 1 to 40 alphanumeric characters or
  55. /// underscores. The name must start with an alphabetic character. Some event names are
  56. /// reserved. See FIREventNames.h for the list of reserved event names. The "firebase_",
  57. /// "google_", and "ga_" prefixes are reserved and should not be used. Note that event names are
  58. /// case-sensitive and that logging two events whose names differ only in case will result in
  59. /// two distinct events. To manually log screen view events, use the `screen_view` event name.
  60. /// @param parameters The dictionary of event parameters. Passing `nil` indicates that the event has
  61. /// no parameters. Parameter names can be up to 40 characters long and must start with an
  62. /// alphabetic character and contain only alphanumeric characters and underscores. Only String,
  63. /// Int, and Double parameter types are supported. String parameter values can be up to 100
  64. /// characters long for standard Google Analytics properties, and up to 500 characters long for
  65. /// Google Analytics 360 properties. The "firebase_", "google_", and "ga_" prefixes are reserved
  66. /// and should not be used for parameter names.
  67. + (void)logEventWithName:(NSString *)name
  68. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  69. NS_SWIFT_NAME(logEvent(_:parameters:));
  70. /// Sets a user property to a given value. Up to 25 user property names are supported. Once set,
  71. /// user property values persist throughout the app lifecycle and across sessions.
  72. ///
  73. /// The following user property names are reserved and cannot be used:
  74. /// <ul>
  75. /// <li>first_open_time</li>
  76. /// <li>last_deep_link_referrer</li>
  77. /// <li>user_id</li>
  78. /// </ul>
  79. ///
  80. /// @param value The value of the user property. Values can be up to 36 characters long. Setting the
  81. /// value to `nil` removes the user property.
  82. /// @param name The name of the user property to set. Should contain 1 to 24 alphanumeric characters
  83. /// or underscores and must start with an alphabetic character. The "firebase_", "google_", and
  84. /// "ga_" prefixes are reserved and should not be used for user property names.
  85. + (void)setUserPropertyString:(nullable NSString *)value forName:(NSString *)name
  86. NS_SWIFT_NAME(setUserProperty(_:forName:));
  87. /// Sets the user ID property. This feature must be used in accordance with
  88. /// <a href="https://www.google.com/policies/privacy">Google's Privacy Policy</a>
  89. ///
  90. /// @param userID The user ID to ascribe to the user of this app on this device, which must be
  91. /// non-empty and no more than 256 characters long. Setting userID to `nil` removes the user ID.
  92. + (void)setUserID:(nullable NSString *)userID;
  93. /// Sets whether analytics collection is enabled for this app on this device. This setting is
  94. /// persisted across app sessions. By default it is enabled.
  95. ///
  96. /// @param analyticsCollectionEnabled A flag that enables or disables Analytics collection.
  97. + (void)setAnalyticsCollectionEnabled:(BOOL)analyticsCollectionEnabled;
  98. /// Sets the interval of inactivity in seconds that terminates the current session. The default
  99. /// value is 1800 seconds (30 minutes).
  100. ///
  101. /// @param sessionTimeoutInterval The custom time of inactivity in seconds before the current
  102. /// session terminates.
  103. + (void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval;
  104. /// Asynchronously retrieves the identifier of the current app session.
  105. ///
  106. /// The session ID retrieval could fail due to Analytics collection disabled, app session expired,
  107. /// etc.
  108. ///
  109. /// @param completion The completion handler to call when the session ID retrieval is complete. This
  110. /// handler is executed on a system-defined global concurrent queue.
  111. /// This completion handler takes the following parameters:
  112. /// <b>sessionID</b> The identifier of the current app session. The value is undefined if the
  113. /// request failed.
  114. /// <b>error</b> An error object that indicates why the request failed, or `nil` if the request
  115. /// was successful.
  116. + (void)sessionIDWithCompletion:(void (^)(int64_t sessionID, NSError *_Nullable error))completion;
  117. /// Returns the unique ID for this instance of the application or `nil` if
  118. /// `ConsentType.analyticsStorage` has been set to `ConsentStatus.denied`.
  119. ///
  120. /// @see `FIRAnalytics+Consent.h`
  121. + (nullable NSString *)appInstanceID;
  122. /// Clears all analytics data for this instance from the device and resets the app instance ID.
  123. + (void)resetAnalyticsData;
  124. /// Adds parameters that will be set on every event logged from the SDK, including automatic ones.
  125. /// The values passed in the parameters dictionary will be added to the dictionary of default event
  126. /// parameters. These parameters persist across app runs. They are of lower precedence than event
  127. /// parameters, so if an event parameter and a parameter set using this API have the same name, the
  128. /// value of the event parameter will be used. The same limitations on event parameters apply to
  129. /// default event parameters.
  130. ///
  131. /// @param parameters Parameters to be added to the dictionary of parameters added to every event.
  132. /// They will be added to the dictionary of default event parameters, replacing any existing
  133. /// parameter with the same name. Valid parameters are String, Int, and Double. Setting a key's
  134. /// value to `NSNull()` will clear that parameter. Passing in a `nil` dictionary will clear all
  135. /// parameters.
  136. + (void)setDefaultEventParameters:(nullable NSDictionary<NSString *, id> *)parameters;
  137. /// Unavailable.
  138. - (instancetype)init NS_UNAVAILABLE;
  139. @end
  140. NS_ASSUME_NONNULL_END