firebase::analytics

Firebase Analytics API.

Summary

See the 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 recent GetAnalyticsInstanceId() call.
GetSessionId()
Future< int64_t >
Asynchronously retrieves the identifier of the current app session.
GetSessionIdLastResult()
Future< int64_t >
Get the result of the most recent GetSessionId() call.
Initialize(const App & app)
void
Initialize the Analytics API.
InitiateOnDeviceConversionMeasurementWithEmailAddress(const char *email_address)
void
Initiates 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)
void
Initiates on-device conversion measurement given a SHA256-hashed user email address.
InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(std::vector< unsigned char > hashed_phone_number)
void
Initiates on-device conversion measurement given a SHA256-hashed phone number in E.164 format.
InitiateOnDeviceConversionMeasurementWithPhoneNumber(const char *phone_number)
void
Initiates 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)
void
Log an event with one string parameter.
LogEvent(const char *name, const char *parameter_name, const double parameter_value)
void
Log an event with one float parameter.
LogEvent(const char *name, const char *parameter_name, const int64_t parameter_value)
void
Log an event with one 64-bit integer parameter.
LogEvent(const char *name, const char *parameter_name, const int parameter_value)
void
Log an event with one integer parameter (stored as a 64-bit integer).
LogEvent(const char *name)
void
Log an event with no parameters.
LogEvent(const char *name, const Parameter *parameters, size_t number_of_parameters)
void
Log an event with associated parameters.
ResetAnalyticsData()
void
Clears all analytics data for this app from the device and resets the app instance id.
SetAnalyticsCollectionEnabled(bool enabled)
void
Sets whether analytics collection is enabled for this app on this device.
SetConsent(const std::map< ConsentType, ConsentStatus > & consent_settings)
void
Sets the applicable end user consent state (e.g., for device identifiers) for this app on this device.
SetSessionTimeoutDuration(int64_t milliseconds)
void
Sets the duration of inactivity that terminates the current session.
SetUserId(const char *user_id)
void
Sets the user ID property.
SetUserProperty(const char *name, const char *property)
void
Set a user property to the given value.
Terminate()
void
Terminate the Analytics API.

Structs

firebase::analytics::Parameter

Event parameter.

Enumerations

ConsentStatus

 ConsentStatus

The status value of the consent type.

Supported statuses are kConsentStatusGranted and kConsentStatusDenied.

ConsentType

 ConsentType

The 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.

Details
Returns
Object which can be used to retrieve the analytics instance ID.

GetAnalyticsInstanceIdLastResult

Future< std::string > GetAnalyticsInstanceIdLastResult()

Get the result of the most recent GetAnalyticsInstanceId() 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 recent GetSessionId() call.

Details
Returns
Object which can be used to retrieve the identifier of the current app session.

Initialize

void Initialize(
  const App & app
)

Initialize the Analytics API.

This must be called prior to calling any other methods in the firebase::analytics namespace.

See also:firebase::App::GetInstance().

Details
Parameters
app
Default firebase::App instance.

InitiateOnDeviceConversionMeasurementWithEmailAddress

void InitiateOnDeviceConversionMeasurementWithEmailAddress(
  const char *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
email_address
User email address. Include a domain name for all email addresses (e.g. gmail.com or hotmail.co.jp).

InitiateOnDeviceConversionMeasurementWithHashedEmailAddress

void InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(
  std::vector< unsigned char > 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
hashed_email_address
User email address as a UTF8-encoded string normalized and hashed according to the instructions at https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3.

InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber

void InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
  std::vector< unsigned char > 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
hashed_phone_number
UTF8-encoded user phone number in E.164 format and then hashed according to the instructions at https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3.

InitiateOnDeviceConversionMeasurementWithPhoneNumber

void InitiateOnDeviceConversionMeasurementWithPhoneNumber(
  const char *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
phone_number
User phone number. Must be in E.164 format, which means it must be limited to a maximum of 15 digits and must include a plus sign (+) prefix and country code with no dashes, parentheses, or spaces.

LogEvent

void LogEvent(
  const char *name,
  const char *parameter_name,
  const char *parameter_value
)

Log an event with one string parameter.

See also: LogEvent(const char*, const Parameter*, size_t)

Details
Parameters
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.
parameter_name
Name of the parameter to log. For more information, see Parameter.
parameter_value
Value of the parameter to log.

LogEvent

void LogEvent(
  const char *name,
  const char *parameter_name,
  const double parameter_value
)

Log an event with one float parameter.

See also: LogEvent(const char*, const Parameter*, size_t)

Details
Parameters
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.
parameter_name
Name of the parameter to log. For more information, see Parameter.
parameter_value
Value of the parameter to log.

LogEvent

void LogEvent(
  const char *name,
  const char *parameter_name,
  const int64_t parameter_value
)

Log an event with one 64-bit integer parameter.

See also: LogEvent(const char*, const Parameter*, size_t)

Details
Parameters
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.
parameter_name
Name of the parameter to log. For more information, see Parameter.
parameter_value
Value of the parameter to log.

LogEvent

void LogEvent(
  const char *name,
  const char *parameter_name,
  const int parameter_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
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.
parameter_name
Name of the parameter to log. For more information, see Parameter.
parameter_value
Value of the parameter to log.

LogEvent

void LogEvent(
  const char *name
)

Log an event with no parameters.

See also: LogEvent(const char*, const Parameter*, size_t)

Details
Parameters
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.

LogEvent

void LogEvent(
  const char *name,
  const Parameter *parameters,
  size_t number_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 in Analytics Events (event_names.h), but you may also choose to specify custom event types that are associated with your specific app.

Details
Parameters
name
Name of the event to log. Should contain 1 to 40 alphanumeric characters or underscores. The name must start with an alphabetic character. Some event names are reserved. See Analytics Events (event_names.h) for the list of reserved event names. The "firebase_" prefix is 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.
parameters
Array of Parameter structures.
number_of_parameters
Number of elements in the parameters array.

ResetAnalyticsData

void ResetAnalyticsData()

Clears all analytics data for this app from the device and resets the app instance id.

SetAnalyticsCollectionEnabled

void SetAnalyticsCollectionEnabled(
  bool enabled
)

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
enabled
true to enable analytics collection, false to disable.

SetConsent

void SetConsent(
  const std::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".

SetSessionTimeoutDuration

void SetSessionTimeoutDuration(
  int64_t milliseconds
)

Sets the duration of inactivity that terminates the current session.

Details
Parameters
milliseconds
The duration of inactivity that terminates the current session.

SetUserId

void SetUserId(
  const char *user_id
)

Sets the user ID property.

This feature must be used in accordance with Google's Privacy Policy

Details
Parameters
user_id
The user ID associated with the user of this app on this device. The user ID must be non-empty and no more than 256 characters long. Setting user_id to NULL or nullptr removes the user ID.

SetUserProperty

void SetUserProperty(
  const char *name,
  const char *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 listed Analytics 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
name
Name of the user property to set. This must be a combination of letters and digits (matching the regular expression [a-zA-Z0-9] between 1 and 40 characters long starting with a letter [a-zA-Z] character.
property
Value to set the user property to. Set this argument to NULL or nullptr to remove the user property. The value can be between 1 to 100 characters long.

Terminate

void Terminate()

Terminate the Analytics API.

Cleans up resources associated with the API.