fix: ensure reward claim happens after file view request
This commit is contained in:
parent
14f4401aef
commit
59872056eb
3 changed files with 29 additions and 24 deletions
|
@ -14,7 +14,7 @@ type Analytics = {
|
||||||
pageView: string => void,
|
pageView: string => void,
|
||||||
setUser: Object => void,
|
setUser: Object => void,
|
||||||
toggle: (boolean, ?boolean) => void,
|
toggle: (boolean, ?boolean) => void,
|
||||||
apiLogView: (string, string, string, ?number, ?() => void) => void,
|
apiLogView: (string, string, string, ?number, ?() => void) => Promise<any>,
|
||||||
apiLogPublish: () => void,
|
apiLogPublish: () => void,
|
||||||
tagFollowEvent: (string, boolean, string) => void,
|
tagFollowEvent: (string, boolean, string) => void,
|
||||||
emailProvidedEvent: () => void,
|
emailProvidedEvent: () => void,
|
||||||
|
@ -49,25 +49,29 @@ const analytics: Analytics = {
|
||||||
// @endif
|
// @endif
|
||||||
},
|
},
|
||||||
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
apiLogView: (uri, outpoint, claimId, timeToStart) => {
|
||||||
if (analyticsEnabled && (isProduction || devInternalApis)) {
|
return new Promise((resolve, reject) => {
|
||||||
const params: {
|
if (analyticsEnabled && (isProduction || devInternalApis)) {
|
||||||
uri: string,
|
const params: {
|
||||||
outpoint: string,
|
uri: string,
|
||||||
claim_id: string,
|
outpoint: string,
|
||||||
time_to_start?: number,
|
claim_id: string,
|
||||||
} = {
|
time_to_start?: number,
|
||||||
uri,
|
} = {
|
||||||
outpoint,
|
uri,
|
||||||
claim_id: claimId,
|
outpoint,
|
||||||
};
|
claim_id: claimId,
|
||||||
|
};
|
||||||
|
|
||||||
// lbry.tv streams from AWS so we don't care about the time to start
|
// lbry.tv streams from AWS so we don't care about the time to start
|
||||||
if (timeToStart && !IS_WEB) {
|
if (timeToStart && !IS_WEB) {
|
||||||
params.time_to_start = timeToStart;
|
params.time_to_start = timeToStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(Lbryio.call('file', 'view', params));
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
Lbryio.call('file', 'view', params);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
apiLogSearch: () => {
|
apiLogSearch: () => {
|
||||||
if (analyticsEnabled && isProduction) {
|
if (analyticsEnabled && isProduction) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Props = {
|
||||||
title: ?string,
|
title: ?string,
|
||||||
floatingPlayerEnabled: boolean,
|
floatingPlayerEnabled: boolean,
|
||||||
clearPlayingUri: () => void,
|
clearPlayingUri: () => void,
|
||||||
triggerAnalyticsView: (string, number) => void,
|
triggerAnalyticsView: (string, number) => Promise<any>,
|
||||||
claimRewards: () => void,
|
claimRewards: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,10 +74,11 @@ export default function FileViewer(props: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (playTime && isReadyToPlay && !hasRecordedView) {
|
if (playTime && isReadyToPlay && !hasRecordedView) {
|
||||||
const timeToStart = Date.now() - playTime;
|
const timeToStart = Date.now() - playTime;
|
||||||
triggerAnalyticsView(uri, timeToStart);
|
triggerAnalyticsView(uri, timeToStart).then(() => {
|
||||||
claimRewards();
|
claimRewards();
|
||||||
setPlayTime(null);
|
setHasRecordedView(false);
|
||||||
setHasRecordedView(false);
|
setPlayTime(null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
|
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
|
||||||
|
|
||||||
|
|
|
@ -430,6 +430,6 @@ export function doAnalyticsView(uri, timeToStart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
analytics.apiLogView(uri, outpoint, claimId, timeToStart);
|
return analytics.apiLogView(uri, outpoint, claimId, timeToStart);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue