Skip to content

Commit

Permalink
feat: update Countly events for personal to team migration (WPB-11318…
Browse files Browse the repository at this point in the history
…) - RC (#3741)
  • Loading branch information
ohassine authored Dec 13, 2024
1 parent 1c29218 commit 6e37dc8
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ fun SelfUserProfileScreen(

SelfUserProfileContent(
state = viewModelSelf.userProfileState,
onCloseClick = navigator::navigateBack,
onCloseClick = {
if (viewModelSelf.userProfileState.isAbleToMigrateToTeamAccount) {
viewModelSelf.sendPersonalToTeamMigrationDismissed()
}
navigator.navigateBack()
},
logout = { viewModelSelf.logout(it, NavigationSwitchAccountActions(navigator::navigate)) },
onChangeUserProfilePicture = {
navigator.navigate(
Expand Down Expand Up @@ -154,7 +159,7 @@ fun SelfUserProfileScreen(
navigator.navigate(NavigationCommand(SelfQRCodeScreenDestination(viewModelSelf.userProfileState.userName)))
},
onCreateAccount = {
viewModelSelf.sendPersonalToTeamMigrationEvent()
viewModelSelf.sendPersonalToTeamMigrationEventCTAClicked()
navigator.navigate(NavigationCommand(TeamMigrationScreenDestination))
},
onAccountDetailsClick = { navigator.navigate(NavigationCommand(MyAccountScreenDestination)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,22 @@ class SelfUserProfileViewModel @Inject constructor(
anonymousAnalyticsManager.sendEvent(AnalyticsEvent.QrCode.Click(!userProfileState.teamName.isNullOrBlank()))
}

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

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

sealed class ErrorCodes {
data object DownloadUserInfoError : ErrorCodes()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ fun TeamMigrationScreen(
if (navController.currentDestination?.route == NavGraphs.personalToTeamMigration.destinations.last().route) {
navigator.navigateBack()
} else {
teamMigrationViewModel.sendPersonalToTeamMigrationDismissed()
teamMigrationViewModel.showMigrationLeaveDialog()
}
}
Expand Down Expand Up @@ -150,6 +149,23 @@ fun TeamMigrationScreen(
teamMigrationViewModel.sendPersonalTeamCreationFlowCanceledEvent(
modalLeaveClicked = true
)
when (teamMigrationViewModel.teamMigrationState.currentStep) {
TEAM_MIGRATION_TEAM_PLAN_STEP -> {
teamMigrationViewModel.sendPersonalTeamCreationFlowStoppedEvent(isOnDisclaimerStep = true)
}

TEAM_MIGRATION_TEAM_NAME_STEP -> {
teamMigrationViewModel.sendPersonalTeamCreationFlowStoppedEvent(isOnTeamNameStep = true)
}

TEAM_MIGRATION_CONFIRMATION_STEP -> {
teamMigrationViewModel.sendPersonalTeamCreationFlowStoppedEvent(isOnConfirmationStep = true)
}

else -> {
// Nothing to send
}
}
navigator.navigateBack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ class TeamMigrationViewModel @Inject constructor(
teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = false)
}

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

fun sendPersonalTeamCreationFlowStartedEvent(step: Int) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowStarted(step)
Expand All @@ -81,20 +73,32 @@ class TeamMigrationViewModel @Inject constructor(
) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCanceled(
teamName = teamMigrationState.teamNameTextState.text.toString(),
modalLeaveClicked = modalLeaveClicked,
modalContinueClicked = modalContinueClicked
)
)
}

fun sendPersonalTeamCreationFlowStoppedEvent(
isOnDisclaimerStep: Boolean? = null,
isOnTeamNameStep: Boolean? = null,
isOnConfirmationStep: Boolean? = null
) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowStopped(
isOnTeamNameStep = isOnTeamNameStep,
isOnConfirmationStep = isOnConfirmationStep,
isOnDisclaimerStep = isOnDisclaimerStep
)
)
}

fun sendPersonalTeamCreationFlowCompletedEvent(
modalOpenTeamManagementButtonClicked: Boolean? = null,
backToWireButtonClicked: Boolean? = null
) {
anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCompleted(
teamName = teamMigrationState.teamNameTextState.text.toString(),
modalOpenTeamManagementButtonClicked = modalOpenTeamManagementButtonClicked,
backToWireButtonClicked = backToWireButtonClicked
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SelfUserProfileViewModelTest {
.withLegalHoldStatus(LegalHoldStateForSelfUser.Disabled)
.arrange()

viewModel.sendPersonalToTeamMigrationEvent()
viewModel.sendPersonalToTeamMigrationEventCTAClicked()

verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
Expand All @@ -82,4 +82,22 @@ class SelfUserProfileViewModelTest {
)
}
}

@Test
fun `given close modal event, when sendPersonalToTeamMigrationDismissed is called, then send the event`() =
runTest {
val (arrangement, viewModel) = SelfUserProfileViewModelArrangement()
.withLegalHoldStatus(LegalHoldStateForSelfUser.Disabled)
.arrange()

viewModel.sendPersonalToTeamMigrationDismissed()

verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.ClickedPersonalTeamMigrationCta(
dismissCreateTeamButtonClicked = true
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ class TeamMigrationViewModelTest {
assertEquals(false, viewModel.teamMigrationState.shouldShowMigrationLeaveDialog)
}

@Test
fun `given close modal event, when sendPersonalToTeamMigrationDismissed is called, then send the event`() =
runTest {
val (arrangement, viewModel) = Arrangement()
.arrange()

viewModel.sendPersonalToTeamMigrationDismissed()

verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.ClickedPersonalTeamMigrationCta(
dismissCreateTeamButtonClicked = true
)
)
}
}

@Test
fun `given the step of migration flow, when sendPersonalTeamCreationFlowStartedEvent is called, then send the event`() =
runTest {
Expand Down Expand Up @@ -109,7 +92,6 @@ class TeamMigrationViewModelTest {
verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCanceled(
teamName = viewModel.teamMigrationState.teamNameTextState.text.toString(),
modalLeaveClicked = true
)
)
Expand All @@ -127,7 +109,6 @@ class TeamMigrationViewModelTest {
verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCanceled(
teamName = viewModel.teamMigrationState.teamNameTextState.text.toString(),
modalContinueClicked = true
)
)
Expand All @@ -147,7 +128,6 @@ class TeamMigrationViewModelTest {
verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCompleted(
teamName = viewModel.teamMigrationState.teamNameTextState.text.toString(),
modalOpenTeamManagementButtonClicked = true
)
)
Expand All @@ -165,7 +145,6 @@ class TeamMigrationViewModelTest {
verify(exactly = 1) {
arrangement.anonymousAnalyticsManager.sendEvent(
AnalyticsEvent.PersonalTeamMigration.PersonalTeamCreationFlowCompleted(
teamName = viewModel.teamMigrationState.teamNameTextState.text.toString(),
backToWireButtonClicked = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ import com.wire.android.feature.analytics.model.AnalyticsEventConstants.CLICKED_
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.CLICKED_PERSONAL_MIGRATION_CTA_EVENT
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.CONTRIBUTED_LOCATION
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MESSAGE_ACTION_KEY
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.QR_CODE_SEGMENTATION_USER_TYPE_PERSONAL
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.QR_CODE_SEGMENTATION_USER_TYPE_TEAM
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MIGRATION_DOT_ACTIVE
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_BACK_TO_WIRE_CLICKED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_CONFIRMATION
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_CONTINUE_CLICKED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_DISCLAIMERS
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_LEAVE_CLICKED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_OPEN_TEAM_MANAGEMENT_CLICKED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.MODAL_TEAM_NAME
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.PERSONAL_TEAM_CREATION_FLOW_CANCELLED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.PERSONAL_TEAM_CREATION_FLOW_COMPLETED
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.PERSONAL_TEAM_CREATION_FLOW_STARTED_EVENT
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.PERSONAL_TEAM_CREATION_FLOW_STOPPED_EVENT
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.QR_CODE_SEGMENTATION_USER_TYPE_PERSONAL
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.QR_CODE_SEGMENTATION_USER_TYPE_TEAM
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.STEP_MODAL_CREATE_TEAM
import com.wire.android.feature.analytics.model.AnalyticsEventConstants.USER_PROFILE_OPENED

Expand Down Expand Up @@ -278,8 +281,29 @@ interface AnalyticsEvent {
}
}

data class PersonalTeamCreationFlowStopped(
val isOnTeamNameStep: Boolean?,
val isOnConfirmationStep: Boolean?,
val isOnDisclaimerStep: Boolean?,
) : AnalyticsEvent {
override val key: String = PERSONAL_TEAM_CREATION_FLOW_STOPPED_EVENT

override fun toSegmentation(): Map<String, Boolean> {
val segmentations = mutableMapOf<String, Boolean>()
isOnTeamNameStep?.let {
segmentations.put(MODAL_TEAM_NAME, it)
}
isOnConfirmationStep?.let {
segmentations.put(MODAL_CONFIRMATION, it)
}
isOnDisclaimerStep?.let {
segmentations.put(MODAL_DISCLAIMERS, it)
}
return segmentations
}
}

data class PersonalTeamCreationFlowCanceled(
val teamName: String?,
val modalLeaveClicked: Boolean? = null,
val modalContinueClicked: Boolean? = null
) : AnalyticsEvent {
Expand All @@ -293,25 +317,18 @@ interface AnalyticsEvent {
modalContinueClicked?.let {
segmentations.put(MODAL_CONTINUE_CLICKED, it)
}
teamName?.let {
segmentations.put(MODAL_TEAM_NAME, it)
}
return segmentations
}
}

data class PersonalTeamCreationFlowCompleted(
val teamName: String? = null,
val modalOpenTeamManagementButtonClicked: Boolean? = null,
val backToWireButtonClicked: Boolean? = null
) : AnalyticsEvent {
override val key: String = PERSONAL_TEAM_CREATION_FLOW_COMPLETED

override fun toSegmentation(): Map<String, Any> {
val segmentations = mutableMapOf<String, Any>()
teamName?.let {
segmentations.put(MODAL_TEAM_NAME, it)
}
modalOpenTeamManagementButtonClicked?.let {
segmentations.put(MODAL_OPEN_TEAM_MANAGEMENT_CLICKED, it)
}
Expand Down Expand Up @@ -393,12 +410,15 @@ object AnalyticsEventConstants {
*/
const val CLICKED_PERSONAL_MIGRATION_CTA_EVENT = "ui.clicked-personal-migration-cta"
const val PERSONAL_TEAM_CREATION_FLOW_STARTED_EVENT = "user.personal-team-creation-flow-started"
const val PERSONAL_TEAM_CREATION_FLOW_STOPPED_EVENT = "personal-team-creation-flow-stopped"
const val PERSONAL_TEAM_CREATION_FLOW_CANCELLED = "user.personal-team-creation-flow-cancelled"
const val PERSONAL_TEAM_CREATION_FLOW_COMPLETED = "user.personal-team-creation-flow-completed"
const val MIGRATION_DOT_ACTIVE = "migration_dot_active"
const val CLICKED_CREATE_TEAM = "clicked_create_team"
const val CLICKED_DISMISS_CTA = "clicked_dismiss_cta"
const val STEP_MODAL_CREATE_TEAM = "step_modalcreateteam"
const val MODAL_DISCLAIMERS = "modal_disclaimers"
const val MODAL_CONFIRMATION = "modal_confirmation"
const val MODAL_TEAM_NAME = "modal_team-name"
const val MODAL_CONTINUE_CLICKED = "modal_continue-clicked"
const val MODAL_LEAVE_CLICKED = "modal_leave-clicked"
Expand Down
2 changes: 1 addition & 1 deletion kalium

0 comments on commit 6e37dc8

Please sign in to comment.