forked from release-it/release-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.js
78 lines (71 loc) · 1.98 KB
/
metrics.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const { EOL } = require('os');
const got = require('got');
const supportsColor = require('supports-color');
const windowSize = require('window-size');
const uuid = require('uuid');
const osName = require('os-name');
const isCi = require('is-ci');
const _ = require('lodash');
const { config } = require('./config');
const { debug } = require('./debug');
const pkg = require('../package.json');
const cast = value => (value ? 1 : 0);
const pickDebugProps = response => _.pick(response, ['statusCode', 'statusMessage', 'url']);
const { options } = config;
const cid = uuid.v4();
const dimensions = windowSize ? windowSize.get() : { width: 0, height: 0 };
const vp = `${dimensions.width}x${dimensions.height}`;
const depths = ['1-bit', '4-bit', '8-bit', '24-bits'];
const sd = depths[supportsColor.level || 0];
const payload = {
v: 1,
tid: 'UA-108828841-1',
cid,
vp,
sd,
cd1: pkg.version,
cd2: process.version,
cd3: osName(),
cd4: cast(config.isInteractive),
cd5: cast(config.isDryRun),
cd6: cast(config.isVerbose),
cd7: cast(config.isDebug),
cd8: cast(options.buildCommand),
cd9: options.preReleaseId,
cd10: cast(options.dist.repo),
cd11: cast(isCi),
cd12: cast(options.git.tag),
cd13: cast(options.npm.publish),
cd14: cast(options.github.release),
cd15: options.increment
};
const send = payload =>
got('http://www.google-analytics.com/collect', {
timeout: 300,
retries: 0,
form: true,
body: payload
})
.then(pickDebugProps)
.then(debug)
.catch(debug);
module.exports.trackEvent = config.isCollectMetrics
? action =>
send(
Object.assign({}, payload, {
t: 'event',
ec: 'session',
ea: action
})
)
: () => Promise.resolve();
module.exports.trackException = config.isCollectMetrics
? err =>
config.isCollectMetrics &&
send(
Object.assign({}, payload, {
t: 'exception',
exd: err.message.split(EOL)[0]
})
)
: () => Promise.resolve();