Skip to content

Commit

Permalink
fix: Address PR comments by Kirill
Browse files Browse the repository at this point in the history
fix: LEARNER-9876
  • Loading branch information
omerhabib26 committed Mar 18, 2024
1 parent 6f86bfe commit 5ae94f0
Show file tree
Hide file tree
Showing 36 changed files with 634 additions and 630 deletions.
36 changes: 21 additions & 15 deletions app/src/main/java/org/openedx/app/AppAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ interface AppAnalytics {
fun logEvent(event: String, params: Map<String, Any?>)
}


enum class AppAnalyticEvent(val event: String) {
LAUNCH("Launch"),
DISCOVER("MainDashboard:Discover"),
MY_COURSES("MainDashboard:My Courses"),
MY_PROGRAMS("MainDashboard:My Programs"),
PROFILE("MainDashboard:Profile"),
}

enum class AppAnalyticValues(val value: String) {
LAUNCH("edx.bi.app.launch"),
DISCOVER("edx.bi.app.main_dashboard.discover"),
MY_COURSES("edx.bi.app.main_dashboard.my_courses"),
MY_PROGRAMS("edx.bi.app.main_dashboard.my_programs"),
PROFILE("edx.bi.app.main_dashboard.profile"),
enum class AppAnalyticsEvent(val eventName: String, val biValue: String) {
LAUNCH(
"Launch",
"edx.bi.app.launch"
),
DISCOVER(
"MainDashboard:Discover",
"edx.bi.app.main_dashboard.discover"
),
MY_COURSES(
"MainDashboard:My Courses",
"edx.bi.app.main_dashboard.my_courses"
),
MY_PROGRAMS(
"MainDashboard:My Programs",
"edx.bi.app.main_dashboard.my_programs"
),
PROFILE(
"MainDashboard:Profile",
"edx.bi.app.main_dashboard.profile"
),
}

enum class AppAnalyticKey(val key: String) {
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/org/openedx/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ class AppViewModel(
}

fun logAppLaunchEvent() {
logEvent(AppAnalyticEvent.LAUNCH, AppAnalyticValues.LAUNCH)
analytics.logEvent(
event = AppAnalyticsEvent.LAUNCH.eventName,
params = buildMap {
put(AppAnalyticKey.NAME.key, AppAnalyticsEvent.LAUNCH.biValue)
})
}

private fun setUserId() {
preferencesManager.user?.let {
analytics.setUserIdForSession(it.id)
}
}

private fun logEvent(event: AppAnalyticEvent, biValue: AppAnalyticValues) {
analytics.logEvent(event.event, buildMap {
put(AppAnalyticKey.NAME.key, biValue.value)
})
}
}
14 changes: 7 additions & 7 deletions app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ class MainViewModel(
}

fun logDiscoveryTabClickedEvent() {
logEvent(AppAnalyticEvent.DISCOVER, AppAnalyticValues.DISCOVER)
logEvent(AppAnalyticsEvent.DISCOVER)
}

fun logMyCoursesTabClickedEvent() {
logEvent(AppAnalyticEvent.MY_COURSES, AppAnalyticValues.MY_COURSES)
logEvent(AppAnalyticsEvent.MY_COURSES)
}

fun logMyProgramsTabClickedEvent() {
logEvent(AppAnalyticEvent.MY_PROGRAMS, AppAnalyticValues.MY_PROGRAMS)
logEvent(AppAnalyticsEvent.MY_PROGRAMS)
}

fun logProfileTabClickedEvent() {
logEvent(AppAnalyticEvent.PROFILE, AppAnalyticValues.PROFILE)
logEvent(AppAnalyticsEvent.PROFILE)
}

private fun logEvent(event: AppAnalyticEvent, biValue: AppAnalyticValues) {
analytics.logEvent(event.event,
private fun logEvent(event: AppAnalyticsEvent) {
analytics.logEvent(event.eventName,
buildMap {
put(AppAnalyticKey.NAME.key, biValue.value)
put(AppAnalyticKey.NAME.key, event.biValue)
})
}
}
71 changes: 45 additions & 26 deletions auth/src/main/java/org/openedx/auth/presentation/AuthAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,51 @@ interface AuthAnalytics {
fun logEvent(event: String, params: Map<String, Any?>)
}

enum class LogistrationAnalyticEvent(val event: String) {
DISCOVERY_COURSES_SEARCH("Logistration:Courses Search"),
EXPLORE_ALL_COURSES("Logistration:Explore All Courses"),
REGISTER_CLICKED("Logistration:Register Clicked"),
CREATE_ACCOUNT_CLICKED("Logistration:Create Account Clicked"),
REGISTER_SUCCESS("Logistration:Register Success"),
SIGN_IN_CLICKED("Logistration:Sign In Clicked"),
USER_SIGN_IN_CLICKED("Logistration:User Sign In Clicked"),
SIGN_IN_SUCCESS("Logistration:Sign In Success"),
FORGOT_PASSWORD_CLICKED("Logistration:Forgot Password Clicked"),
RESET_PASSWORD_CLICKED("Logistration:Reset Password Clicked"),
RESET_PASSWORD_SUCCESS("Logistration:Reset Password Success"),
}

enum class LogistrationAnalyticValues(val biValue: String) {
DISCOVERY_COURSES_SEARCH("edx.bi.app.logistration.courses_search"),
EXPLORE_ALL_COURSES("edx.bi.app.logistration.explore.all.courses"),
REGISTER_CLICKED("edx.bi.app.logistration.register.clicked"),
CREATE_ACCOUNT_CLICKED("edx.bi.app.logistration.user.create_account.clicked"),
REGISTER_SUCCESS("edx.bi.app.user.register.success"),
SIGN_IN_CLICKED("edx.bi.app.logistration.signin.clicked"),
USER_SIGN_IN_CLICKED("edx.bi.app.logistration.user.signin.clicked"),
SIGN_IN_SUCCESS("edx.bi.app.user.signin.success"),
FORGOT_PASSWORD_CLICKED("edx.bi.app.logistration.forgot_password.clicked"),
RESET_PASSWORD_CLICKED("edx.bi.app.user.reset_password.clicked"),
RESET_PASSWORD_SUCCESS("edx.bi.app.user.reset_password.success"),
enum class LogistrationAnalyticsEvent(val eventName: String, val biValue: String) {
DISCOVERY_COURSES_SEARCH(
"Logistration:Courses Search",
"edx.bi.app.logistration.courses_search"
),
EXPLORE_ALL_COURSES(
"Logistration:Explore All Courses",
"edx.bi.app.logistration.explore.all.courses"
),
REGISTER_CLICKED(
"Logistration:Register Clicked",
"edx.bi.app.logistration.register.clicked"
),
CREATE_ACCOUNT_CLICKED(
"Logistration:Create Account Clicked",
"edx.bi.app.logistration.user.create_account.clicked"
),
REGISTER_SUCCESS(
"Logistration:Register Success",
"edx.bi.app.user.register.success"
),
SIGN_IN_CLICKED(
"Logistration:Sign In Clicked",
"edx.bi.app.logistration.signin.clicked"
),
USER_SIGN_IN_CLICKED(
"Logistration:User Sign In Clicked",
"edx.bi.app.logistration.user.signin.clicked"
),
SIGN_IN_SUCCESS(
"Logistration:Sign In Success",
"edx.bi.app.user.signin.success"
),
FORGOT_PASSWORD_CLICKED(
"Logistration:Forgot Password Clicked",
"edx.bi.app.logistration.forgot_password.clicked"
),
RESET_PASSWORD_CLICKED(
"Logistration:Reset Password Clicked",
"edx.bi.app.user.reset_password.clicked"
),
RESET_PASSWORD_SUCCESS(
"Logistration:Reset Password Success",
"edx.bi.app.user.reset_password.success"
),
}

enum class LogistrationAnalyticKey(val key: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package org.openedx.auth.presentation.logistration
import androidx.fragment.app.FragmentManager
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.auth.presentation.AuthRouter
import org.openedx.auth.presentation.LogistrationAnalyticEvent
import org.openedx.auth.presentation.LogistrationAnalyticKey
import org.openedx.auth.presentation.LogistrationAnalyticValues
import org.openedx.auth.presentation.LogistrationAnalyticsEvent
import org.openedx.core.BaseViewModel
import org.openedx.core.config.Config
import org.openedx.core.extension.takeIfNotEmpty
Expand All @@ -21,18 +20,12 @@ class LogistrationViewModel(

fun navigateToSignIn(parentFragmentManager: FragmentManager) {
router.navigateToSignIn(parentFragmentManager, courseId, null)
logEvent(
LogistrationAnalyticEvent.SIGN_IN_CLICKED,
LogistrationAnalyticValues.SIGN_IN_CLICKED
)
logEvent(LogistrationAnalyticsEvent.SIGN_IN_CLICKED)
}

fun navigateToSignUp(parentFragmentManager: FragmentManager) {
router.navigateToSignUp(parentFragmentManager, courseId, null)
logEvent(
LogistrationAnalyticEvent.REGISTER_CLICKED,
LogistrationAnalyticValues.REGISTER_CLICKED
)
logEvent(LogistrationAnalyticsEvent.REGISTER_CLICKED)
}

fun navigateToDiscovery(parentFragmentManager: FragmentManager, querySearch: String) {
Expand All @@ -49,23 +42,22 @@ class LogistrationViewModel(
}
querySearch.takeIfNotEmpty()?.let {
logEvent(
LogistrationAnalyticEvent.DISCOVERY_COURSES_SEARCH,
LogistrationAnalyticValues.DISCOVERY_COURSES_SEARCH,
buildMap { put(LogistrationAnalyticKey.SEARCH_QUERY.key, querySearch) })
} ?: logEvent(
LogistrationAnalyticEvent.EXPLORE_ALL_COURSES,
LogistrationAnalyticValues.EXPLORE_ALL_COURSES
)
LogistrationAnalyticsEvent.DISCOVERY_COURSES_SEARCH,
buildMap {
put(LogistrationAnalyticKey.SEARCH_QUERY.key, querySearch)
})
} ?: logEvent(LogistrationAnalyticsEvent.EXPLORE_ALL_COURSES)
}

private fun logEvent(
eventName: LogistrationAnalyticEvent,
biValue: LogistrationAnalyticValues,
params: Map<String, Any?> = emptyMap()
event: LogistrationAnalyticsEvent,
params: Map<String, Any?> = emptyMap(),
) {
analytics.logEvent(eventName.event, buildMap {
put(LogistrationAnalyticKey.NAME.key, biValue.biValue)
putAll(params)
})
analytics.logEvent(
event = event.eventName,
params = buildMap {
put(LogistrationAnalyticKey.NAME.key, event.biValue)
putAll(params)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.auth.presentation.LogistrationAnalyticEvent
import org.openedx.auth.presentation.LogistrationAnalyticKey
import org.openedx.auth.presentation.LogistrationAnalyticValues
import org.openedx.auth.presentation.LogistrationAnalyticsEvent
import org.openedx.core.BaseViewModel
import org.openedx.core.R
import org.openedx.core.SingleEventLiveData
Expand All @@ -24,7 +23,7 @@ class RestorePasswordViewModel(
private val interactor: AuthInteractor,
private val resourceManager: ResourceManager,
private val analytics: AuthAnalytics,
private val appUpgradeNotifier: AppUpgradeNotifier
private val appUpgradeNotifier: AppUpgradeNotifier,
) : BaseViewModel() {

private val _uiState = MutableLiveData<RestorePasswordUIState>()
Expand All @@ -44,6 +43,7 @@ class RestorePasswordViewModel(
}

fun passwordReset(email: String) {
logEvent(LogistrationAnalyticsEvent.RESET_PASSWORD_CLICKED)
_uiState.value = RestorePasswordUIState.Loading
viewModelScope.launch {
try {
Expand Down Expand Up @@ -87,22 +87,24 @@ class RestorePasswordViewModel(
}
}

fun logResetPasswordClickedEvent() {
analytics.logEvent(
LogistrationAnalyticEvent.RESET_PASSWORD_CLICKED.event,
private fun logResetPasswordEvent(success: Boolean) {
logEvent(
LogistrationAnalyticsEvent.RESET_PASSWORD_SUCCESS,
buildMap {
put(LogistrationAnalyticKey.NAME.key, LogistrationAnalyticValues.RESET_PASSWORD_CLICKED.biValue)
put(LogistrationAnalyticKey.SUCCESS.key, success)
}
)
}

private fun logResetPasswordEvent(success: Boolean) {
private fun logEvent(
event: LogistrationAnalyticsEvent,
params: Map<String, Any?> = emptyMap(),
) {
analytics.logEvent(
LogistrationAnalyticEvent.RESET_PASSWORD_SUCCESS.event,
buildMap {
put(LogistrationAnalyticKey.NAME.key, LogistrationAnalyticValues.RESET_PASSWORD_SUCCESS.biValue)
put(LogistrationAnalyticKey.SUCCESS.key, success)
}
)
event = event.eventName,
params = buildMap {
put(LogistrationAnalyticKey.NAME.key, event.biValue)
putAll(params)
})
}
}
}
Loading

0 comments on commit 5ae94f0

Please sign in to comment.