fire analytics event after file has started downloading

This commit is contained in:
Sean Yesmunt 2019-11-13 10:20:54 -05:00
parent 1427ad2a76
commit 73bd46e7d8
3 changed files with 19 additions and 19 deletions

View file

@ -19,8 +19,7 @@ const select = (state, props) => ({
const perform = dispatch => ({ const perform = dispatch => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
pause: () => dispatch(doSetPlayingUri(null)), pause: () => dispatch(doSetPlayingUri(null)),
download: uri => dispatch(doPlayUri(uri, false, true)), download: uri => dispatch(doPlayUri(uri, false, true, () => dispatch(doAnalyticsView(uri)))),
triggerAnalyticsView: (uri, timeToStart) => dispatch(doAnalyticsView(uri, timeToStart)),
}); });
export default connect( export default connect(

View file

@ -1,7 +1,7 @@
// @flow // @flow
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import * as MODALS from 'constants/modal_types'; import * as MODALS from 'constants/modal_types';
import React, { useState } from 'react'; import React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import ToolTip from 'component/common/tooltip'; import ToolTip from 'component/common/tooltip';
@ -15,12 +15,10 @@ type Props = {
openModal: (id: string, { path: string }) => void, openModal: (id: string, { path: string }) => void,
pause: () => void, pause: () => void,
download: string => void, download: string => void,
triggerAnalyticsView: (string, number) => void,
}; };
function FileDownloadLink(props: Props) { function FileDownloadLink(props: Props) {
const [clicked, setClicked] = useState(false); const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri } = props;
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, triggerAnalyticsView } = props;
if (downloading || loading) { if (downloading || loading) {
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0; const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
@ -30,11 +28,6 @@ function FileDownloadLink(props: Props) {
return <span>{label}</span>; return <span>{label}</span>;
} }
if (fileInfo && fileInfo.download_path && clicked) {
triggerAnalyticsView(uri, 0);
setClicked(false);
}
if (fileInfo && fileInfo.download_path && fileInfo.completed) { if (fileInfo && fileInfo.download_path && fileInfo.completed) {
return ( return (
<ToolTip label={__('Open file')}> <ToolTip label={__('Open file')}>
@ -55,7 +48,6 @@ function FileDownloadLink(props: Props) {
button="link" button="link"
icon={ICONS.DOWNLOAD} icon={ICONS.DOWNLOAD}
onClick={() => { onClick={() => {
setClicked(true);
download(uri); download(uri);
}} }}
/> />

View file

@ -179,19 +179,28 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
}; };
} }
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean) { export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean, cb: ?() => void) {
return (dispatch: Dispatch, getState: () => any) => { return (dispatch: Dispatch, getState: () => any) => {
function onSuccess(fileInfo) { function onSuccess(fileInfo) {
if (saveFile) {
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint)); dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
} }
// Only pass the success callback if we are saving the file, otherwise we don't show the download percentage if (cb) {
const successCallBack = saveFile ? onSuccess : undefined; cb();
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, successCallBack)); }
}
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, onSuccess));
}; };
} }
export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileOverride: boolean = false) { export function doPlayUri(
uri: string,
skipCostCheck: boolean = false,
saveFileOverride: boolean = false,
cb?: () => void
) {
return (dispatch: Dispatch, getState: () => any) => { return (dispatch: Dispatch, getState: () => any) => {
const state = getState(); const state = getState();
const fileInfo = makeSelectFileInfoForUri(uri)(state); const fileInfo = makeSelectFileInfoForUri(uri)(state);
@ -211,7 +220,7 @@ export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileO
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state); const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
function beginGetFile() { function beginGetFile() {
dispatch(doPurchaseUriWrapper(uri, cost, saveFile)); dispatch(doPurchaseUriWrapper(uri, cost, saveFile, cb));
} }
function attemptPlay(instantPurchaseMax = null) { function attemptPlay(instantPurchaseMax = null) {