serverless
Version:
Serverless Framework - Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more
34 lines (29 loc) • 801 B
JavaScript
;
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,
};