Track duration of startup events
Tracking only `user/me` for now.
This commit is contained in:
parent
b8c763f749
commit
398388de10
3 changed files with 46 additions and 14 deletions
|
@ -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) => {
|
||||||
|
if (analytics.appStartTime !== 0) {
|
||||||
sendGaEvent('diag_app_ready', {
|
sendGaEvent('diag_app_ready', {
|
||||||
[GA_DIMENSIONS.DURATION_MS]: timeToReadyMs,
|
[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', {
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue