Skip to content

Commit

Permalink
Move WordPress Analytics from GravatarApi to WPAndroid
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Jan 15, 2024
1 parent c185318 commit b7601e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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<String, Object> 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");
}
});
Expand Down Expand Up @@ -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<String, Object> 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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,15 +38,14 @@ 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
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
Expand Down Expand Up @@ -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))
}
})
Expand All @@ -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(
Expand Down

0 comments on commit b7601e0

Please sign in to comment.