From b7601e0520913070e2e116ee25e8ac9a4f0d7216 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Mon, 15 Jan 2024 14:57:40 +0100 Subject: [PATCH] Move WordPress Analytics from GravatarApi to WPAndroid --- .../signup/SignupEpilogueFragment.java | 18 +++++++++--------- .../wordpress/android/ui/main/MeFragment.kt | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java index c9cf412a613c..b45bbffeac79 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java @@ -33,6 +33,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.gravatar.GravatarApi; +import com.gravatar.GravatarApi.ErrorType; import com.yalantis.ucrop.UCrop; import com.yalantis.ucrop.UCropActivity; @@ -737,8 +738,8 @@ protected void startGravatarUpload(final String filePath) { new GravatarApi.GravatarUploadListener() { @Override public void onSuccess() { - // FIXME: log analytics endProgress(); + AnalyticsTracker.track(Stat.ME_GRAVATAR_UPLOADED); mPhotoUrl = GravatarUtils.fixGravatarUrl(mAccount.getAccount().getAvatarUrl(), getResources().getDimensionPixelSize(R.dimen.avatar_sz_large)); loadAvatar(mPhotoUrl, filePath); @@ -747,10 +748,12 @@ public void onSuccess() { } @Override - public void onError(@NonNull String exceptionClass, @NonNull String exceptionMessage) { + public void onError(@NonNull ErrorType errorType) { endProgress(); showErrorDialogWithCloseButton(getString(R.string.signup_epilogue_error_avatar)); - // FIXME: log analytics + Map properties = new HashMap<>(); + properties.put("error_type", errorType); + AnalyticsTracker.track(AnalyticsTracker.Stat.ME_GRAVATAR_UPLOAD_EXCEPTION, properties); AppLog.e(T.NUX, "Uploading image to Gravatar failed"); } }); @@ -836,18 +839,15 @@ public void run() { new GravatarApi.GravatarUploadListener() { @Override public void onSuccess() { - // FIXME: log analytics AppLog.i(T.NUX, "Google avatar download and Gravatar upload succeeded."); - AnalyticsTracker.track(AnalyticsTracker.Stat.ME_GRAVATAR_UPLOAD_UNSUCCESSFUL); + AnalyticsTracker.track(Stat.ME_GRAVATAR_UPLOADED); } @Override - public void onError(String exceptionClass, String exceptionMessage) { + public void onError(@NonNull ErrorType errorType) { AppLog.i(T.NUX, "Google avatar download and Gravatar upload failed."); - // FIXME: Don't track exceptions caused by poor internet connectivity Map properties = new HashMap<>(); - properties.put("network_exception_class", exceptionClass); - properties.put("network_exception_message", exceptionMessage); + properties.put("error_type", errorType); AnalyticsTracker.track(AnalyticsTracker.Stat.ME_GRAVATAR_UPLOAD_EXCEPTION, properties); } }); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/MeFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/MeFragment.kt index cb35c8b69bf5..e2fbe6629c98 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/MeFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/MeFragment.kt @@ -20,6 +20,8 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModelProvider import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar +import com.gravatar.GravatarApi +import com.gravatar.GravatarApi.GravatarUploadListener import com.yalantis.ucrop.UCrop import com.yalantis.ucrop.UCrop.Options import com.yalantis.ucrop.UCropActivity @@ -36,6 +38,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.ME_GRAVATAR_GALLERY import org.wordpress.android.analytics.AnalyticsTracker.Stat.ME_GRAVATAR_SHOT_NEW import org.wordpress.android.analytics.AnalyticsTracker.Stat.ME_GRAVATAR_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.ME_GRAVATAR_UPLOADED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.ME_GRAVATAR_UPLOAD_EXCEPTION import org.wordpress.android.databinding.MeFragmentBinding import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.store.AccountStore @@ -43,8 +46,6 @@ import org.wordpress.android.fluxc.store.AccountStore.OnAccountChanged import org.wordpress.android.fluxc.store.PostStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.models.JetpackPoweredScreen -import com.gravatar.GravatarApi -import com.gravatar.GravatarApi.GravatarUploadListener import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.RequestCodes import org.wordpress.android.ui.about.UnifiedAboutActivity @@ -672,12 +673,12 @@ class MeFragment : Fragment(R.layout.me_fragment), OnScrollToTopListener { GravatarApi.uploadGravatar(file, accountStore.account.email, accountStore.accessToken!!, object : GravatarUploadListener { override fun onSuccess() { - // FIXME: log analytics + AnalyticsTracker.track(ME_GRAVATAR_UPLOADED) EventBus.getDefault().post(GravatarUploadFinished(filePath, true)) } - override fun onError(exceptionClass: String, exceptionMessage: String) { - // FIXME: log analytics + override fun onError(errorType: GravatarApi.ErrorType) { + AnalyticsTracker.track(ME_GRAVATAR_UPLOAD_EXCEPTION, mapOf("error_type" to errorType.name)) EventBus.getDefault().post(GravatarUploadFinished(filePath, false)) } }) @@ -689,7 +690,6 @@ class MeFragment : Fragment(R.layout.me_fragment), OnScrollToTopListener { fun onEventMainThread(event: GravatarUploadFinished) { binding?.showGravatarProgressBar(false) if (event.success) { - AnalyticsTracker.track(ME_GRAVATAR_UPLOADED) binding?.loadAvatar(event.filePath) } else { ToastUtils.showToast(