Skip to content

Commit

Permalink
Merge pull request #509 from BCSDLab/fix/campus
Browse files Browse the repository at this point in the history
[Fix] 캠퍼스팀 요구사항 반영
  • Loading branch information
wateralsie authored Dec 19, 2024
2 parents b4b5a2a + 30fa3be commit 4b07d5c
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 126 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/in/koreatech/koin/core/analytics/EventLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ object EventLogger {
logEvent(action, EventCategory.NOTIFICATION, label, value, *extras)
}

/**
* AB테스트 이벤트 로깅
* @param category: 이벤트 종류
* @param label: 이벤트 소분류
* @param value: 이벤트 값
*/
fun logABTestEvent(category: String, label: String, value: String) {
logCustomEvent(EventAction.ABTEST.value, category, label, value)
}

/**
* @param action: 커스텀 이벤트 발생(EventAction 이외에 action)
* @param category: 커스텀 이벤트 종류(EventCategory 이외에 category)
Expand Down Expand Up @@ -118,6 +128,7 @@ enum class EventAction(val value: String) {
BUSINESS("BUSINESS"),
CAMPUS("CAMPUS"),
USER("USER"),
ABTEST("AB_TEST"),
}

enum class EventCategory(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ object AnalyticsConstant {

const val CAMPUS_DINING_1 = "CAMPUS_dining_1"
const val CAMPUS_NOTICE_1 = "CAMPUS_notice_1"
const val APP_MAIN_NOTICE_DETAIL = "app_main_notice_detail"
const val POPULAR_NOTICE_BANNER = "popular_notice_banner"
const val TO_MANAGE_KEYWORD = "to_manage_keyword"

const val BUSINESS_CALL_NUMBER = " BUSINESS_call_1"
const val BUSINESS_CALL_FLOATING = "BUSINESS_call_1"
const val BUSINESS_BENEFIT_1 = "BUSINESS_benefit_1"
const val BUSINESS_CALL_1 = "BUSINESS_call_1"
}

const val PREVIOUS_PAGE = "previous_page"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import `in`.koreatech.koin.data.request.user.UserRequest
import `in`.koreatech.koin.data.response.notification.NotificationPermissionInfoResponse
import `in`.koreatech.koin.data.response.store.StoreReviewResponse
import `in`.koreatech.koin.data.response.user.ABTestResponse
import `in`.koreatech.koin.data.response.user.ABTestTokenResponse
import `in`.koreatech.koin.data.response.user.UserInfoEditResponse
import `in`.koreatech.koin.data.response.user.UserResponse
import retrofit2.Response
Expand Down Expand Up @@ -90,6 +91,9 @@ interface UserAuthApi {
@GET(URLConstant.OWNER.OWNER)
suspend fun getOwnerTokenIsValid()

@POST("abtest/assign/token")
suspend fun updateABTestToken(): ABTestTokenResponse

@POST("abtest/assign")
suspend fun postABTestAssign(@Body abTestRequest: ABTestRequest): ABTestResponse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class UserRepositoryImpl @Inject constructor(
userRemoteDataSource.verifyPassword(PasswordRequest(hashedPassword))
}

override suspend fun updateABTestToken() {
userRemoteDataSource.updateABTestToken().accessHistoryId.also {
tokenLocalDataSource.saveAccessHistoryId(it)
}
}

override suspend fun postABTestAssign(title: String): ABTest {
userRemoteDataSource.postABTestAssign(ABTestRequest(title)).let {
return ABTest(it.variableName, it.accessHistoryId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package `in`.koreatech.koin.data.response.user

import com.google.gson.annotations.SerializedName

data class ABTestTokenResponse(
@SerializedName("accessHistoryId") val accessHistoryId: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class UserRemoteDataSource(
suspend fun verifyPassword(passwordRequest: PasswordRequest) {
userAuthApi.checkPassword(passwordRequest)
}

suspend fun updateABTestToken(): ABTestTokenResponse {
return userAuthApi.updateABTestToken()
}

suspend fun postABTestAssign(abTestRequest: ABTestRequest): ABTestResponse {
return userAuthApi.postABTestAssign(abTestRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ interface UserRepository {
suspend fun deleteDeviceToken()
suspend fun verifyPassword(hashedPassword: String)
suspend fun updateUserPassword(user: User, hashedPassword: String)
suspend fun updateABTestToken()
suspend fun postABTestAssign(title: String) : ABTest
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package `in`.koreatech.koin.domain.usecase.user

import `in`.koreatech.koin.domain.error.user.UserErrorHandler
import `in`.koreatech.koin.domain.model.error.ErrorHandler
import `in`.koreatech.koin.domain.repository.TokenRepository
import `in`.koreatech.koin.domain.repository.UserRepository
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import javax.inject.Inject

class ABTestUseCase @Inject constructor(
private val userRepository: UserRepository,
private val tokenRepository: TokenRepository,
private val userErrorHandler: UserErrorHandler
private val tokenRepository: TokenRepository
) {
suspend operator fun invoke(title: String): Pair<String?, ErrorHandler?> {
return try {
val accessHistory = userRepository.postABTestAssign(title)
val accessHistoryId = accessHistory.accessHistoryId
tokenRepository.saveAccessHistoryId(accessHistoryId)
accessHistory.variableName to null
} catch (t: Throwable) {
null to userErrorHandler.handleVerifyUserPasswordError(t)
private val mutex = Mutex()

suspend operator fun invoke(title: String): Result<String> {
return runCatching {
mutex.withLock {
if (tokenRepository.getAccessHistoryId() == null) {
userRepository.updateABTestToken()
}
}
userRepository.postABTestAssign(title).variableName
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import `in`.koreatech.koin.domain.usecase.user.ABTestUseCase
import `in`.koreatech.koin.domain.usecase.user.GetUserStatusUseCase
import `in`.koreatech.koin.domain.util.DiningUtil
import `in`.koreatech.koin.domain.util.TimeUtil
import `in`.koreatech.koin.domain.util.onFailure
import `in`.koreatech.koin.domain.util.onSuccess
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package `in`.koreatech.koin.ui.main.activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -242,6 +241,11 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
TabLayoutMediator(tabHotArticle, viewPagerHotArticle) { _, _ -> }.attach()

textSeeMoreArticle.setOnClickListener {
EventLogger.logClickEvent(
EventAction.CAMPUS,
AnalyticsConstant.Label.APP_MAIN_NOTICE_DETAIL,
getString(R.string.article_more)
)
startActivity(Intent(this@MainActivity, ArticleActivity::class.java))
}

Expand Down Expand Up @@ -323,33 +327,30 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
observeLiveData(variableName) {
when (viewModel.variableName.value) {
ExperimentGroup.A -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(3차 스프린트, 혜택페이지)",
label = "BUSINESS_benefit_1",
value = "혜택X"
EventLogger.logABTestEvent(
"a/b test 로깅(3차 스프린트, 혜택페이지)",
AnalyticsConstant.Label.BUSINESS_BENEFIT_1,
"혜택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"
EventLogger.logABTestEvent(
"a/b test 로깅(3차 스프린트, 혜택페이지)",
AnalyticsConstant.Label.BUSINESS_BENEFIT_1,
"혜택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"
EventLogger.logABTestEvent(
"a/b test 로깅(3차 스프린트, 혜택페이지)",
AnalyticsConstant.Label.BUSINESS_BENEFIT_1,
"혜택X"
)
binding.storeButtonLayout.visibility = View.GONE
binding.recyclerViewStoreCategory.visibility = View.VISIBLE
Expand All @@ -376,42 +377,6 @@ class MainActivity : KoinNavigationDrawerTimeActivity() {
}
binding.recyclerViewStoreCategory.visibility = View.GONE
binding.storeButtonLayout.visibility = View.VISIBLE
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
}
}
}
}

private fun initBusViewPagerScrollCallback(busArrivalInfos: List<BusArrivalInfo>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package `in`.koreatech.koin.ui.main.viewmodel

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.asFlow
Expand All @@ -9,7 +8,6 @@ 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
Expand All @@ -26,8 +24,6 @@ import `in`.koreatech.koin.domain.usecase.store.GetStoreCategoriesUseCase
import `in`.koreatech.koin.domain.usecase.user.ABTestUseCase
import `in`.koreatech.koin.domain.util.DiningUtil
import `in`.koreatech.koin.domain.util.TimeUtil
import `in`.koreatech.koin.domain.util.onFailure
import `in`.koreatech.koin.domain.util.onSuccess
import `in`.koreatech.koin.ui.main.state.ArticleMainState
import `in`.koreatech.koin.ui.main.state.toContent
import `in`.koreatech.koin.ui.main.state.toNoti
Expand Down Expand Up @@ -65,17 +61,15 @@ class MainActivityViewModel @Inject constructor(
emit(it)
when (it) {
ExperimentGroup.MAIN_BANNER_NEW -> {
EventLogger.logCustomEvent(
"AB_TEST",
EventLogger.logABTestEvent(
"a/b test 로깅(키워드관리 진입 배너)",
AnalyticsConstant.Label.CAMPUS_NOTICE_1,
"진입점O"
)
}

ExperimentGroup.MAIN_BANNER_ORIGINAL -> {
EventLogger.logCustomEvent(
"AB_TEST",
EventLogger.logABTestEvent(
"a/b test 로깅(키워드관리 진입 배너)",
AnalyticsConstant.Label.CAMPUS_NOTICE_1,
"진입점X"
Expand All @@ -96,16 +90,16 @@ class MainActivityViewModel @Inject constructor(
emit(it)
when (it) {
ExperimentGroup.MAIN_DINING_NEW -> {
EventLogger.logClickEvent(
EventAction.CAMPUS,
EventLogger.logABTestEvent(
"a/b test 로깅(식단 메인 진입점)",
AnalyticsConstant.Label.CAMPUS_DINING_1,
"더보기O"
)
}

ExperimentGroup.MAIN_DINING_ORIGINAL -> {
EventLogger.logClickEvent(
EventAction.CAMPUS,
EventLogger.logABTestEvent(
"a/b test 로깅(식단 메인 진입점)",
AnalyticsConstant.Label.CAMPUS_DINING_1,
"더보기X"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.ClipData
import android.content.ClipboardManager
import android.content.SharedPreferences
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
Expand All @@ -14,9 +13,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
Expand Down Expand Up @@ -321,11 +318,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
abtestName = it
when (viewModel.variableName.value) {
ExperimentGroup.CALL_NUMBER -> {
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(전화하기)",
label = AnalyticsConstant.Label.BUSINESS_CALL_NUMBER,
value = "number"
EventLogger.logABTestEvent(
"a/b test 로깅(전화하기)",
AnalyticsConstant.Label.BUSINESS_CALL_1,
"number"
)
binding.callFloatingButton.visibility = View.GONE
binding.storeDetailPhoneTextview.setTextColor(
Expand All @@ -339,11 +335,10 @@ class StoreDetailActivity : KoinNavigationDrawerActivity() {
ExperimentGroup.CALL_FLOATING -> {
binding.scrollUpButton.visibility = View.GONE
binding.storeDetailPhoneImage.visibility = View.GONE
EventLogger.logCustomEvent(
action = "AB_TEST",
category = "a/b test 로깅(전화하기)",
label = AnalyticsConstant.Label.BUSINESS_CALL_FLOATING,
value = "floating"
EventLogger.logABTestEvent(
"a/b test 로깅(전화하기)",
AnalyticsConstant.Label.BUSINESS_CALL_1,
"floating"
)
}
}
Expand Down
Loading

0 comments on commit 4b07d5c

Please sign in to comment.