triggers analytic on download click + completed

This commit is contained in:
jessop 2019-11-04 12:34:18 -05:00 committed by Sean Yesmunt
parent 723d1fabbb
commit ba4d6afde0

View file

@ -19,13 +19,10 @@ type Props = {
};
function FileDownloadLink(props: Props) {
const [shouldTrigger, setShouldTrigger] = useState(false);
const [clicked, setClicked] = useState(false);
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, triggerAnalyticsView } = props;
if (downloading || loading) {
if (!shouldTrigger) {
setShouldTrigger(true);
}
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
const label =
fileInfo && fileInfo.written_bytes > 0 ? progress.toFixed(0) + __('% downloaded') : __('Connecting...');
@ -33,9 +30,9 @@ function FileDownloadLink(props: Props) {
return <span>{label}</span>;
}
if (fileInfo && fileInfo.download_path && fileInfo.completed && shouldTrigger) {
if (fileInfo && fileInfo.download_path && fileInfo.completed && clicked) {
triggerAnalyticsView(uri, 0);
setShouldTrigger(false);
setClicked(false);
}
if (fileInfo && fileInfo.download_path && fileInfo.completed) {
@ -58,6 +55,7 @@ function FileDownloadLink(props: Props) {
button="link"
icon={ICONS.DOWNLOAD}
onClick={() => {
setClicked(true);
download(uri);
}}
/>