Skip to content

Commit

Permalink
Merge pull request #211 from GEON-PPANG/feat-amplitude-user-property-…
Browse files Browse the repository at this point in the history
…setting

[feat] amplitude user property setting
  • Loading branch information
Dan2dani authored Sep 29, 2023
2 parents 906091c + c5bc5ad commit 5f97565
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class ResponseSignup(
)

fun toSignUpInfo() = SignUpInfo(
memberId = data.memberId,
role = data.role,
type = data.type
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sopt.geonppang.domain.model

data class SignUpInfo(
val memberId: Int,
val role: String,
val type: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class AuthViewModel @Inject constructor(
val passwordCheck = MutableStateFlow("")

val nickname = MutableStateFlow("")

private val _flag = MutableStateFlow("")
val flag get() = _flag
private val _memberId = MutableStateFlow<Int?>(null)
val memberId get() = _memberId.asStateFlow()

private val _authRoleType = MutableStateFlow<AuthRoleType?>(null)
val authRoleType get() = _authRoleType.asStateFlow()
Expand Down Expand Up @@ -159,6 +158,9 @@ class AuthViewModel @Inject constructor(
gpDataSource.refreshToken = BEARER_PREFIX + refreshToken
}
_signUpState.value = UiState.Success(true)
if (platformType == PlatformType.NONE) {
_memberId.value = responseBody?.memberId
}
}
.onFailure { throwable ->
Timber.e(throwable.message)
Expand All @@ -172,6 +174,7 @@ class AuthViewModel @Inject constructor(
authRepository.settingNickname(RequestNicknameSetting(nickname))
.onSuccess { response ->
val responseHeader = response.headers()
val responseBody = response.body()
val accessToken = responseHeader[AUTHORIZATION].toString()
val refreshToken = responseHeader[AUTHORIZATION_REFRESH].toString()
gpDataSource.accessToken = BEARER_PREFIX + accessToken
Expand All @@ -180,6 +183,7 @@ class AuthViewModel @Inject constructor(
_signUpState.value = UiState.Success(true)
// 소셜 회원가입 시 자동 로그인 설정
setAutoLogin()
_memberId.value = responseBody?.data?.memberId
}
.onFailure { throwable ->
Timber.e(throwable.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SignActivity :

AuthRoleType.USER -> {
authViewModel.setAutoLogin()
AmplitudeUtils.trackEvent(LOGIN_APP)
moveToMain()
}

Expand Down Expand Up @@ -89,5 +90,6 @@ class SignActivity :
const val SIGNUP_TYPE = "signup type"
const val EMAIL = "EMAIL"
const val KAKAO = "KAKAO"
const val LOGIN_APP = "login_app"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.flow.onEach
class SignUpActivity :
BindingActivity<ActivitySignupBinding>(R.layout.activity_signup) {
private val viewModel: AuthViewModel by viewModels()
private var flag = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -75,7 +74,6 @@ class SignUpActivity :
)
tvEmailErrorMsg.text = getString(R.string.email_validate_to_use)
tvEmailErrorMsg.visibility = View.VISIBLE
flag = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class SignUpNicknameActivity :
viewModel.initNickname()
}
}.launchIn(lifecycleScope)
viewModel.memberId.flowWithLifecycle(lifecycle).onEach { memberId ->
AmplitudeUtils.setUserId(GUNBBANG + memberId)
}.launchIn(lifecycleScope)
}

private fun completeSignUp() {
Expand Down Expand Up @@ -125,5 +128,6 @@ class SignUpNicknameActivity :
const val PASSWORD = "password"
const val COMPLETE_NICKNAME = "complete_nickname"
const val COMPLETE_SIGNUP = "complete_signup"
const val GUNBBANG = "gunbbang"
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/sopt/geonppang/util/AmplitudeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ object AmplitudeUtils {
fun trackEventWithMapProperties(eventName: String, properties: Map<String, Any>) {
amplitude.track(eventName, properties)
}

fun setUserId(userId: String) {
amplitude.setUserId(userId)
}
}

0 comments on commit 5f97565

Please sign in to comment.