Skip to content

Commit

Permalink
Merge pull request #27 from MONEYMONG/feature/moneymong-501-ga-트래킹
Browse files Browse the repository at this point in the history
Feature/moneymong 501 ga 트래킹
  • Loading branch information
Heonbyeong authored Aug 12, 2024
2 parents 8399c38 + cbfdd89 commit 58778c4
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/moneymong/moneymong/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import com.moneymong.moneymong.common.event.EventTracker
import dagger.hilt.android.AndroidEntryPoint
import com.moneymong.moneymong.design_system.theme.MMTheme
import com.moneymong.moneymong.domain.repository.TokenRepository
Expand All @@ -32,8 +33,13 @@ class MainActivity : ComponentActivity() {
lateinit var tokenRepository: TokenRepository
private val expired = mutableStateOf(false)

@Inject
lateinit var eventTracker: EventTracker

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
eventTracker.initialize()

setContent {
MMTheme {
MoneyMongApp(expired.value) {
Expand Down
5 changes: 5 additions & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
plugins {
alias(libs.plugins.moneymong.android.library)
alias(libs.plugins.moneymong.android.library.compose)
alias(libs.plugins.moneymong.android.hilt)
}

android {
Expand All @@ -20,6 +21,10 @@ dependencies {
implementation(libs.orbit.viewModel)
implementation(libs.okhttp)

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
implementation(libs.firebase.crashlytics)

testImplementation(libs.junit4)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.moneymong.moneymong.common.di

import com.moneymong.moneymong.common.event.EventTracker
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object EventModule {

@Provides
@Singleton
fun provideEventTracker(): EventTracker =
EventTracker()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.moneymong.moneymong.common.event

enum class Event(val eventName: String, val desc: String) {
OPERATION_COST_CLICK(
eventName = "operation_cost_click",
desc = "운영비 등록하기 버튼 클릭"
),
LEDGER_CLICK(
eventName = "ledger_click",
desc = "소속 장부 확인 버튼 클릭"
),
OCR_REGISTER_CLICK(
eventName = "ocr_register_click",
desc = "등록하기 버튼 클릭"
),
OCR_MODIFY_CLICK(
eventName = "ocr_modify_click",
desc = "수정하기 버튼 클릭"
),
OCR_MODIFY_TO_REGISTER_CLICK(
eventName = "ocr_modify_to_register_click",
desc = "등록하기 버튼 클릭"
),
PLUS_CLICK(
eventName = "plus_click",
desc = "+ 플로팅 버튼 클릭"
),
HAND_CLICK(
eventName = "hand_click",
desc = "수동 등록 플로팅 버튼 클릭"
),
OCR_CLICK(
eventName = "ocr_click",
desc = "OCR 등록 플로팅 버튼 클릭"
)
;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.moneymong.moneymong.common.event

import android.os.Bundle
import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.analytics
import javax.inject.Inject

class EventTracker @Inject constructor() {

private lateinit var firebaseAnalytics: FirebaseAnalytics
private var initialized: Boolean = false

fun initialize() {
firebaseAnalytics = Firebase.analytics
initialized = true
}

fun logEvent(event: Event, param: Bundle? = null) {
check(initialized) { "logEvent를 호출하기 전 초기화가 필요합니다." }

firebaseAnalytics.logEvent(event.eventName, param)
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.moneymong.moneymong.feature.agency.register.complete

import com.moneymong.moneymong.common.base.BaseViewModel
import com.moneymong.moneymong.common.event.Event
import com.moneymong.moneymong.common.event.EventTracker
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class AgencyRegisterCompleteViewModel @Inject constructor() :
class AgencyRegisterCompleteViewModel @Inject constructor(
private val eventTracker: EventTracker
) :
BaseViewModel<AgencyRegisterCompleteState, AgencyRegisterCompleteSideEffect>(
AgencyRegisterCompleteState
) {

fun navigateToLedger() =
fun navigateToLedger() {
eventTracker.logEvent(Event.LEDGER_CLICK)
eventEmit(sideEffect = AgencyRegisterCompleteSideEffect.NavigateToLedger)
}

fun navigateToAgencySearch() =
eventEmit(sideEffect = AgencyRegisterCompleteSideEffect.NavigateToAgencySearch)

fun navigateToLedgerManual() =
fun navigateToLedgerManual() {
eventTracker.logEvent(Event.OPERATION_COST_CLICK)
eventEmit(sideEffect = AgencyRegisterCompleteSideEffect.NavigateToLedgerManual)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavOptions
import com.example.member.MemberScreen
import com.moneymong.moneymong.common.event.Event
import com.moneymong.moneymong.common.ui.plus
import com.moneymong.moneymong.design_system.R
import com.moneymong.moneymong.design_system.component.bottomSheet.MDSBottomSheet
Expand Down Expand Up @@ -283,7 +284,7 @@ fun LedgerScreen(
height = 24.dp
),
containerColor = Mint03,
onClick = { viewModel.eventEmit(LedgerSideEffect.LedgerNavigateToOCR) }
onClick = viewModel::onClickLedgerRegisterOCR
)
}
if (expandableFab) Spacer(modifier = Modifier.height(10.dp))
Expand All @@ -307,7 +308,7 @@ fun LedgerScreen(
MDSFloatingActionButton(
iconResource = R.drawable.ic_pencil,
containerColor = Mint03,
onClick = { viewModel.eventEmit(LedgerSideEffect.LedgerNavigateToLedgerManual) }
onClick = viewModel::onClickLedgerRegisterManual
)
}
if (expandableFab) Spacer(modifier = Modifier.height(10.dp))
Expand All @@ -325,6 +326,7 @@ fun LedgerScreen(
iconResource = R.drawable.ic_plus_default,
containerColor = containerColor,
onClick = {
viewModel.eventTracker.logEvent(Event.PLUS_CLICK)
expandableFab = !expandableFab
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.util.Log
import androidx.lifecycle.SavedStateHandle
import com.moneymong.moneymong.common.base.BaseViewModel
import com.moneymong.moneymong.common.error.MoneyMongError
import com.moneymong.moneymong.common.event.Event
import com.moneymong.moneymong.common.event.EventTracker
import com.moneymong.moneymong.domain.usecase.agency.FetchAgencyIdUseCase
import com.moneymong.moneymong.domain.usecase.agency.FetchMyAgencyListUseCase
import com.moneymong.moneymong.domain.usecase.agency.SaveAgencyIdUseCase
Expand All @@ -30,6 +32,7 @@ import javax.inject.Inject
@HiltViewModel
class LedgerViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
val eventTracker: EventTracker,
private val fetchLedgerTransactionListUseCase: FetchLedgerTransactionListUseCase,
private val fetchAgencyExistLedgerUseCase: FetchAgencyExistLedgerUseCase,
private val fetchMyAgencyListUseCase: FetchMyAgencyListUseCase,
Expand Down Expand Up @@ -236,6 +239,16 @@ class LedgerViewModel @Inject constructor(
fetchLedgerTransactionList()
}

fun onClickLedgerRegisterOCR() = intent {
eventTracker.logEvent(Event.OCR_CLICK)
postSideEffect(LedgerSideEffect.LedgerNavigateToOCR)
}

fun onClickLedgerRegisterManual() = intent {
eventTracker.logEvent(Event.HAND_CLICK)
postSideEffect(LedgerSideEffect.LedgerNavigateToLedgerManual)
}

fun onDismissOnboarding() = intent {
postDisplayedLedgerOnboardingUseCase(onboardingType = state.onboardingType)
reduce { state.copy(visibleOnboarding = false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.moneymong.moneymong.ocr_detail
import android.content.SharedPreferences
import androidx.compose.ui.text.input.TextFieldValue
import com.moneymong.moneymong.common.base.BaseViewModel
import com.moneymong.moneymong.common.event.Event
import com.moneymong.moneymong.common.event.EventTracker
import com.moneymong.moneymong.common.ext.toMultipart
import com.moneymong.moneymong.common.ui.isValidPaymentDate
import com.moneymong.moneymong.common.ui.isValidPaymentTime
Expand All @@ -29,6 +31,7 @@ import javax.inject.Inject

@HiltViewModel
class OCRDetailViewModel @Inject constructor(
private val eventTracker: EventTracker,
private val prefs: SharedPreferences,
private val postLedgerTransactionUseCase: PostLedgerTransactionUseCase,
private val postFileUploadUseCase: PostFileUploadUseCase,
Expand Down Expand Up @@ -134,6 +137,7 @@ class OCRDetailViewModel @Inject constructor(
}

fun onClickPostLedger() = intent {
eventTracker.logEvent(Event.OCR_MODIFY_TO_REGISTER_CLICK)
postDocumentImage(imageFile = state.receiptFile, isReceipt = true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.moneymong.moneymong.ocr_result

import android.content.SharedPreferences
import com.moneymong.moneymong.common.base.BaseViewModel
import com.moneymong.moneymong.common.event.Event
import com.moneymong.moneymong.common.event.EventTracker
import com.moneymong.moneymong.common.ext.toMultipart
import com.moneymong.moneymong.domain.usecase.agency.FetchAgencyIdUseCase
import com.moneymong.moneymong.domain.usecase.ledger.PostLedgerTransactionUseCase
Expand All @@ -21,6 +23,7 @@ import javax.inject.Inject

@HiltViewModel
class OCRResultViewModel @Inject constructor(
private val eventTracker: EventTracker,
private val prefs: SharedPreferences,
private val postLedgerTransactionUseCase: PostLedgerTransactionUseCase,
private val postFileUploadUseCase: PostFileUploadUseCase,
Expand Down Expand Up @@ -59,6 +62,8 @@ class OCRResultViewModel @Inject constructor(
}

fun postReceiptImage() = intent {
eventTracker.logEvent(Event.OCR_REGISTER_CLICK)

state.receiptFile?.let {
if (!state.isLoading) {
reduce { state.copy(isLoading = true) }
Expand Down Expand Up @@ -93,6 +98,7 @@ class OCRResultViewModel @Inject constructor(

// onClick
fun onClickOCREdit() = intent {
eventTracker.logEvent(Event.OCR_MODIFY_CLICK)
postSideEffect(OCRResultSideEffect.OCRResultNavigateToOCRDetail(state.document))
}
}

0 comments on commit 58778c4

Please sign in to comment.