diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 380455c2ca6a..a6884db857a2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -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; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt index e31635fa54ec..0edca25c46ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt @@ -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 @@ -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()) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt index 1a00989a78ce..8ae1a20c0480 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt @@ -3,7 +3,10 @@ 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 @@ -11,7 +14,8 @@ 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, @@ -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); } } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt index 366303e9fe00..c51bbaa40fbb 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt @@ -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 @@ -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) } @@ -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( @@ -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( @@ -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) } @@ -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 ) } @@ -136,5 +141,13 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { this.id = mediaModelId this.uploadState = MediaUploadState.FAILED.name } + + fun createEditorMediaListener() = mock { + on { getImmutablePost() } doAnswer { + mock { + on { localSiteId } doAnswer { 0 } + } + } + } } }