forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment.js
More file actions
33 lines (29 loc) · 803 Bytes
/
segment.js
File metadata and controls
33 lines (29 loc) · 803 Bytes
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
'use strict';
const BbPromise = require('bluebird');
const fetch = require('node-fetch');
const isTrackingDisabled = require('./isTrackingDisabled');
/* note segment call swallows errors */
function request(url, payload) {
return fetch(url, {
headers: {
'content-type': 'application/json',
},
method: 'POST',
timeout: '1000',
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then(() => BbPromise.resolve())
.catch(() => BbPromise.resolve());
}
function track(payload) {
const TRACKING_IS_DISABLED = isTrackingDisabled();
// exit early is tracking disabled
if (TRACKING_IS_DISABLED) {
return BbPromise.resolve();
}
return request('https://tracking.serverlessteam.com/v1/track', payload);
}
module.exports = {
track,
};