2
0
mirror of https://github.com/frappe/books.git synced 2024-11-12 16:36:27 +00:00

incr: capture telemetryobject on unload

This commit is contained in:
18alantom 2022-03-10 17:36:28 +05:30
parent 132edff44b
commit f6219f956c
3 changed files with 27 additions and 4 deletions

View File

@ -96,7 +96,9 @@ export async function connectToLocalDatabase(filePath) {
// second init with currency, normal usage
await callInitializeMoneyMaker();
telemetry.start();
await telemetry.setCount();
return { connectionSuccess: true, reason: '' };
}

View File

@ -8,6 +8,7 @@ import config from './config';
import { getErrorHandled, handleError } from './errorHandling';
import { IPC_CHANNELS, IPC_MESSAGES } from './messages';
import router from './router';
import telemetry from './telemetry/telemetry';
import { outsideClickDirective } from './ui';
import { setLanguageMap, showToast, stringifyCircular } from './utils';
(async () => {
@ -135,4 +136,14 @@ function registerIpcRendererListeners() {
error.name = 'Updation Error';
handleError(true, error);
});
document.addEventListener('visibilitychange', function () {
if (document.visibilityState !== 'hidden') {
return;
}
const telemetryData = telemetry.stop();
console.log(telemetryData);
// navigator.sendBeacon('', telemetryData)
});
}

View File

@ -9,7 +9,7 @@ class TelemetryManager {
#telemetryObject: Partial<Telemetry> = {};
start() {
this.#telemetryObject.locale ||= getLocale();
this.#telemetryObject.locale = getLocale();
this.#telemetryObject.deviceId ||= getDeviceId();
this.#telemetryObject.instanceId ||= getInstanceId();
this.#telemetryObject.openTime ||= new Date().valueOf();
@ -49,18 +49,28 @@ class TelemetryManager {
this.#telemetryObject.errors[name] += 1;
}
async stop() {
async setCount() {
this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {};
}
stop() {
// Will set ids if not set.
this.start();
//@ts-ignore
this.#telemetryObject.version = frappe.store.appVersion ?? '';
this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {};
this.#telemetryObject.closeTime = new Date().valueOf();
const telemetryObject = this.#telemetryObject;
this.#started = false;
this.#telemetryObject = {};
if (config.get(ConfigKeys.Telemetry) === TelemetrySetting.dontLogAnything) {
return;
return '';
}
return JSON.stringify(telemetryObject);
}
get telemetryObject(): Readonly<Partial<Telemetry>> {