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] amplitude user property setting #211

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading