diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt index 74fb3e93d63b..247b88ed1007 100644 --- a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt @@ -2,6 +2,7 @@ package org.wordpress.android.localcontentmigration import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.Companion.ERROR_TYPE +import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.EmailError import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import javax.inject.Inject @@ -11,8 +12,15 @@ class ContentMigrationAnalyticsTracker @Inject constructor( fun trackContentMigrationFailed(errorType: ErrorType) = analyticsTracker.track(Stat.SHARED_LOGIN_FAILED, mapOf(ERROR_TYPE to errorType.value)) + fun trackMigrationEmailSuccess() = + analyticsTracker.track(Stat.MIGRATION_EMAIL_TRIGGERED) + + fun trackMigrationEmailFailed(errorType: EmailError) = + analyticsTracker.track(Stat.MIGRATION_EMAIL_FAILED, mapOf(ERROR_TYPE to errorType.value)) + sealed class ErrorType(val value: String) { object LocalDraftContent : ErrorType("local_draft_content_is_present") + class EmailError(val error: String?) : ErrorType(error ?: "unknown_email_error") companion object { const val ERROR_TYPE = "error_type" diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt new file mode 100644 index 000000000000..fc3f597bc0c0 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt @@ -0,0 +1,31 @@ +package org.wordpress.android.localcontentmigration + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import org.wordpress.android.fluxc.store.mobile.JetpackMigrationStore +import org.wordpress.android.fluxc.store.mobile.MigrationCompleteFetchedPayload.Error +import org.wordpress.android.fluxc.store.mobile.MigrationCompleteFetchedPayload.Success +import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.EmailError +import org.wordpress.android.modules.BG_THREAD +import javax.inject.Inject +import javax.inject.Named +import kotlin.coroutines.CoroutineContext + +class MigrationEmailHelper @Inject constructor( + private val jetpackMigrationStore: JetpackMigrationStore, + private val migrationAnalyticsTracker: ContentMigrationAnalyticsTracker, + @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, +) : CoroutineScope { + private val job = Job() + override val coroutineContext: CoroutineContext + get() = bgDispatcher + job + + fun notifyMigrationComplete() = launch(bgDispatcher) { + when (val result = jetpackMigrationStore.migrationComplete()) { + is Success -> migrationAnalyticsTracker.trackMigrationEmailSuccess() + is Error -> migrationAnalyticsTracker.trackMigrationEmailFailed(EmailError(result.error?.message)) + } + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt index 73eda7b11c68..4ea2077529c3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt @@ -18,6 +18,7 @@ import org.wordpress.android.localcontentmigration.LocalMigrationState.Finished. import org.wordpress.android.localcontentmigration.LocalMigrationState.Finished.Successful import org.wordpress.android.localcontentmigration.LocalMigrationState.Initial import org.wordpress.android.localcontentmigration.LocalMigrationState.Migrating +import org.wordpress.android.localcontentmigration.MigrationEmailHelper import org.wordpress.android.sharedlogin.resolver.LocalMigrationOrchestrator import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeletePrimaryButton import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeleteSecondaryButton @@ -49,6 +50,7 @@ class JetpackMigrationViewModel @Inject constructor( private val gravatarUtilsWrapper: GravatarUtilsWrapper, private val appPrefsWrapper: AppPrefsWrapper, private val localMigrationOrchestrator: LocalMigrationOrchestrator, + private val migrationEmailHelper: MigrationEmailHelper, ) : ViewModel() { private val _uiState = MutableStateFlow(Loading) @@ -162,6 +164,7 @@ class JetpackMigrationViewModel @Inject constructor( } private fun onDoneClicked() { + migrationEmailHelper.notifyMigrationComplete() appPrefsWrapper.setJetpackMigrationCompleted(true) postActionEvent(CompleteFlow) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt index d458c5294a88..5ae81c3ceebb 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt @@ -8,6 +8,7 @@ import org.mockito.junit.MockitoJUnitRunner import org.mockito.kotlin.mock import org.wordpress.android.BaseUnitTest import org.wordpress.android.R +import org.wordpress.android.localcontentmigration.MigrationEmailHelper import org.wordpress.android.sharedlogin.resolver.LocalMigrationOrchestrator import org.wordpress.android.test import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeletePrimaryButton @@ -33,11 +34,13 @@ class JetpackMigrationViewModelTest : BaseUnitTest() { private val gravatarUtilsWrapper: GravatarUtilsWrapper = mock() private val appPrefsWrapper: AppPrefsWrapper = mock() private val localMigrationOrchestrator: LocalMigrationOrchestrator = mock() + private val migrationEmailHelper: MigrationEmailHelper = mock() private val classToTest = JetpackMigrationViewModel( siteUtilsWrapper = siteUtilsWrapper, gravatarUtilsWrapper = gravatarUtilsWrapper, appPrefsWrapper = appPrefsWrapper, localMigrationOrchestrator = localMigrationOrchestrator, + migrationEmailHelper = migrationEmailHelper ) // region ViewModel diff --git a/build.gradle b/build.gradle index 42c9d5b39f6f..d14b21415a5b 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = 'trunk-c0c1d3d56d09eec19e668eb6e2f3bcff648c644f' + fluxCVersion = 'trunk-9266d1b01317fcecf068e737e51a07186a1baf8f' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index b721efc9cac4..da50693b8e34 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -950,6 +950,8 @@ public enum Stat { SHARED_LOGIN_START, SHARED_LOGIN_SUCCESS, SHARED_LOGIN_FAILED, + MIGRATION_EMAIL_TRIGGERED, + MIGRATION_EMAIL_FAILED, CONTENT_MIGRATION_FAILED, USER_FLAGS_START, USER_FLAGS_SUCCESS, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index ed1a9baed390..7c1b9fe1d453 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -2393,6 +2393,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "shared_login_success"; case SHARED_LOGIN_FAILED: return "shared_login_failed"; + case MIGRATION_EMAIL_FAILED: + return "migration_email_failed"; + case MIGRATION_EMAIL_TRIGGERED: + return "migration_email_triggered"; case CONTENT_MIGRATION_FAILED: return "content_migration_failed"; case USER_FLAGS_START: