Skip to content

Commit

Permalink
Merge pull request #83 from AdultOfNineteen/feature/issue-82
Browse files Browse the repository at this point in the history
[FEAT] Amplitude 이벤트 수집 - 홈 탭
  • Loading branch information
DongChyeon authored Aug 2, 2024
2 parents d2f5ca4 + ccc951c commit 9f10151
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/teamwiney/winey/WineyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.teamwiney.winey

import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import com.teamwiney.core.common.di.AmplitudeProvider
import com.teamwiney.core.common.AmplitudeProvider
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.teamwiney.core.common

enum class AmplitudeEvent {
HOME_ENTER,
WINE_DETAIL_CLICK,
ANALYZE_BUTTON_CLICK,
TIP_POST_CLICK;

val eventName: String
get() = name
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.teamwiney.core.common.di
package com.teamwiney.core.common

import android.content.Context
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
import com.amplitude.android.DefaultTrackingOptions
import com.amplitude.android.utilities.AndroidLoggerProvider
import com.teamwiney.core.common.BuildConfig

object AmplitudeProvider {
private var amplitude: Amplitude? = null
Expand All @@ -25,7 +24,7 @@ object AmplitudeProvider {
return amplitude ?: throw IllegalStateException("Amplitude is not initialized")
}

fun trackEvent(eventName: String) {
getAmplitude().track(eventName)
fun trackEvent(event: AmplitudeEvent) {
getAmplitude().track(event.eventName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ object AuthDestinations {
const val PHONE = "signUpPhone"
const val AUTHENTICATION = "signUpAuthentication"
const val FAVORITE_TASTE = "signUpFavoriteTaste"
const val TASTE_RESULT = "signUpTasteResult"
const val COMPLETE = "signUpComplete"
}
}
Expand Down
11 changes: 9 additions & 2 deletions feature/home/src/main/java/com/teamwiney/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey
import com.teamwiney.analysis.component.TipCard
import com.teamwiney.core.common.AmplitudeEvent
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.di.AmplitudeProvider
import com.teamwiney.core.common.AmplitudeProvider
import com.teamwiney.core.common.navigation.HomeDestinations
import com.teamwiney.core.design.R
import com.teamwiney.data.network.model.response.RecommendWine
Expand All @@ -74,6 +75,10 @@ fun HomeScreen(
val wineTips = uiState.wineTips.collectAsLazyPagingItems()
val wineTipsRefreshState = wineTips.loadState.refresh

LaunchedEffect(true) {
AmplitudeProvider.trackEvent(AmplitudeEvent.HOME_ENTER)
}

LaunchedEffect(wineTipsRefreshState) {
if (wineTipsRefreshState is LoadState.Error) {
val errorMessage = wineTipsRefreshState.error.message ?: "네트워크 오류가 발생했습니다."
Expand Down Expand Up @@ -111,7 +116,7 @@ fun HomeScreen(
HomeLogo(
onClick = {
viewModel.processEvent(HomeContract.Event.ShowAnalysis)
AmplitudeProvider.trackEvent("analysis_button_click")
AmplitudeProvider.trackEvent(AmplitudeEvent.ANALYZE_BUTTON_CLICK)
},
hintPopupOpen = uiState.isFirstScroll
)
Expand Down Expand Up @@ -194,6 +199,7 @@ fun HomeWineTips(
thumbnail = it.thumbnail,
onClick = {
viewModel.processEvent(HomeContract.Event.ShowTipDetail(it.url))
AmplitudeProvider.trackEvent(AmplitudeEvent.TIP_POST_CLICK)
}
)
}
Expand Down Expand Up @@ -290,6 +296,7 @@ private fun HomeRecommendWine(
},
onShowDetail = {
processEvent(HomeContract.Event.ShowWineCardDetail(recommendWines[page].wineId))
AmplitudeProvider.trackEvent(AmplitudeEvent.WINE_DETAIL_CLICK)
},
color = recommendWines[page].type,
name = recommendWines[page].name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HomeViewModel @Inject constructor(
}
}

fun getRecommendWines() = viewModelScope.launch {
private fun getRecommendWines() = viewModelScope.launch {
wineRepository.getRecommendWines().onStart {
updateState(currentState.copy(isLoading = true))
}.collectLatest {
Expand Down Expand Up @@ -130,7 +130,7 @@ class HomeViewModel @Inject constructor(
}
}

fun getWineTips() = viewModelScope.launch {
private fun getWineTips() = viewModelScope.launch {
updateState(
currentState.copy(
wineTips = Pager(
Expand Down

0 comments on commit 9f10151

Please sign in to comment.