Merge pull request #3597 from lbryio/embedAnalytics
make embeds log views in analytics
This commit is contained in:
commit
d2240d3df5
3 changed files with 21 additions and 6 deletions
|
@ -88,7 +88,7 @@ export default function FileViewer(props: Props) {
|
||||||
const timeToStart = Date.now() - playTime;
|
const timeToStart = Date.now() - playTime;
|
||||||
triggerAnalyticsView(uri, timeToStart).then(() => {
|
triggerAnalyticsView(uri, timeToStart).then(() => {
|
||||||
claimRewards();
|
claimRewards();
|
||||||
setHasRecordedView(false);
|
setHasRecordedView(true);
|
||||||
setPlayTime(null);
|
setPlayTime(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import EmbedWrapperPage from './view';
|
import EmbedWrapperPage from './view';
|
||||||
import { doResolveUri, makeSelectClaimForUri, buildURI } from 'lbry-redux';
|
import { doResolveUri, makeSelectClaimForUri, buildURI } from 'lbry-redux';
|
||||||
|
import { doAnalyticsView } from 'redux/actions/app';
|
||||||
|
|
||||||
const select = (state, props) => {
|
const select = (state, props) => {
|
||||||
const { match } = props;
|
const { match } = props;
|
||||||
|
@ -13,9 +14,12 @@ const select = (state, props) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => {
|
||||||
resolveUri: uri => dispatch(doResolveUri(uri)),
|
return {
|
||||||
});
|
resolveUri: uri => dispatch(doResolveUri(uri)),
|
||||||
|
triggerAnalyticsView: uri => dispatch(doAnalyticsView(uri)),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
select,
|
select,
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import FileRender from 'component/fileRender';
|
import FileRender from 'component/fileRender';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
resolveUri: string => void,
|
resolveUri: string => void,
|
||||||
claim: Claim,
|
claim: Claim,
|
||||||
|
triggerAnalyticsView: string => Promise<any>,
|
||||||
};
|
};
|
||||||
// $FlowFixMe apparently flow thinks this is wrong.
|
// $FlowFixMe apparently flow thinks this is wrong.
|
||||||
export const EmbedContext = React.createContext();
|
export const EmbedContext = React.createContext();
|
||||||
const EmbedWrapperPage = (props: Props) => {
|
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(() => {
|
useEffect(() => {
|
||||||
if (resolveUri && uri) {
|
if (resolveUri && uri) {
|
||||||
resolveUri(uri);
|
resolveUri(uri);
|
||||||
|
|
Loading…
Reference in a new issue