الانتقال إلى وحدة التحكم

Get Started with Google Analytics for C++

Google 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 user base, 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:

  1. In the Firebase console, open your project.
  2. 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 Google Analytics features as they become available.

Before you begin

Before you can use Google Analytics, you need to:

  • Register your C++ project and configure it to use Firebase.

    If your C++ project already uses Firebase, then it's already registered and configured for Firebase.

  • In your project-level build.gradle file, make sure to include Google's Maven repository in both your buildscript and allprojects sections.

  • Add the Firebase C++ SDK to your C++ project.

Note that adding Firebase to your C++ project involves tasks both in the Firebase console and in your open C++ project (for example, you download Firebase config files from the console, then move them into your C++ 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