Skip to content

Commit

Permalink
fix: 상점 로깅
Browse files Browse the repository at this point in the history
  • Loading branch information
skdud0629 committed Dec 14, 2024
1 parent 0b93a0a commit 6ad88ff
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ object ExperimentGroup {

const val CALL_NUMBER = "call_number"
const val CALL_FLOATING = "call_floating"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ object EventLogger {
logEvent(action, EventCategory.CLICK, label, value, *extras)
}

fun logClickABTestEvent(action: EventAction, label: String, value: String, vararg extras: EventExtra) {
logEvent(action, EventCategory.ABTEST, label, value, *extras)
}




/**
Expand Down Expand Up @@ -78,6 +73,8 @@ object EventLogger {
param(EVENT_LABEL, "$label (debug)")
param(VALUE, value)
}
println("EventLoggerCustom: ${action}, ${category}, $label, $value, ")

} else {
Firebase.analytics.logEvent(action) {
param(EVENT_CATEGORY, category)
Expand Down Expand Up @@ -128,7 +125,6 @@ enum class EventCategory(val value: String) {
SCROLL("scroll"),
SWIPE("swipe"), // 하단 뒤로가기(아이폰의 swipe 뒤로가기와 대응)
NOTIFICATION("notification"),
ABTEST("a/b test 로깅(전화하기)")
}

data class EventExtra(val key: String, val value: String)
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
scrollPercentage = 100.0f * offset / (range - extent)
}
viewModel.postABTestAssign(Experiment.BENEFIT_STORE.experimentTitle)

storeListButton.setOnClickListener {
gotoStoreActivity(0)
}
Expand Down Expand Up @@ -319,6 +320,42 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
private fun initViewModel() = with(viewModel) {
getStoreCategories(StoreCategories(-1, R.drawable.ic_benefit_icon, "혜택"))

observeLiveData(variableName) {
when (viewModel.variableName.value) {
ExperimentGroup.A -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(3차 스프린트, 혜택페이지)",
label = "BUSINESS_benefit_1",
value = "혜택X"
)
binding.storeButtonLayout.visibility = View.GONE
binding.recyclerViewStoreCategory.visibility = View.VISIBLE
}

ExperimentGroup.B -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(3차 스프린트, 혜택페이지)",
label = "BUSINESS_benefit_1",
value = "혜택O"
)
binding.storeButtonLayout.visibility = View.VISIBLE
binding.recyclerViewStoreCategory.visibility = View.GONE
}

else -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(3차 스프린트, 혜택페이지)",
label = "BUSINESS_benefit_1",
value = "혜택X"
)
binding.storeButtonLayout.visibility = View.GONE
binding.recyclerViewStoreCategory.visibility = View.VISIBLE
}
}
}
observeLiveData(isLoading) {
binding.mainSwipeRefreshLayout.isRefreshing = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
Expand All @@ -22,6 +21,7 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import `in`.koreatech.koin.R
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.EventExtra
Expand Down Expand Up @@ -101,6 +101,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
setContentView(binding.root)
initViewModel()

if (!isABTestAssigned) {
viewModel.postABTestAssign(Experiment.BUSINESS_CALL.experimentTitle)
isABTestAssigned = true
}

binding.koinBaseAppbar.storeDetailClickListener {
when (it.id) {
Expand All @@ -115,28 +119,27 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
reviewElapsedTime = System.currentTimeMillis() - reviewCurrentTime

showCallDialog()
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_CALL,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.DURATION_TIME, (dialogElapsedTime / 1000.0 ).toString())
)

if(intent.extras?.getBoolean(StoreDetailActivityContract.IS_BENEFIT) == true){
if (intent.extras?.getBoolean(StoreDetailActivityContract.IS_BENEFIT) == true) {
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.BENEFIT_SHOP_CALL,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.DURATION_TIME, (dialogElapsedTime / 1000.0 ).toString())
EventExtra(
AnalyticsConstant.DURATION_TIME,
(dialogElapsedTime / 1000.0).toString()
)
)
}
else{
} else {
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_CALL,
(viewModel.store.value?.name
?: "Unknown") ,
EventExtra(AnalyticsConstant.DURATION_TIME, (dialogElapsedTime / 1000.0 ).toString())
?: "Unknown"),
EventExtra(
AnalyticsConstant.DURATION_TIME,
(dialogElapsedTime / 1000.0).toString()
)

)
}
Expand All @@ -147,7 +150,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.PREVIOUS_PAGE, "리뷰"),
EventExtra(AnalyticsConstant.CURRENT_PAGE, currentPage),
EventExtra(AnalyticsConstant.DURATION_TIME, (reviewElapsedTime / 1000.0 ).toString())
EventExtra(
AnalyticsConstant.DURATION_TIME,
(reviewElapsedTime / 1000.0).toString()
)
)
}
}
Expand Down Expand Up @@ -200,7 +206,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.PREVIOUS_PAGE, "리뷰"),
EventExtra(AnalyticsConstant.CURRENT_PAGE, currentPage),
EventExtra(AnalyticsConstant.DURATION_TIME, (reviewElapsedTime / 1000.0 ).toString())
EventExtra(
AnalyticsConstant.DURATION_TIME,
(reviewElapsedTime / 1000.0).toString()
)
)
}
}
Expand All @@ -221,7 +230,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.PREVIOUS_PAGE, "리뷰"),
EventExtra(AnalyticsConstant.CURRENT_PAGE, currentPage),
EventExtra(AnalyticsConstant.DURATION_TIME, (reviewElapsedTime / 1000.0 ).toString())
EventExtra(
AnalyticsConstant.DURATION_TIME,
(reviewElapsedTime / 1000.0).toString()
)
)
}
}
Expand Down Expand Up @@ -288,12 +300,12 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
super.onBackPressed()
}

private fun initCallFunction(){
private fun initCallFunction() {
binding.storeDetailPhoneImage.setOnClickListener {
callingLogic()
}

binding.storeDetailPhoneTextview.setOnClickListener{
binding.storeDetailPhoneTextview.setOnClickListener {
callingLogic()
}

Expand All @@ -302,19 +314,18 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
}
}

private fun callingLogic(){
private fun callingLogic() {
dialogElapsedTime = System.currentTimeMillis() - dialogCurrentTime

showCallDialog()
if(intent.extras?.getBoolean(StoreDetailActivityContract.IS_BENEFIT) == true){
if (intent.extras?.getBoolean(StoreDetailActivityContract.IS_BENEFIT) == true) {
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.BENEFIT_SHOP_CALL,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.DURATION_TIME, (dialogElapsedTime / 1000.0 ).toString())
EventExtra(AnalyticsConstant.DURATION_TIME, (dialogElapsedTime / 1000.0).toString())
)
}
else {
} else {
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_CALL,
Expand All @@ -328,6 +339,35 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
private fun initViewModel() {
withLoading(this@StoreDetailActivity, viewModel)

observeLiveData(viewModel.variableName) {
when (viewModel.variableName.value) {
ExperimentGroup.CALL_NUMBER -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(전화하기)",
label = AnalyticsConstant.Label.BUSINESS_CALL_NUMBER,
value = "number"
)
binding.callFloatingButton.visibility = View.GONE
binding.storeDetailPhoneTextview.setTextColor(
ContextCompat.getColor(
this@StoreDetailActivity,
R.color.colorPrimary
)
)
}

ExperimentGroup.CALL_FLOATING -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(전화하기)",
label = AnalyticsConstant.Label.BUSINESS_CALL_FLOATING,
value = "floating"
)
}
}
}

observeLiveData(viewModel.storeReview) {
binding.storeDetailTabLayout.getTabAt(2)?.text =
getString(R.string.review, it.totalCount.toString())
Expand Down Expand Up @@ -403,8 +443,8 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
binding.storeDetailImageview.apply {
adapter = StoreDetailImageViewpagerAdapter(it.imageUrls) {
ImageZoomableDialog(context, it)
.also {
zoomableDialog -> zoomableDialog.show()
.also { zoomableDialog ->
zoomableDialog.show()
}
EventLogger.logClickEvent(
EventAction.BUSINESS,
Expand All @@ -416,22 +456,6 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
}
}

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.callABTestExperimentGroup.collect {
when (it) {
ExperimentGroup.CALL_NUMBER-> {
binding.callFloatingButton.visibility = View.GONE
binding.storeDetailPhoneTextview.setTextColor(ContextCompat.getColor(this@StoreDetailActivity, R.color.colorPrimary))
}
ExperimentGroup.CALL_FLOATING -> {
binding.scrollUpButton.visibility = View.GONE
binding.storeDetailPhoneImage.visibility = View.GONE
}
}
}
}
}

}

Expand All @@ -447,35 +471,34 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
val category = intent.extras?.getString(StoreDetailActivityContract.CATEGORY)
storeElapsedTime = System.currentTimeMillis() - storeCurrentTime
currentPage = "카테고리($category)"
if ( isSwipeGesture) {
if (isSwipeGesture) {
EventLogger.logSwipeEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_DETAIL_VIEW_BACK,
viewModel.store.value?.name ?: "Unknown" ,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.CURRENT_PAGE, category ?: "Unknown"),
EventExtra(AnalyticsConstant.DURATION_TIME, (storeElapsedTime / 1000.0 ).toString()),
EventExtra(AnalyticsConstant.DURATION_TIME, (storeElapsedTime / 1000.0).toString()),
)

}
else{
} else {
EventLogger.logSwipeEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_DETAIL_VIEW_BACK,
viewModel.store.value?.name ?: "Unknown" ,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.CURRENT_PAGE, category ?: "Unknown"),
EventExtra(AnalyticsConstant.DURATION_TIME, (storeElapsedTime / 1000.0 ).toString()),
EventExtra(AnalyticsConstant.DURATION_TIME, (storeElapsedTime / 1000.0).toString()),
)
}

if(currentTab == 2){
if (currentTab == 2) {
reviewElapsedTime = System.currentTimeMillis() - reviewCurrentTime
EventLogger.logClickEvent(
EventAction.BUSINESS,
AnalyticsConstant.Label.SHOP_DETAIL_VIEW_REVIEW_BACK,
viewModel.store.value?.name ?: "Unknown",
EventExtra(AnalyticsConstant.PREVIOUS_PAGE, "리뷰"),
EventExtra(AnalyticsConstant.CURRENT_PAGE, currentPage),
EventExtra(AnalyticsConstant.DURATION_TIME, (reviewElapsedTime / 1000.0 ).toString())
EventExtra(AnalyticsConstant.DURATION_TIME, (reviewElapsedTime / 1000.0).toString())
)

}
Expand Down Expand Up @@ -553,5 +576,6 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
const val ELAPSED_TIME = "elapsedTime"
const val STORE_NAME = "storeName"
const val BACK_ACTION = "back_action"
var isABTestAssigned = false
}
}
Loading

0 comments on commit 6ad88ff

Please sign in to comment.