diff --git a/ui/component/floatingViewer/view.jsx b/ui/component/floatingViewer/view.jsx index 0835e9de0..6a3e7fd85 100644 --- a/ui/component/floatingViewer/view.jsx +++ b/ui/component/floatingViewer/view.jsx @@ -88,7 +88,7 @@ export default function FileViewer(props: Props) { const timeToStart = Date.now() - playTime; triggerAnalyticsView(uri, timeToStart).then(() => { claimRewards(); - setHasRecordedView(false); + setHasRecordedView(true); setPlayTime(null); }); } diff --git a/ui/page/embedWrapper/index.js b/ui/page/embedWrapper/index.js index fd7ac0ec8..44baf2e0d 100644 --- a/ui/page/embedWrapper/index.js +++ b/ui/page/embedWrapper/index.js @@ -1,6 +1,7 @@ import { connect } from 'react-redux'; import EmbedWrapperPage from './view'; import { doResolveUri, makeSelectClaimForUri, buildURI } from 'lbry-redux'; +import { doAnalyticsView } from 'redux/actions/app'; const select = (state, props) => { const { match } = props; @@ -13,9 +14,12 @@ const select = (state, props) => { }; }; -const perform = dispatch => ({ - resolveUri: uri => dispatch(doResolveUri(uri)), -}); +const perform = dispatch => { + return { + resolveUri: uri => dispatch(doResolveUri(uri)), + triggerAnalyticsView: uri => dispatch(doAnalyticsView(uri)), + }; +}; export default connect( select, diff --git a/ui/page/embedWrapper/view.jsx b/ui/page/embedWrapper/view.jsx index 33747c33c..16f506ca6 100644 --- a/ui/page/embedWrapper/view.jsx +++ b/ui/page/embedWrapper/view.jsx @@ -1,16 +1,27 @@ // @flow -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import FileRender from 'component/fileRender'; type Props = { uri: string, resolveUri: string => void, claim: Claim, + triggerAnalyticsView: string => Promise, }; // $FlowFixMe apparently flow thinks this is wrong. export const EmbedContext = React.createContext(); const EmbedWrapperPage = (props: Props) => { - const { resolveUri, claim, uri } = props; + const { resolveUri, claim, uri, triggerAnalyticsView } = props; + const [hasRecordedView, setHasRecordedView] = useState(false); + + useEffect(() => { + if (!hasRecordedView && uri && claim) { + triggerAnalyticsView(uri).then(() => { + setHasRecordedView(true); + }); + } + }, [triggerAnalyticsView, setHasRecordedView, hasRecordedView, uri, claim]); + useEffect(() => { if (resolveUri && uri) { resolveUri(uri);