Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wateralsie committed Nov 18, 2024
1 parent 0e32ae8 commit ad31847
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package `in`.koreatech.koin.core.analytics

object EventUtils {

private const val SCROLL_THRESHOLD = .7f
private const val SCROLL_THRESHOLD = 70f

fun didCrossedScrollThreshold(prevScrollRatio: Float, currentScrollRatio: Float, threshold: Float = SCROLL_THRESHOLD): Boolean {
return prevScrollRatio < threshold && currentScrollRatio >= threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object AnalyticsConstant {
}

object Label {
const val MAIN_SCROLL = "main_scroll"
const val MAIN_SHOP_CATEGORIES = "main_shop_categories"
const val MAIN_SHOP_BENEFIT = "main_shop_benefit"
const val SHOP_CATEGORIES = "shop_categories"
Expand Down Expand Up @@ -95,6 +96,9 @@ object AnalyticsConstant {
const val BENEFIT_SHOP_CALL = "benefit_shop_call"

const val MENU_SHARE = "menu_share"

const val CAMPUS_DINING_1 = "CAMPUS_dining_1"
const val CAMPUS_NOTICE_1 = "CAMPUS_notice_1"
}

const val PREVIOUS_PAGE = "previous_page"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import `in`.koreatech.koin.core.activity.WebViewActivity
import `in`.koreatech.koin.core.analytics.EventAction
import `in`.koreatech.koin.core.analytics.EventExtra
import `in`.koreatech.koin.core.analytics.EventLogger
import `in`.koreatech.koin.core.analytics.EventUtils
import `in`.koreatech.koin.core.constant.AnalyticsConstant
import `in`.koreatech.koin.core.navigation.Navigator
import `in`.koreatech.koin.core.navigation.SchemeType
Expand Down Expand Up @@ -69,6 +70,8 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
override val screenTitle = "코인 - 메인"
private val viewModel by viewModels<MainActivityViewModel>()

private var scrollPercentage = 0.0f

@Inject
lateinit var navigator: Navigator

Expand Down Expand Up @@ -164,6 +167,25 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {

private fun initView() = with(binding) {
initDiningABTest()
binding.nestedScrollViewMain.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
val offset = binding.nestedScrollViewMain.computeVerticalScrollOffset()
val extent = binding.nestedScrollViewMain.computeVerticalScrollExtent()
val range = binding.nestedScrollViewMain.computeVerticalScrollRange()

val newScrollPercentage = 100.0f * offset / (range - extent)
if (EventUtils.didCrossedScrollThreshold(
scrollPercentage,
newScrollPercentage
) && scrollPercentage.toDouble() != .0
) {
EventLogger.logScrollEvent(
EventAction.CAMPUS,
AnalyticsConstant.Label.MAIN_SCROLL,
"70%"
)
}
scrollPercentage = 100.0f * offset / (range - extent)
}
viewModel.postABTestAssign(Experiment.BENEFIT_STORE.experimentTitle)
storeListButton.setOnClickListener {
gotoStoreActivity(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import `in`.koreatech.koin.core.abtest.Experiment
import `in`.koreatech.koin.core.abtest.ExperimentGroup
import `in`.koreatech.koin.core.analytics.EventAction
import `in`.koreatech.koin.core.analytics.EventLogger
import `in`.koreatech.koin.core.constant.AnalyticsConstant
import `in`.koreatech.koin.core.viewmodel.BaseViewModel
import `in`.koreatech.koin.domain.error.bus.BusErrorHandler
import `in`.koreatech.koin.domain.model.bus.BusNode
Expand Down Expand Up @@ -34,6 +38,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -75,6 +80,14 @@ class MainActivityViewModel @Inject constructor(
val diningABTestExperimentGroup = flow {
abTestUseCase(Experiment.MAIN_DINING_SEE_MORE.experimentTitle).onSuccess {
emit(it)
when (it) {
ExperimentGroup.MAIN_DINING_NEW -> {
EventLogger.logClickEvent(EventAction.CAMPUS, AnalyticsConstant.Label.CAMPUS_DINING_1, "더보기O")
}
ExperimentGroup.MAIN_DINING_ORIGINAL -> {
EventLogger.logClickEvent(EventAction.CAMPUS, AnalyticsConstant.Label.CAMPUS_DINING_1, "더보기X")
}
}
}.onFailure {
emit(Experiment.MAIN_DINING_SEE_MORE.experimentGroups.first())
}
Expand Down
1 change: 1 addition & 0 deletions koin/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
android:layout_marginTop="-24dp">

<androidx.core.widget.NestedScrollView
android:id="@+id/nested_scroll_view_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
Expand Down

0 comments on commit ad31847

Please sign in to comment.