Skip to content

Commit

Permalink
feat: FirebaseAnalytics 생성 및 로그 삽입을 담당할 객체 생성 및 상수 모음 파일 생성 (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandr97 authored Aug 3, 2023
1 parent 5795ebf commit 0c50b4c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
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"
}
}
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"
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"

0 comments on commit 0c50b4c

Please sign in to comment.