forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 2
/
telemetry.js
58 lines (50 loc) · 1.2 KB
/
telemetry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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://telemetry.umami.is/api/send';
async function sendTelemetry(action) {
let json = {};
try {
json = await fs.readJSON(dest);
} catch {
// Ignore
}
try {
await fs.writeJSON(dest, { version: pkg.version });
} catch {
// Ignore
}
const { default: isDocker } = await import('is-docker');
const { default: fetch } = await import('node-fetch');
const upgrade = json.version !== undefined && json.version !== pkg.version;
const payload = {
action,
version: pkg.version,
node: process.version,
platform: os.platform(),
arch: os.arch(),
os: `${os.type()} (${os.version()})`,
docker: isDocker(),
ci: isCI,
prev: json.version,
upgrade,
};
try {
await fetch(url, {
method: 'post',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
} catch {
// Ignore
}
}
module.exports = {
sendTelemetry,
};