From 1f649b9d38129cbfc2a9d4acfe26bf5adbb527af Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 17 Feb 2020 07:24:39 +0100 Subject: [PATCH] App timing (#123) * log launch timing. recalculate play time to start timing. * remove decimal points from time to start values --- src/page/discover/view.js | 23 ----------------------- src/page/file/view.js | 16 ++++++++++------ src/page/splash/view.js | 3 +++ 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/page/discover/view.js b/src/page/discover/view.js index 1696323..dc4ad63 100644 --- a/src/page/discover/view.js +++ b/src/page/discover/view.js @@ -37,29 +37,6 @@ class DiscoverPage extends React.PureComponent { }; componentDidMount() { - // Track the total time taken if this is the first launch - AsyncStorage.getItem('firstLaunchTime').then(startTime => { - if (startTime !== null && !isNaN(parseInt(startTime, 10))) { - // We don't need this value anymore once we've retrieved it - AsyncStorage.removeItem('firstLaunchTime'); - - // We know this is the first app launch because firstLaunchTime is set and it"s a valid number - const start = parseInt(startTime, 10); - const now = moment().unix(); - const delta = now - start; - AsyncStorage.getItem('firstLaunchSuspended').then(suspended => { - AsyncStorage.removeItem('firstLaunchSuspended'); - const appSuspended = suspended === 'true'; - if (NativeModules.Firebase) { - NativeModules.Firebase.track('first_run_time', { - total_seconds: delta, - app_suspended: appSuspended, - }); - } - }); - } - }); - const { sortByItem, fetchRewardedContent, fileList, followedTags } = this.props; this.buildTagCollection(followedTags); diff --git a/src/page/file/view.js b/src/page/file/view.js index 23167ce..f9aecb7 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -610,7 +610,7 @@ class FilePage extends React.PureComponent { let timeToStartMillis, timeToStart; if (this.startTime) { timeToStartMillis = Date.now() - this.startTime; - timeToStart = Math.ceil(timeToStartMillis / 1000); + timeToStart = Math.ceil(timeToStartMillis / 1000.0); this.startTime = null; } @@ -620,8 +620,8 @@ class FilePage extends React.PureComponent { let payload = { uri: uri }; if (!isNaN(timeToStart)) { - payload['time_to_start_seconds'] = timeToStart; - payload['time_to_start_ms'] = timeToStartMillis; + payload['time_to_start_seconds'] = parseInt(timeToStart, 10); + payload['time_to_start_ms'] = parseInt(timeToStartMillis, 10); } NativeModules.Firebase.track('play', payload); @@ -702,19 +702,24 @@ class FilePage extends React.PureComponent { [ { text: __('OK'), - onPress: () => purchaseUri(uri, costInfo, download), + onPress: () => { + this.startTime = Date.now(); + purchaseUri(uri, costInfo, download); + }, }, { text: __('Cancel') }, ], ); } else { // Free content. Just call purchaseUri directly. + this.startTime = Date.now(); purchaseUri(uri, costInfo, download); } }; onFileDownloadButtonPressed = () => { - const { claim, costInfo, contentType, purchaseUri, setPlayerVisible } = this.props; + this.startTime = Date.now(); + const { claim, costInfo, contentType, setPlayerVisible } = this.props; const mediaType = Lbry.getMediaType(contentType); const isPlayable = mediaType === 'video' || mediaType === 'audio'; const isViewable = mediaType === 'image' || mediaType === 'text'; @@ -729,7 +734,6 @@ class FilePage extends React.PureComponent { } if (isPlayable) { - this.startTime = Date.now(); this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false }); } if (isViewable) { diff --git a/src/page/splash/view.js b/src/page/splash/view.js index 2f3580a..8f520c8 100644 --- a/src/page/splash/view.js +++ b/src/page/splash/view.js @@ -67,6 +67,9 @@ class SplashScreen extends React.PureComponent { } } } + + // splash screen is done at this point, next page to be displayed will be user-interactable + NativeModules.Firebase.logLaunchTiming(); }; componentWillReceiveProps(nextProps) {