Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.generated.MediaActionBuilder;
import org.wordpress.android.fluxc.model.MediaModel;
Expand All @@ -18,11 +19,14 @@
import org.wordpress.android.fluxc.store.MediaStore.MediaPayload;
import org.wordpress.android.fluxc.store.MediaStore.OnMediaUploaded;
import org.wordpress.android.models.MediaUploadState;
import org.wordpress.android.util.AnalyticsUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -111,11 +115,13 @@ private void handleOnMediaUploadedSuccess(@NonNull OnMediaUploaded event) {
if (event.canceled) {
// Upload canceled
AppLog.i(AppLog.T.MEDIA, "Upload successfully canceled.");
trackUploadMediaEvents(AnalyticsTracker.Stat.MEDIA_UPLOAD_CANCELED, mCurrentUpload, null);
completeCurrentUpload();
uploadNextInQueue();
} else if (event.completed) {
// Upload completed
AppLog.i(AppLog.T.MEDIA, "Upload completed - localId=" + event.media.getId() + " title=" + event.media.getTitle());
trackUploadMediaEvents(AnalyticsTracker.Stat.MEDIA_UPLOAD_SUCCESS, mCurrentUpload, null);
mCurrentUpload.setMediaId(event.media.getMediaId());
completeCurrentUpload();
uploadNextInQueue();
Expand All @@ -134,6 +140,9 @@ private void handleOnMediaUploadedError(@NonNull OnMediaUploaded event) {
completeCurrentUpload();
// TODO: check whether we need to broadcast the error or maybe it is enough to register for FluxC events
// event.media, event.error
Map<String, Object> properties = new HashMap<>();
properties.put("error_type", event.error.type.name());
trackUploadMediaEvents(AnalyticsTracker.Stat.MEDIA_UPLOAD_ERROR, mCurrentUpload, properties);
uploadNextInQueue();
}

Expand All @@ -160,6 +169,7 @@ private void uploadNextInQueue() {
}

dispatchUploadAction(mCurrentUpload);
trackUploadMediaEvents(AnalyticsTracker.Stat.MEDIA_UPLOAD_STARTED, mCurrentUpload, null);
}

private void completeCurrentUpload() {
Expand Down Expand Up @@ -272,4 +282,21 @@ public void onMediaUploaded(OnMediaUploaded event) {
handleOnMediaUploadedSuccess(event);
}
}

/**
* Analytics about media being uploaded
*
* @param media The media being uploaded
*/
private void trackUploadMediaEvents(AnalyticsTracker.Stat stat, MediaModel media, Map<String, Object> properties) {
if (media == null) {
AppLog.e(AppLog.T.MEDIA, "Cannot track media upload service events if the original media is null!!");
return;
}
Map<String, Object> mediaProperties = AnalyticsUtils.getMediaProperties(this, media.isVideo(), null, media.getFilePath());
if (properties != null) {
mediaProperties.putAll(properties);
}
AnalyticsTracker.track(stat, mediaProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ public enum Stat {
DEEP_LINKED,
DEEP_LINKED_FALLBACK,
DEEP_LINK_NOT_DEFAULT_HANDLER,
MEDIA_UPLOAD_STARTED,
MEDIA_UPLOAD_ERROR,
MEDIA_UPLOAD_SUCCESS,
MEDIA_UPLOAD_CANCELED,
}

private static final List<Tracker> TRACKERS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,22 @@ private AnalyticsTrackerMixpanelInstructionsForStat instructionsForStat(
instructions = AnalyticsTrackerMixpanelInstructionsForStat.
mixpanelInstructionsForEventName("Media Library - Added Video");
break;
case MEDIA_UPLOAD_STARTED:
instructions = AnalyticsTrackerMixpanelInstructionsForStat.
mixpanelInstructionsForEventName("Media Service - Upload Started");
break;
case MEDIA_UPLOAD_ERROR:
instructions = AnalyticsTrackerMixpanelInstructionsForStat.
mixpanelInstructionsForEventName("Media Service - Upload Error");
break;
case MEDIA_UPLOAD_SUCCESS:
instructions = AnalyticsTrackerMixpanelInstructionsForStat.
mixpanelInstructionsForEventName("Media Service - Response OK");
break;
case MEDIA_UPLOAD_CANCELED:
instructions = AnalyticsTrackerMixpanelInstructionsForStat.
mixpanelInstructionsForEventName("Media Service - Upload Canceled");
break;
default:
instructions = null;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,14 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) {
return "media_library_photo_added";
case MEDIA_LIBRARY_ADDED_VIDEO:
return "media_library_video_added";
case MEDIA_UPLOAD_STARTED:
return "media_service_upload_started";
case MEDIA_UPLOAD_ERROR:
return "media_service_upload_response_error";
case MEDIA_UPLOAD_SUCCESS:
return "media_service_upload_response_ok";
case MEDIA_UPLOAD_CANCELED:
return "media_service_upload_canceled";
default:
return null;
}
Expand Down