Updates to insights, event data, telemetry.

This commit is contained in:
Mike Cao 2023-07-23 13:18:01 -07:00
parent 39562d4a64
commit e4bd314bd6
44 changed files with 413 additions and 278 deletions

View file

@ -1,40 +1,24 @@
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const isCI = require('is-ci');
const pkg = require('../package.json');
const dest = path.resolve(__dirname, '../.next/cache/umami.json');
const url = 'https://api.umami.is/v1/telemetry';
async function sendTelemetry(action) {
let json = {};
try {
json = await fs.readJSON(dest);
} catch {
// Ignore
}
try {
await fs.writeJSON(dest, { version: pkg.version });
} catch {
// Ignore
}
async function sendTelemetry(type) {
const { default: isDocker } = await import('is-docker');
const { default: fetch } = await import('node-fetch');
const payload = {
action,
version: pkg.version,
node: process.version,
platform: os.platform(),
arch: os.arch(),
os: `${os.type()} (${os.version()})`,
isDocker: isDocker(),
isCi: isCI,
prevVersion: json.version,
const data = {
type,
payload: {
version: pkg.version,
node: process.version,
platform: os.platform(),
arch: os.arch(),
os: `${os.type()} (${os.version()})`,
isDocker: isDocker(),
isCi: isCI,
},
};
try {
@ -44,7 +28,7 @@ async function sendTelemetry(action) {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
body: JSON.stringify(data),
});
} catch {
// Ignore