Skip to content

Commit

Permalink
Merge pull request #19900 from wordpress-mobile/media-upload/track-fa…
Browse files Browse the repository at this point in the history
…iled-editor

Use `trackWithSiteDetails` to track failed media uploads in the editor
  • Loading branch information
jhnstn authored Jan 16, 2024
2 parents 52f85bf + 825e67e commit c1558d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,7 @@ public boolean onMediaRetryClicked(final String mediaId) {
mEditorMedia.retryFailedMediaAsync(Collections.singletonList(media.getId()));
}

AnalyticsTracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED);
AnalyticsUtils.trackWithSiteDetails(Stat.EDITOR_UPLOAD_MEDIA_RETRIED, mSite);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.wordpress.android.util.NetworkUtilsWrapper
import org.wordpress.android.util.StringUtils
import org.wordpress.android.util.ToastUtils.Duration
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.util.analytics.AnalyticsUtils
import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.SingleLiveEvent
Expand Down Expand Up @@ -295,7 +296,11 @@ class EditorMedia @Inject constructor(
it["error_type"] = error.type.name
}
}
analyticsTrackerWrapper.track(EDITOR_UPLOAD_MEDIA_FAILED, properties)
AnalyticsUtils.trackWithSiteDetails(
analyticsTrackerWrapper,
EDITOR_UPLOAD_MEDIA_FAILED,
site,
properties)
listener.onMediaUploadFailed(media.id.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package org.wordpress.android.ui.posts.editor.media
import dagger.Reusable
import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.SiteStore
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.util.analytics.AnalyticsUtils
import javax.inject.Inject

@Reusable
class RetryFailedMediaUploadUseCase @Inject constructor(
private val getMediaModelUseCase: GetMediaModelUseCase,
private val updateMediaModelUseCase: UpdateMediaModelUseCase,
private val uploadMediaUseCase: UploadMediaUseCase,
private val tracker: AnalyticsTrackerWrapper
private val tracker: AnalyticsTrackerWrapper,
private val siteStore: SiteStore
) {
suspend fun retryFailedMediaAsync(
editorMediaListener: EditorMediaListener,
Expand All @@ -33,7 +37,9 @@ class RetryFailedMediaUploadUseCase @Inject constructor(
editorMediaListener,
mediaModels
)
tracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED)
val siteId = editorMediaListener.getImmutablePost().localSiteId
val site: SiteModel? = siteStore.getSiteByLocalId(siteId)
AnalyticsUtils.trackWithSiteDetails(tracker, Stat.EDITOR_UPLOAD_MEDIA_RETRIED, site, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.model.MediaModel
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED
import org.wordpress.android.fluxc.model.PostImmutableModel
import org.wordpress.android.fluxc.store.SiteStore
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper

@ExperimentalCoroutinesApi
Expand All @@ -29,8 +31,9 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val getMediaModelUseCase = createGetMediaModelUseCase()
val useCase = createUseCase(getMediaModelUseCase = getMediaModelUseCase)


// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)
// Assert
verify(getMediaModelUseCase).loadMediaByLocalId(FAILED_MEDIA_IDS)
}
Expand All @@ -42,7 +45,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val useCase = createUseCase(updateMediaModelUseCase = updateMediaModelUseCase)

// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)

// Assert
verify(updateMediaModelUseCase, times(FAILED_MEDIA_IDS.size)).updateMediaModel(
Expand All @@ -59,7 +62,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val useCase = createUseCase(uploadMediaUseCase = uploadMediaUseCase)

// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)

// Assert
verify(uploadMediaUseCase).saveQueuedPostAndStartUpload(
Expand All @@ -74,7 +77,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val trackerWrapper: AnalyticsTrackerWrapper = mock()
val useCase = createUseCase(tracker = trackerWrapper)
// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)
// Assert
verify(trackerWrapper).track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED)
}
Expand Down Expand Up @@ -112,13 +115,15 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
getMediaModelUseCase: GetMediaModelUseCase = createGetMediaModelUseCase(),
updateMediaModelUseCase: UpdateMediaModelUseCase = mock(),
uploadMediaUseCase: UploadMediaUseCase = mock(),
tracker: AnalyticsTrackerWrapper = mock()
tracker: AnalyticsTrackerWrapper = mock(),
siteStore: SiteStore = mock()
): RetryFailedMediaUploadUseCase {
return RetryFailedMediaUploadUseCase(
getMediaModelUseCase,
updateMediaModelUseCase,
uploadMediaUseCase,
tracker
tracker,
siteStore
)
}

Expand All @@ -136,5 +141,13 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
this.id = mediaModelId
this.uploadState = MediaUploadState.FAILED.name
}

fun createEditorMediaListener() = mock<EditorMediaListener> {
on { getImmutablePost() } doAnswer {
mock<PostImmutableModel> {
on { localSiteId } doAnswer { 0 }
}
}
}
}
}

0 comments on commit c1558d1

Please sign in to comment.