From 0c50b4ce016efc11701dfdef42c710dc51b9ab82 Mon Sep 17 00:00:00 2001 From: k_dragonm <78788847+briandr97@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:58:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20FirebaseAnalytics=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B0=8F=20=EB=A1=9C=EA=B7=B8=20=EC=82=BD=EC=9E=85=EC=9D=84?= =?UTF-8?q?=20=EB=8B=B4=EB=8B=B9=ED=95=A0=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=83=81=EC=88=98=20=EB=AA=A8=EC=9D=8C?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=20(#171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 2 +- .../firebase/analytics/AnalyticsDelegate.kt | 55 +++++++++++++++++++ .../data/firebase/analytics/ButtonNames.kt | 6 ++ .../firebase/analytics/ServerErrorNames.kt | 6 ++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 android/app/src/main/java/com/now/naaga/data/firebase/analytics/AnalyticsDelegate.kt create mode 100644 android/app/src/main/java/com/now/naaga/data/firebase/analytics/ButtonNames.kt create mode 100644 android/app/src/main/java/com/now/naaga/data/firebase/analytics/ServerErrorNames.kt diff --git a/android/app/build.gradle b/android/app/build.gradle index ce6373bd1..fc1207aae 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -88,6 +88,6 @@ dependencies { // firebase implementation(platform('com.google.firebase:firebase-bom:32.2.0')) - implementation 'com.google.firebase:firebase-analytics-ktx' + implementation "com.google.firebase:firebase-analytics-ktx" implementation("com.google.firebase:firebase-crashlytics-ktx") } diff --git a/android/app/src/main/java/com/now/naaga/data/firebase/analytics/AnalyticsDelegate.kt b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/AnalyticsDelegate.kt new file mode 100644 index 000000000..918815891 --- /dev/null +++ b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/AnalyticsDelegate.kt @@ -0,0 +1,55 @@ +package com.now.naaga.data.firebase.analytics + +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.analytics.ktx.analytics +import com.google.firebase.analytics.ktx.logEvent +import com.google.firebase.ktx.Firebase + +interface AnalyticsDelegate { + val firebaseAnalytics: FirebaseAnalytics + + fun registerAnalytics(lifeCycle: Lifecycle) + fun logClickEvent(id: String, name: String) + fun logServerError(apiName: String, httpCode: Int, errorMessage: String) +} + +class DefaultAnalyticsDelegate() : AnalyticsDelegate, DefaultLifecycleObserver { + override lateinit var firebaseAnalytics: FirebaseAnalytics + + override fun registerAnalytics(lifeCycle: Lifecycle) { + lifeCycle.addObserver(this) + } + + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + firebaseAnalytics = Firebase.analytics + } + + override fun logClickEvent(id: String, name: String) { + firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT) { + param(FirebaseAnalytics.Param.ITEM_ID, id) + param(FirebaseAnalytics.Param.ITEM_NAME, name) + param(FirebaseAnalytics.Param.CONTENT_TYPE, BUTTON) + } + } + + override fun logServerError(apiName: String, httpCode: Int, errorMessage: String) { + firebaseAnalytics.logEvent(SERVER_ERROR) { + param(API_NAME, apiName) + param(HTTP_STATUS_CODE, "$httpCode") + param(ERROR_MESSAGE, errorMessage) + } + } + + companion object { + const val BUTTON = "BUTTON" + const val SERVER_ERROR = "SERVER_ERROR" + + const val API_NAME = "API_NAME" + const val HTTP_STATUS_CODE = "HTTP_STATUS_CODE" + const val ERROR_MESSAGE = "ERROR_MESSAGE" + } +} diff --git a/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ButtonNames.kt b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ButtonNames.kt new file mode 100644 index 000000000..c68781e6c --- /dev/null +++ b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ButtonNames.kt @@ -0,0 +1,6 @@ +package com.now.naaga.data.firebase.analytics + +const val BUTTON = "BUTTON" + +// BeginActivity +const val BEGIN_END_ADVENTURE = "END_ADVENTURE" diff --git a/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ServerErrorNames.kt b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ServerErrorNames.kt new file mode 100644 index 000000000..1122cee08 --- /dev/null +++ b/android/app/src/main/java/com/now/naaga/data/firebase/analytics/ServerErrorNames.kt @@ -0,0 +1,6 @@ +package com.now.naaga.data.firebase.analytics + +const val SERVER_ERROR = "SERVER_ERROR" + +// AdventureService +const val ON_ADVENTURE_BEGIN_ADVENTURE = "BEGIN_ADVENTURE"