Skip to content

Commit

Permalink
feat: Report Metric of Personal User creating a team in Countly (WPB-…
Browse files Browse the repository at this point in the history
…11318) (#3552)
  • Loading branch information
ohassine authored Oct 31, 2024
1 parent 7993fc5 commit f529c34
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class UserDataStore(private val context: Context, userId: UserId) {
}

fun isCreateTeamNoticeRead(): Flow<Boolean> = context.dataStore.data.map {
it[IS_CREATE_TEAM_NOTICE_READ] ?: true
it[IS_CREATE_TEAM_NOTICE_READ] ?: false
}

suspend fun setIsCreateTeamNoticeRead(isRead: Boolean) {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
Expand Down Expand Up @@ -167,7 +166,10 @@ fun HomeScreen(
homeDrawerState = homeDrawerViewModel.drawerState,
homeStateHolder = homeScreenState,
onNewConversationClick = { navigator.navigate(NavigationCommand(NewConversationSearchPeopleScreenDestination)) },
onSelfUserClick = remember(navigator) { { navigator.navigate(NavigationCommand(SelfUserProfileScreenDestination)) } }
onSelfUserClick = {
homeViewModel.sendOpenProfileEvent()
navigator.navigate(NavigationCommand(SelfUserProfileScreenDestination))
}
)

BackHandler(homeScreenState.drawerState.isOpen) {
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

package com.wire.android.ui.home

import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.datastore.UserDataStore
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.android.migration.userDatabase.ShouldTriggerMigrationForUserUserCase
import com.wire.android.model.ImageAsset.UserAvatarAsset
import com.wire.android.model.NameBasedAvatar
Expand All @@ -51,9 +54,11 @@ class HomeViewModel @Inject constructor(
private val needsToRegisterClient: NeedsToRegisterClientUseCase,
private val observeLegalHoldStatusForSelfUser: ObserveLegalHoldStateForSelfUserUseCase,
private val wireSessionImageLoader: WireSessionImageLoader,
private val shouldTriggerMigrationForUser: ShouldTriggerMigrationForUserUserCase
private val shouldTriggerMigrationForUser: ShouldTriggerMigrationForUserUserCase,
private val analyticsManager: AnonymousAnalyticsManager
) : SavedStateViewModel(savedStateHandle) {

@VisibleForTesting
var homeState by mutableStateOf(HomeState())
private set

Expand Down Expand Up @@ -136,4 +141,8 @@ class HomeViewModel @Inject constructor(
homeState = homeState.copy(shouldDisplayWelcomeMessage = false)
}
}

fun sendOpenProfileEvent() {
analyticsManager.sendEvent(AnalyticsEvent.UserProfileOpened(homeState.shouldShowCreateTeamUnreadIndicator))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ fun SelfUserProfileScreen(
navigator.navigate(NavigationCommand(SelfQRCodeScreenDestination(viewModelSelf.userProfileState.userName)))
},
onCreateAccount = {
viewModelSelf.sendPersonalToTeamMigrationEvent()
navigator.navigate(NavigationCommand(TeamMigrationScreenDestination))
},
isUserInCall = viewModelSelf::isUserInCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SelfUserProfileViewModel @Inject constructor(
private val notificationManager: WireNotificationManager,
private val globalDataStore: GlobalDataStore,
private val qualifiedIdMapper: QualifiedIdMapper,
private val analyticsManager: AnonymousAnalyticsManager
private val anonymousAnalyticsManager: AnonymousAnalyticsManager
) : ViewModel() {

var userProfileState by mutableStateOf(SelfUserProfileState(userId = selfUserId, isAvatarLoading = true))
Expand Down Expand Up @@ -342,10 +342,18 @@ class SelfUserProfileViewModel @Inject constructor(
}

fun trackQrCodeClick() {
analyticsManager.sendEvent(AnalyticsEvent.QrCode.Click(!userProfileState.teamName.isNullOrBlank()))
anonymousAnalyticsManager.sendEvent(AnalyticsEvent.QrCode.Click(!userProfileState.teamName.isNullOrBlank()))
}

fun sendPersonalToTeamMigrationEvent() {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.ClickedPersonalTeamMigrationCta(
createTeamButtonClicked = true
)
)
}

sealed class ErrorCodes {
object DownloadUserInfoError : ErrorCodes()
data object DownloadUserInfoError : ErrorCodes()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package com.wire.android.ui.userprofile.teammigration

import com.ramcosta.composedestinations.annotation.NavGraph
import com.ramcosta.composedestinations.annotation.RootNavGraph

@RootNavGraph
@NavGraph
annotation class PersonalToTeamMigrationNavGraph(
val start: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -99,6 +98,7 @@ fun TeamMigrationScreen(
if (navController.currentDestination?.route == NavGraphs.personalToTeamMigration.destinations.last().route) {
navigator.navigateBack()
} else {
teamMigrationViewModel.sendPersonalToTeamMigrationDismissed()
teamMigrationViewModel.showMigrationLeaveDialog()
}
}
Expand All @@ -116,10 +116,7 @@ fun TeamMigrationScreen(
dependenciesContainerBuilder = {
dependency(navigator)
dependency(NavGraphs.personalToTeamMigration) {
val parentEntry = remember(navBackStackEntry) {
navController.getBackStackEntry(NavGraphs.personalToTeamMigration.route)
}
hiltViewModel<TeamMigrationViewModel>(parentEntry)
teamMigrationViewModel
}
}
)
Expand All @@ -128,10 +125,16 @@ fun TeamMigrationScreen(
if (teamMigrationViewModel.teamMigrationState.shouldShowMigrationLeaveDialog) {
ConfirmMigrationLeaveDialog(
onContinue = {
teamMigrationViewModel.sendPersonalTeamCreationFlowCanceledEvent(
modalContinueClicked = true
)
teamMigrationViewModel.hideMigrationLeaveDialog()
}
) {
teamMigrationViewModel.hideMigrationLeaveDialog()
teamMigrationViewModel.sendPersonalTeamCreationFlowCanceledEvent(
modalLeaveClicked = true
)
navigator.navigateBack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class TeamMigrationViewModel @Inject constructor() : ViewModel() {
class TeamMigrationViewModel @Inject constructor(
private val anonymousAnalyticsManager: AnonymousAnalyticsManager
) : ViewModel() {

var teamMigrationState by mutableStateOf(TeamMigrationState())
private set
Expand All @@ -37,4 +41,44 @@ class TeamMigrationViewModel @Inject constructor() : ViewModel() {
fun hideMigrationLeaveDialog() {
teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = false)
}

fun sendPersonalToTeamMigrationDismissed() {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.ClickedPersonalTeamMigrationCta(
dismissCreateTeamButtonClicked = true
)
)
}

fun sendPersonalTeamCreationFlowStartedEvent(step: Int) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowStarted(step)
)
}

fun sendPersonalTeamCreationFlowCanceledEvent(
modalLeaveClicked: Boolean? = null,
modalContinueClicked: Boolean? = null
) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCanceled(
teamName = teamMigrationState.teamNameTextState.text.toString(),
modalLeaveClicked = modalLeaveClicked,
modalContinueClicked = modalContinueClicked
)
)
}

fun sendPersonalTeamCreationFlowCompletedEvent(
modalOpenTeamManagementButtonClicked: Boolean? = null,
backToWireButtonClicked: Boolean? = null
) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCompleted(
teamName = teamMigrationState.teamNameTextState.text.toString(),
modalOpenTeamManagementButtonClicked = modalOpenTeamManagementButtonClicked,
backToWireButtonClicked = backToWireButtonClicked
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.material.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -55,6 +56,7 @@ import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.common.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.ui.userprofile.teammigration.TeamMigrationViewModel
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.ui.PreviewMultipleThemes

Expand All @@ -64,13 +66,18 @@ import com.wire.android.util.ui.PreviewMultipleThemes
)
@Composable
fun TeamMigrationTeamPlanStepScreen(
navigator: DestinationsNavigator
navigator: DestinationsNavigator,
teamMigrationViewModel: TeamMigrationViewModel
) {
TeamMigrationTeamPlanStepScreenContent(
onContinueButtonClicked = {
navigator.navigate(TeamMigrationTeamNameStepScreenDestination)
}
)

LaunchedEffect(Unit) {
teamMigrationViewModel.sendPersonalTeamCreationFlowStartedEvent(1)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
Expand Down Expand Up @@ -66,6 +67,9 @@ fun TeamMigrationTeamNameStepScreen(
},
teamNameTextFieldState = teamMigrationViewModel.teamMigrationState.teamNameTextState
)
LaunchedEffect(Unit) {
teamMigrationViewModel.sendPersonalTeamCreationFlowStartedEvent(2)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -72,6 +73,7 @@ fun TeamMigrationConfirmationStepScreen(
navigator: DestinationsNavigator,
teamMigrationViewModel: TeamMigrationViewModel
) {

TeamMigrationConfirmationStepScreenContent(
onContinueButtonClicked = {
// TODO: call the API to migrate the user to the team, if successful navigate to next screen
Expand All @@ -82,6 +84,9 @@ fun TeamMigrationConfirmationStepScreen(
},
passwordTextState = teamMigrationViewModel.teamMigrationState.passwordTextState
)
LaunchedEffect(Unit) {
teamMigrationViewModel.sendPersonalTeamCreationFlowStartedEvent(3)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ fun TeamMigrationDoneStepScreen(
val teamManagementUrl = stringResource(R.string.url_team_management)
TeamMigrationDoneStepContent(
onBackToWireClicked = {
teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent(
backToWireButtonClicked = true
)
navigator.navigate(
NavigationCommand(
HomeScreenDestination,
Expand All @@ -73,6 +76,9 @@ fun TeamMigrationDoneStepScreen(
)
},
onOpenTeamManagementClicked = {
teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent(
modalOpenTeamManagementButtonClicked = true
)
CustomTabsHelper.launchUrl(context, teamManagementUrl)
},
teamName = teamMigrationViewModel.teamMigrationState.teamNameTextState.text.toString()
Expand Down
Loading

0 comments on commit f529c34

Please sign in to comment.