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

View file

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

View file

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