umami/scripts/telemetry.js

41 lines
820 B
JavaScript
Raw Normal View History

2022-03-17 05:50:24 +01:00
const os = require('os');
const isCI = require('is-ci');
const pkg = require('../package.json');
2023-07-19 13:06:49 +02:00
const url = 'https://api.umami.is/v1/telemetry';
2022-03-17 05:50:24 +01:00
async function sendTelemetry(type) {
2022-03-19 06:39:39 +01:00
const { default: isDocker } = await import('is-docker');
const { default: fetch } = await import('node-fetch');
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,
},
2022-03-19 06:39:39 +01:00
};
2022-04-05 00:14:26 +02:00
try {
await fetch(url, {
method: 'post',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
2022-04-05 00:14:26 +02:00
});
} catch {
// Ignore
}
2022-03-17 05:50:24 +01:00
}
2022-03-19 05:57:58 +01:00
module.exports = {
sendTelemetry,
};