-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FirebaseAnalytics 생성 및 로그 삽입을 담당할 객체 생성 및 상수 모음 파일 생성 (#171)
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
android/app/src/main/java/com/now/naaga/data/firebase/analytics/AnalyticsDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/now/naaga/data/firebase/analytics/ButtonNames.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.now.naaga.data.firebase.analytics | ||
|
||
const val BUTTON = "BUTTON" | ||
|
||
// BeginActivity | ||
const val BEGIN_END_ADVENTURE = "END_ADVENTURE" |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/now/naaga/data/firebase/analytics/ServerErrorNames.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |