Track duration of startup events

Tracking only `user/me` for now.
This commit is contained in:
infinite-persistence 2021-10-22 15:59:26 +08:00
parent b8c763f749
commit 398388de10
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 46 additions and 14 deletions

View file

@ -28,7 +28,9 @@ export const GA_DIMENSIONS = {
TYPE: 'type',
ACTION: 'action',
VALUE: 'value',
START_TIME_MS: 'start_time_ms',
DURATION_MS: 'duration_ms',
END_TIME_MS: 'end_time_ms',
};
// import getConnectionSpeed from 'util/detect-user-bandwidth';
@ -50,6 +52,8 @@ const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/report
const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds
type Analytics = {
appStartTime: number,
eventStartTime: any,
error: (string) => Promise<any>,
sentryError: ({} | string, {}) => Promise<any>,
setUser: (Object) => void,
@ -78,9 +82,11 @@ type Analytics = {
emailProvidedEvent: () => void,
emailVerifiedEvent: () => void,
rewardEligibleEvent: () => void,
startupEvent: () => void,
initAppStartTime: (startTime: number) => void,
startupEvent: (time: number) => void,
eventStarted: (name: string, time: number, id?: string) => void,
eventCompleted: (name: string, time: number, id?: string) => void,
purchaseEvent: (number) => void,
readyEvent: (number) => void,
openUrlEvent: (string) => void,
reportEvent: (string, any) => void,
};
@ -221,6 +227,9 @@ async function sendWatchmanData(body) {
}
const analytics: Analytics = {
appStartTime: 0,
eventStartTime: {},
// receive buffer events from tracking plugin and save buffer amounts and times for backend call
videoBufferEvent: async (claim, data) => {
amountOfBufferEvents = amountOfBufferEvents + 1;
@ -424,14 +433,31 @@ const analytics: Analytics = {
trending_algorithm: trendingAlgorithm,
});
},
startupEvent: () => {
// TODO: This can be removed (use the automated 'session_start' instead).
// sendGaEvent('app_diagnostics', 'startup');
initAppStartTime: (startTime: number) => {
analytics.appStartTime = startTime;
},
readyEvent: (timeToReadyMs: number) => {
sendGaEvent('diag_app_ready', {
[GA_DIMENSIONS.DURATION_MS]: timeToReadyMs,
});
startupEvent: (time: number) => {
if (analytics.appStartTime !== 0) {
sendGaEvent('diag_app_ready', {
[GA_DIMENSIONS.DURATION_MS]: time - analytics.appStartTime,
});
}
},
eventStarted: (name: string, time: number, id?: string) => {
const key = id || name;
analytics.eventStartTime[key] = time;
},
eventCompleted: (name: string, time: number, id?: string) => {
const key = id || name;
if (analytics.eventStartTime[key]) {
sendGaEvent(name, {
[GA_DIMENSIONS.START_TIME_MS]: analytics.eventStartTime[key] - analytics.appStartTime,
[GA_DIMENSIONS.DURATION_MS]: time - analytics.eventStartTime[key],
[GA_DIMENSIONS.END_TIME_MS]: time - analytics.appStartTime,
});
delete analytics.eventStartTime[key];
}
},
purchaseEvent: (purchaseInt: number) => {
sendGaEvent('purchase', {

View file

@ -97,8 +97,7 @@ Lbry.setOverride(
);
// @endif
const startTime = Date.now();
analytics.startupEvent();
analytics.initAppStartTime(Date.now());
// @if TARGET='app'
const { autoUpdater } = remote.require('electron-updater');
@ -266,14 +265,13 @@ function AppWrapper() {
if (DEFAULT_LANGUAGE) {
app.store.dispatch(doFetchLanguage(DEFAULT_LANGUAGE));
}
app.store.dispatch(doUpdateIsNightAsync());
app.store.dispatch(doDaemonReady());
app.store.dispatch(doBlackListedOutpointsSubscribe());
app.store.dispatch(doFilteredOutpointsSubscribe());
const appReadyTime = Date.now();
const timeToStart = appReadyTime - startTime;
analytics.readyEvent(timeToStart);
analytics.startupEvent(Date.now());
}
}, [readyToLaunch, persistDone]);

View file

@ -60,6 +60,14 @@ function handleAnalyticsForAction(action: { type: string, data: any }) {
});
break;
case ACTIONS.AUTHENTICATION_STARTED:
analytics.eventStarted('diag_authentication', Date.now());
break;
case ACTIONS.AUTHENTICATION_SUCCESS:
analytics.eventCompleted('diag_authentication', Date.now());
break;
default:
// Do nothing
break;