Firebase Analytics collects usage and behavior data for your app. The SDK logs two primary types of information:
- Events: What is happening in your app, such as user actions, system events, or errors.
- User properties: Attributes you define to describe segments of your userbase, such as language preference or geographic location.
Analytics automatically logs some events and user properties; you don't need to add any code to enable them. If your app needs to collect additional data, you can set up to 25 different Analytics user properties and log up to 500 different Analytics event types in your app. There is no limit on the total volume of events your app logs.
To access this data:
- In the Firebase console, open your project.
- Select Analytics from the menu to view the Analytics reporting dashboard.
The Events tab shows the event reports that are automatically created for each distinct type of Analytics event logged by your app. Read more about the Analytics reporting dashboard in the Firebase Help Center.
To help you get started, the Analytics SDK defines a number of suggested events that are common among different types of apps, including retail and ecommerce, travel, and gaming apps. To learn more about these events and when to use them, browse the Events and properties articles in the Firebase Help Center. To get the maximum detail in reports, log the suggested Analytics events that make sense for your app and their prescribed parameters. This also ensures that you benefit from the latest Firebase Analytics features as they become available.
Connect your app in the Firebase console
- Install the Firebase SDK.
- In the Firebase console, add your app to your Firebase project.
Add Analytics to your app
In order to use the analytics libraries in your C++ project, you'll need to add it to your build files, so that the appropriate libraries are linked.
Android
Add the Firebase Java Component to the build.gradle file:
compile 'com.google.firebase:firebase-analytics:9.6.1'
Link the following libraries in when you build your C++ component:
libapp.a libanalytics.a
iOS
Before you can build for iOS, you'll need to add the Firebase frameworks to your Xcode project:
- Add the following dependancy to your Podfile:
pod 'Firebase/Core' pod 'Firebase/Analytics'
- Run
$pod install
- Add
firebase.framework
andfirebase_analytics.framework
to your xcode project.
Create and initialize the firebase app
Before you start, you'll need to create and initialize the firebase App:
Android
Create the firebase app, passing the jni environment and a jobject
reference to the java activity as arguments:
app = ::firebase::App::Create(::firebase::AppOptions(), jni_env, activity);
Initialize the Analytics library:
::firebase::analytics::Initialize(app);
iOS
Create the firebase app:
app = ::firebase::App::Create(::firebase::AppOptions());
Initialize the Analytics library:
::firebase::analytics::Initialize(app);
Log events
After you have configured the firebase::App
instance, you can begin to log
events with the LogEvent()
method.
The following example updates the user's score:
analytics::LogEvent(analytics::kEventPostScore, analytics::kParameterScore, 42);
Next Steps
- See your data refresh periodically in the Firebase console.
- Explore the guides on events and user properties.