firebase:: analytics
Firebase Analytics API.
Summary
Seethe developer guides for general information on using Firebase Analytics in your apps.
Enumerations | |
|---|---|
ConsentStatus | enum The status value of the consent type. |
ConsentType | enum The type of consent to set. |
Functions | |
|---|---|
GetAnalyticsInstanceId() | Future< std::string >Get the instance ID from the analytics service. |
GetAnalyticsInstanceIdLastResult() | Future< std::string >Get the result of the most recentGetAnalyticsInstanceId() call. |
GetSessionId() | Future< int64_t >Asynchronously retrieves the identifier of the current app session. |
GetSessionIdLastResult() | Future< int64_t >Get the result of the most recentGetSessionId() call. |
Initialize(constApp & app) | voidInitialize the Analytics API. |
InitiateOnDeviceConversionMeasurementWithEmailAddress(const char *email_address) | voidInitiates on-device conversion measurement given a user email address on iOS and tvOS (no-op on Android). |
InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(std::vector< unsigned char > hashed_email_address) | voidInitiates on-device conversion measurement given a SHA256-hashed user email address. |
InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(std::vector< unsigned char > hashed_phone_number) | voidInitiates on-device conversion measurement given a SHA256-hashed phone number in E.164 format. |
InitiateOnDeviceConversionMeasurementWithPhoneNumber(const char *phone_number) | voidInitiates on-device conversion measurement given a phone number in E.164 format on iOS (no-op on Android). |
LogEvent(const char *name, const char *parameter_name, const char *parameter_value) | voidLog an event with one string parameter. |
LogEvent(const char *name, const char *parameter_name, const double parameter_value) | voidLog an event with one float parameter. |
LogEvent(const char *name, const char *parameter_name, const int64_t parameter_value) | voidLog an event with one 64-bit integer parameter. |
LogEvent(const char *name, const char *parameter_name, const int parameter_value) | voidLog an event with one integer parameter (stored as a 64-bit integer). |
LogEvent(const char *name) | voidLog an event with no parameters. |
LogEvent(const char *name, constParameter *parameters, size_t number_of_parameters) | voidLog an event with associated parameters. |
LogEvent(const char *name, const std::vector<Parameter > & parameters) | voidLog an event with associated parameters. |
ResetAnalyticsData() | voidClears all analytics data for this app from the device and resets the app instance id. |
SetAnalyticsCollectionEnabled(bool enabled) | voidSets whether analytics collection is enabled for this app on this device. |
SetConsent(const std::map<ConsentType,ConsentStatus > & consent_settings) | voidSets the applicable end user consent state (e.g., for device identifiers) for this app on this device. |
SetDefaultEventParameters(constParameter *parameters, size_t number_of_parameters) | voidAdds parameters that will be set on every event logged from the SDK. |
SetDefaultEventParameters(const std::vector<Parameter > & parameters) | voidAdds parameters that will be set on every event logged from the SDK. |
SetSessionTimeoutDuration(int64_t milliseconds) | voidSets the duration of inactivity that terminates the current session. |
SetUserId(const char *user_id) | voidSets the user ID property. |
SetUserProperty(const char *name, const char *property) | voidSet a user property to the given value. |
Terminate() | voidTerminate the Analytics API. |
Structs | |
|---|---|
| firebase:: | Event parameter. |
Enumerations
ConsentStatus
ConsentStatusThe status value of the consent type.
Supported statuses are kConsentStatusGranted and kConsentStatusDenied.
ConsentType
ConsentTypeThe type of consent to set.
Supported consent types are mapped to corresponding constants in the Android and iOS SDKs. Omitting a type retains its previous status.
Functions
GetAnalyticsInstanceId
Future<std::string>GetAnalyticsInstanceId()
Get the instance ID from the analytics service.
Note: This isnot the same ID as the ID returned by firebase::instance_id::InstanceId.
| Details | |
|---|---|
| Returns | Object which can be used to retrieve the analytics instance ID. |
GetAnalyticsInstanceIdLastResult
Future<std::string>GetAnalyticsInstanceIdLastResult()
Get the result of the most recentGetAnalyticsInstanceId() call.
| Details | |
|---|---|
| Returns | Object which can be used to retrieve the analytics instance ID. |
GetSessionId
Future<int64_t>GetSessionId()
Asynchronously retrieves the identifier of the current app session.
The session ID retrieval could fail due to Analytics collection disabled, or if the app session was expired.
| Details | |
|---|---|
| Returns | Object which can be used to retrieve the identifier of the current app session. |
GetSessionIdLastResult
Future<int64_t>GetSessionIdLastResult()
Get the result of the most recentGetSessionId() call.
| Details | |
|---|---|
| Returns | Object which can be used to retrieve the identifier of the current app session. |
Initialize
voidInitialize(constApp&app)
Initialize the Analytics API.
This must be called prior to calling any other methods in thefirebase::analytics namespace.
See also:firebase::App::GetInstance().
| Details | |||
|---|---|---|---|
| Parameters |
|
InitiateOnDeviceConversionMeasurementWithEmailAddress
voidInitiateOnDeviceConversionMeasurementWithEmailAddress(constchar*email_address)
Initiates on-device conversion measurement given a user email address on iOS and tvOS (no-op on Android).
On iOS and tvOS, this method requires the dependency GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise the invocation results in a no-op.
| Details | |||
|---|---|---|---|
| Parameters |
|
InitiateOnDeviceConversionMeasurementWithHashedEmailAddress
voidInitiateOnDeviceConversionMeasurementWithHashedEmailAddress(std::vector<unsignedchar>hashed_email_address)
Initiates on-device conversion measurement given a SHA256-hashed user email address.
Requires dependency GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise it is a no-op.
| Details | |||
|---|---|---|---|
| Parameters |
|
InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber
voidInitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(std::vector<unsignedchar>hashed_phone_number)
Initiates on-device conversion measurement given a SHA256-hashed phone number in E.164 format.
Requires dependency GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise it is a no-op.
| Details | |||
|---|---|---|---|
| Parameters |
|
InitiateOnDeviceConversionMeasurementWithPhoneNumber
voidInitiateOnDeviceConversionMeasurementWithPhoneNumber(constchar*phone_number)
Initiates on-device conversion measurement given a phone number in E.164 format on iOS (no-op on Android).
On iOS, requires dependency GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise it is a no-op.
| Details | |||
|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,constchar*parameter_name,constchar*parameter_value)
Log an event with one string parameter.
See also:LogEvent(const char*, const Parameter*, size_t)
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,constchar*parameter_name,constdoubleparameter_value)
Log an event with one float parameter.
See also:LogEvent(const char*, const Parameter*, size_t)
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,constchar*parameter_name,constint64_tparameter_value)
Log an event with one 64-bit integer parameter.
See also:LogEvent(const char*, const Parameter*, size_t)
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,constchar*parameter_name,constintparameter_value)
Log an event with one integer parameter (stored as a 64-bit integer).
See also:LogEvent(const char*, const Parameter*, size_t)
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name)
Log an event with no parameters.
See also:LogEvent(const char*, const Parameter*, size_t)
| Details | |||
|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,constParameter*parameters,size_tnumber_of_parameters)
Log an event with associated parameters.
An Event is an important occurrence in your app that you want to measure. You can report up to 500 different types of events per app and you can associate up to 25 unique parameters with each Event type.
Some common events are documented inAnalytics Events (event_names.h), but you may also choose to specify custom event types that are associated with your specific app.
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
LogEvent
voidLogEvent(constchar*name,conststd::vector<Parameter>¶meters)
Log an event with associated parameters.
An Event is an important occurrence in your app that you want to measure. You can report up to 500 different types of events per app and you can associate up to 25 unique parameters with each Event type.
Some common events are documented inAnalytics Events (event_names.h), but you may also choose to specify custom event types that are associated with your specific app.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ResetAnalyticsData
voidResetAnalyticsData()
Clears all analytics data for this app from the device and resets the app instance id.
SetAnalyticsCollectionEnabled
voidSetAnalyticsCollectionEnabled(boolenabled)
Sets whether analytics collection is enabled for this app on this device.
This setting is persisted across app sessions. By default it is enabled.
| Details | |||
|---|---|---|---|
| Parameters |
|
SetConsent
voidSetConsent(conststd::map<ConsentType,ConsentStatus>&consent_settings)
Sets the applicable end user consent state (e.g., for device identifiers) for this app on this device.
Use the consent map to specify individual consent type values. Settings are persisted across app sessions. By default consent types are set to "granted".
SetDefaultEventParameters
voidSetDefaultEventParameters(constParameter*parameters,size_tnumber_of_parameters)
Adds parameters that will be set on every event logged from the SDK.
Adds parameters that will be set on every event logged from the SDK, including automatic ones. The values passed in the parameters bundle will be added to the map 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.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
SetDefaultEventParameters
voidSetDefaultEventParameters(conststd::vector<Parameter>¶meters)
Adds parameters that will be set on every event logged from the SDK.
Adds parameters that will be set on every event logged from the SDK, including automatic ones. The values passed in the parameters bundle will be added to the map 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.
| Details | |||
|---|---|---|---|
| Parameters |
|
SetSessionTimeoutDuration
voidSetSessionTimeoutDuration(int64_tmilliseconds)
Sets the duration of inactivity that terminates the current session.
Note: The default value is 1800000 (30 minutes).
| Details | |||
|---|---|---|---|
| Parameters |
|
SetUserId
voidSetUserId(constchar*user_id)
Sets the user ID property.
This feature must be used in accordance withGoogle's Privacy Policy
| Details | |||
|---|---|---|---|
| Parameters |
|
SetUserProperty
voidSetUserProperty(constchar*name,constchar*property)
Set a user property to the given value.
Properties associated with a user allow a developer to segment users into groups that are useful to their application. Up to 25 properties can be associated with a user.
Suggested property names are listedAnalytics User Properties (user_property_names.h) but you're not limited to this set. For example, the "gamertype" property could be used to store the type of player where a range of values could be "casual", "mid_core", or "core".
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
Terminate
voidTerminate()
Terminate the Analytics API.
Cleans up resources associated with the API.
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-11-18 UTC.