이벤트는 사용자 작업, 시스템 이벤트 또는 오류와 같이 앱에서 발생하는 상황에 대한 통찰력을 제공합니다.
Google Analytics는 일부 이벤트 를 자동으로 기록합니다. 수신하기 위해 코드를 추가할 필요가 없습니다. 앱에서 추가 데이터를 수집해야 하는 경우 앱에서 최대 500개의 서로 다른 Analytics 이벤트 유형을 기록할 수 있습니다. 앱이 기록하는 총 이벤트 양에는 제한이 없습니다. 이벤트 이름은 대소문자를 구분하며 대소문자만 다른 이름의 두 이벤트를 기록하면 두 개의 개별 이벤트가 생성됩니다.
시작하기 전에
C++용 Analytics 시작하기 에서 설명한 대로 프로젝트를 설정하고 Analytics에 액세스할 수 있는지 확인하십시오.
로그 이벤트
firebase::analytics
모듈을 초기화한 후 이를 사용하여 LogEvent()
메서드로 이벤트를 기록할 수 있습니다.
시작하는 데 도움이 되도록 애널리틱스 SDK는 소매 및 전자상거래, 여행, 게임 앱을 포함하여 다양한 유형의 앱 간에 공통적인 여러 제안 이벤트를 정의합니다. 이러한 이벤트와 사용 시기에 대해 자세히 알아보려면 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]));
규정된 매개변수 외에도 모든 이벤트에 다음 매개변수를 추가할 수 있습니다.
맞춤 매개변수: 맞춤 매개변수는 애널리틱스 보고서에 직접 표시되지 않지만 모든 보고서에 적용할 수 있는 잠재고객 정의에서 필터로 사용할 수 있습니다. 앱이 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 콘솔 대시보드에서 분석 이벤트에 대한 집계된 통계를 볼 수 있습니다. 이 대시보드는 하루 종일 주기적으로 업데이트됩니다. 즉각적인 테스트를 위해 이전 섹션에서 설명한 대로 logcat 출력을 사용합니다.
Firebase 콘솔에서 이 데이터에 액세스하려면 다음 단계를 따르세요.
- Firebase 콘솔 에서 프로젝트를 엽니다.
- Analytics 보고 대시보드를 보려면 메뉴에서 Analytics 를 선택합니다.
이벤트 탭에는 앱에서 기록된 각각의 고유한 분석 이벤트 유형에 대해 자동으로 생성된 이벤트 보고서 가 표시됩니다. Firebase 도움말 센터에서 애널리틱스 보고 대시보드 에 대해 자세히 알아보세요.