Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 코스 상세 뷰 앰플리튜드 트래킹 이벤트 코드 심기 #264

Merged
merged 9 commits into from
Sep 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class CourseDetailContract {
val currentImagePage: Int = 0,
val usePointLoadState: LoadState = LoadState.Idle,
val deleteLoadState: LoadState = LoadState.Idle,
var isWebViewOpened: Boolean = false
var isWebViewOpened: Boolean = false,
var hasPointReadDialogOpened: Boolean = false
) : UiState

sealed interface CourseDetailSideEffect : UiSideEffect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ import org.sopt.dateroad.presentation.ui.coursedetail.component.CourseDetailBasi
import org.sopt.dateroad.presentation.ui.coursedetail.component.CourseDetailBottomBar
import org.sopt.dateroad.presentation.ui.coursedetail.component.CourseDetailUnopenedDetail
import org.sopt.dateroad.presentation.ui.coursedetail.component.courseDetailOpenedDetail
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.CLICK_COURSE_BACK
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.CLICK_COURSE_PURCHASE
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.COURSE_LIST_ID
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.COURSE_LIST_TITLE
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.PURCHASE_SUCCESS
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.VIEW_COURSE_DETAILS
import org.sopt.dateroad.presentation.util.WebViewUrl.REPORT_URL
import org.sopt.dateroad.presentation.util.amplitude.AmplitudeUtils
import org.sopt.dateroad.presentation.util.view.LoadState
import org.sopt.dateroad.ui.theme.DATEROADTheme
import org.sopt.dateroad.ui.theme.DateRoadTheme
Expand Down Expand Up @@ -74,6 +81,20 @@ fun CourseDetailRoute(
viewModel.fetchCourseDetail(courseId = courseId)
}

LaunchedEffect(uiState.loadState, lifecycleOwner) {
if (uiState.loadState == LoadState.Success) {
with(uiState.courseDetail) {
AmplitudeUtils.trackEventWithProperties(
eventName = VIEW_COURSE_DETAILS,
mapOf(
COURSE_LIST_ID to courseId,
COURSE_LIST_TITLE to title
)
)
}
}
}

when (uiState.loadState) {
LoadState.Idle -> DateRoadIdleView()

Expand Down Expand Up @@ -110,7 +131,16 @@ fun CourseDetailRoute(
onReportCourseBottomSheet = { viewModel.setEvent(CourseDetailContract.CourseDetailEvent.OnReportCourseBottomSheet) },
dismissReportCourseBottomSheet = { viewModel.setEvent(CourseDetailContract.CourseDetailEvent.DismissReportCourseBottomSheet) },
enrollSchedule = { viewModel.setSideEffect(CourseDetailContract.CourseDetailSideEffect.NavigateToEnroll(EnrollType.TIMELINE, courseId)) },
onTopBarIconClicked = { viewModel.setSideEffect(CourseDetailContract.CourseDetailSideEffect.PopBackStack) },
onTopBarIconClicked = {
viewModel.setSideEffect(CourseDetailContract.CourseDetailSideEffect.PopBackStack)
AmplitudeUtils.trackEventWithProperties(
eventName = CLICK_COURSE_BACK,
properties = mapOf(
CLICK_COURSE_PURCHASE to uiState.hasPointReadDialogOpened,
PURCHASE_SUCCESS to uiState.courseDetail.isAccess
)
)
},
openCourseDetail = { viewModel.postUsePoint(courseId = courseId) },
onReportButtonClicked = {
viewModel.setEvent(CourseDetailContract.CourseDetailEvent.OnReportWebViewClicked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import org.sopt.dateroad.domain.usecase.DeleteCourseUseCase
import org.sopt.dateroad.domain.usecase.GetCourseDetailUseCase
import org.sopt.dateroad.domain.usecase.PostCourseLikeUseCase
import org.sopt.dateroad.domain.usecase.PostUsePointUseCase
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.CLICK_COURSE_LIKES
import org.sopt.dateroad.presentation.util.CourseDetailAmplitude.COURSE_LIST_LIKE
import org.sopt.dateroad.presentation.util.Point
import org.sopt.dateroad.presentation.util.amplitude.AmplitudeUtils
import org.sopt.dateroad.presentation.util.base.BaseViewModel
import org.sopt.dateroad.presentation.util.view.LoadState

Expand All @@ -34,7 +37,7 @@ class CourseDetailViewModel @Inject constructor(
is CourseDetailContract.CourseDetailEvent.DismissDialogDeleteCourse -> setState { copy(isDeleteCourseDialogOpen = false) }
is CourseDetailContract.CourseDetailEvent.OnDialogReportCourse -> setState { copy(isReportCourseDialogOpen = true) }
is CourseDetailContract.CourseDetailEvent.DismissDialogReportCourse -> setState { copy(isReportCourseDialogOpen = false) }
is CourseDetailContract.CourseDetailEvent.OnDialogLookedByPoint -> setState { copy(isPointReadDialogOpen = true) }
is CourseDetailContract.CourseDetailEvent.OnDialogLookedByPoint -> setState { copy(isPointReadDialogOpen = true, hasPointReadDialogOpened = true) }
is CourseDetailContract.CourseDetailEvent.DismissDialogLookedByPoint -> setState { copy(isPointReadDialogOpen = false) }
is CourseDetailContract.CourseDetailEvent.OnLikeButtonClicked -> setState { copy(isLikedButtonChecked = !isLikedButtonChecked) }
is CourseDetailContract.CourseDetailEvent.OnDeleteCourseBottomSheet -> setState { copy(isDeleteCourseBottomSheetOpen = true) }
Expand Down Expand Up @@ -80,6 +83,7 @@ class CourseDetailViewModel @Inject constructor(
)
postCourseLikeUseCase(courseId = courseId).onSuccess {
setEvent(CourseDetailContract.CourseDetailEvent.PostCourseLike(courseDetail = currentState.courseDetail.copy(isUserLiked = true, like = currentState.courseDetail.like + 1)))
AmplitudeUtils.trackEventWithProperty(eventName = CLICK_COURSE_LIKES, propertyName = COURSE_LIST_LIKE, propertyValue = currentState.courseDetail.isUserLiked)
}.onFailure {
setEvent(CourseDetailContract.CourseDetailEvent.PostCourseLike(courseDetail = currentState.courseDetail))
}
Expand All @@ -91,6 +95,7 @@ class CourseDetailViewModel @Inject constructor(
setEvent(CourseDetailContract.CourseDetailEvent.PostUsePoint(usePointLoadState = LoadState.Loading, isAccess = currentState.courseDetail.isAccess))
postUsePointUseCase(courseId = courseId, usePoint = UsePoint(Point.POINT, Point.POINT_USED, Point.POINT_USED_DESCRIPTION)).onSuccess {
setEvent(CourseDetailContract.CourseDetailEvent.PostUsePoint(usePointLoadState = LoadState.Success, isAccess = true))
AmplitudeUtils.trackEventWithProperty(eventName = CLICK_COURSE_LIKES, propertyName = COURSE_LIST_LIKE, propertyValue = currentState.courseDetail.isUserLiked)
}.onFailure {
setEvent(CourseDetailContract.CourseDetailEvent.PostUsePoint(usePointLoadState = LoadState.Error, isAccess = currentState.courseDetail.isAccess))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object Token {
object Time {
const val TIME = " 시간"
}

object LoadingView {
const val LOTTIE = "loading.json"
const val CLIPMIN = 0
Expand All @@ -59,3 +60,14 @@ object Pattern {
private const val NICKNAME_PATTERN = "^[ㄱ-ㅎ가-힣a-zA-Z0-9]*$"
val NICKNAME_REGEX = Regex(NICKNAME_PATTERN)
}

object CourseDetailAmplitude {
const val VIEW_COURSE_DETAILS = "view_course_details"
const val CLICK_COURSE_BACK = "click_course_back"
const val CLICK_COURSE_LIKES = "click_course_likes"
const val COURSE_LIST_ID = "course_list_id"
const val COURSE_LIST_TITLE = "course_list_title"
const val CLICK_COURSE_PURCHASE = "click_course_purchase"
const val PURCHASE_SUCCESS = "purchase_success"
const val COURSE_LIST_LIKE = "course_list_like"
}