App timing #123

Merged
akinwale merged 2 commits from app-timing into master 2020-02-17 07:24:39 +01:00
3 changed files with 13 additions and 29 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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) {