イベントは、ユーザー アクション、システム イベント、エラーなど、アプリで何が起こっているかについての洞察を提供します。
Google Analytics は自動的にいくつかのイベントを記録します。それらを受け取るためにコードを追加する必要はありません。アプリで追加のデータを収集する必要がある場合は、アプリで最大 500 の異なる Analytics イベント タイプをログに記録できます。アプリがログに記録するイベントの総量に制限はありません。イベント名は大文字と小文字が区別されることに注意してください。名前の大文字と小文字が異なる 2 つのイベントをログに記録すると、2 つの異なるイベントが発生することに注意してください。
あなたが始める前に
C++ 用 Analytics の使用を開始する で説明されているように、プロジェクトをセットアップし、Analytics にアクセスできることを確認してください。
ログイベント
firebase::analytics
モジュールを初期化したら、それを使用してLogEvent()
メソッドでイベントをログに記録できます。
開始を支援するために、Analytics SDK では、小売、e コマース、旅行、ゲームなどのさまざまな種類のアプリに共通する推奨イベントが多数定義されています。これらのイベントとそれらをいつ使用するかについて詳しくは、Firebase ヘルプセンターのイベントとプロパティの記事を参照してください。
推奨されるイベント タイプの実装の詳細については、次の場所を参照してください。
- 推奨されるイベント:
Event
定数のリストを参照してください。 - 規定のパラメーター:
Parameters
定数のリストを参照してください。
次の例は、推奨されるSELECT_CONTENT
イベントをログに記録する方法を示しています。
const analytics::Parameter kSelectContentParameters[] = { analytics::Parameter(analytics::kParameterItemID , id), analytics::Parameter(analytics::kParameterItemName, "name"), analytics::Parameter(analytics::kUserPropertySignUpMethod, "Google"), analytics::Parameter("favorite_food", mFavoriteFood), analytics::Parameter("user_id", mUserId), }; analytics::LogEvent( analytics::kEventSelectContent, kSelectContentParameters, sizeof(kSelectContentParameters) / sizeof(kSelectContentParameters[0]));
所定のパラメータに加えて、次のパラメータを任意のイベントに追加できます。
カスタム パラメータ: カスタム パラメータは Analytics レポートに直接表示されませんが、すべてのレポートに適用できるオーディエンス定義のフィルタとして使用できます。アプリが BigQuery プロジェクトにリンクされている場合、カスタム パラメータはBigQuery にエクスポートされるデータにも含まれます。
VALUE
パラメータ:VALUE
は、Analytics イベントに関連する主要な指標を蓄積するのに役立つ汎用パラメータです。例には、収益、距離、時間、およびポイントが含まれます。
推奨される分析イベント タイプでは対応できない特定のニーズがアプリケーションにある場合は、次の例に示すように、独自のカスタム分析イベントをログに記録できます。
// Copyright 2016 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "firebase/analytics.h" #include "firebase/analytics/event_names.h" #include "firebase/analytics/parameter_names.h" #include "firebase/analytics/user_property_names.h" #include "firebase/app.h" // Thin OS abstraction layer. #include "main.h" // NOLINT // Execute all methods of the C++ Analytics API. extern "C" int common_main(int argc, const char* argv[]) { namespace analytics = ::firebase::analytics; ::firebase::App* app; LogMessage("Initialize the Analytics library"); #if defined(__ANDROID__) app = ::firebase::App::Create(GetJniEnv(), GetActivity()); #else app = ::firebase::App::Create(); #endif // defined(__ANDROID__) LogMessage("Created the firebase app %x", static_cast<int>(reinterpret_cast<intptr_t>(app))); analytics::Initialize(*app); LogMessage("Initialized the firebase analytics API"); LogMessage("Enabling data collection."); analytics::SetAnalyticsCollectionEnabled(true); // App session times out after 30 minutes. // If the app is placed in the background and returns to the foreground after // the timeout is expired analytics will log a new session. analytics::SetSessionTimeoutDuration(1000 * 60 * 30); LogMessage("Get App Instance ID..."); auto future_result = analytics::GetAnalyticsInstanceId(); while (future_result.status() == firebase::kFutureStatusPending) { if (ProcessEvents(1000)) break; } if (future_result.status() == firebase::kFutureStatusComplete) { LogMessage("Analytics Instance ID %s", future_result.result()->c_str()); } else { LogMessage("ERROR: Failed to fetch Analytics Instance ID %s (%d)", future_result.error_message(), future_result.error()); } LogMessage("Set user properties."); // Set the user's sign up method. analytics::SetUserProperty(analytics::kUserPropertySignUpMethod, "Google"); // Set the user ID. analytics::SetUserId("uber_user_510"); LogMessage("Log current screen."); // Log the user's current screen. analytics::LogEvent(analytics::kEventScreenView, "Firebase Analytics C++ testapp", "testapp" ); // Log an event with no parameters. LogMessage("Log login event."); analytics::LogEvent(analytics::kEventLogin); // Log an event with a floating point parameter. LogMessage("Log progress event."); analytics::LogEvent("progress", "percent", 0.4f); // Log an event with an integer parameter. LogMessage("Log post score event."); analytics::LogEvent(analytics::kEventPostScore, analytics::kParameterScore, 42); // Log an event with a string parameter. LogMessage("Log group join event."); analytics::LogEvent(analytics::kEventJoinGroup, analytics::kParameterGroupID, "spoon_welders"); // Log an event with multiple parameters. LogMessage("Log level up event."); { const analytics::Parameter kLevelUpParameters[] = { analytics::Parameter(analytics::kParameterLevel, 5), analytics::Parameter(analytics::kParameterCharacter, "mrspoon"), analytics::Parameter("hit_accuracy", 3.14f), }; analytics::LogEvent( analytics::kEventLevelUp, kLevelUpParameters, sizeof(kLevelUpParameters) / sizeof(kLevelUpParameters[0])); } LogMessage("Complete"); // Wait until the user wants to quit the app. while (!ProcessEvents(1000)) { } analytics::Terminate(); delete app; LogMessage("Shutdown"); return 0; }
Android Studio デバッグ ログでイベントを表示する
詳細ログを有効にして、SDK によるイベントのログを監視し、イベントが適切にログに記録されていることを確認できます。これには、自動的に記録されたイベントと手動で記録されたイベントの両方が含まれます。
一連の adb コマンドを使用して詳細ログを有効にできます。
adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC
このコマンドは、Android Studio の logcat にイベントを表示するので、イベントが送信されていることをすぐに確認できます。
ダッシュボードで分析イベントを表示する
Firebase コンソール ダッシュボードで、Analytics イベントに関する集計された統計を表示できます。これらのダッシュボードは、1 日を通して定期的に更新されます。すぐにテストするには、前のセクションで説明した logcat 出力を使用します。
Firebase コンソールでこのデータにアクセスするには:
- Firebase コンソールで、プロジェクトを開きます。
- メニューから [ Analytics ] を選択して、Analytics レポート ダッシュボードを表示します。
[イベント] タブには、アプリによって記録された分析イベントの種類ごとに自動的に作成されるイベント レポートが表示されます。 Firebase ヘルプセンターでアナリティクス レポート ダッシュボードの詳細をご覧ください。