UNPKG

botpress

Version:

The world's first CMS for bots. Easily create, manage and extend chatbots.

65 lines (48 loc) 1.72 kB
'use strict'; var _os = require('os'); var _os2 = _interopRequireDefault(_os); var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto); var _universalAnalytics = require('universal-analytics'); var _universalAnalytics2 = _interopRequireDefault(_universalAnalytics); var _nodeMachineId = require('node-machine-id'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = botfile => { let visitor = null; let queued = []; (0, _nodeMachineId.machineId)().catch(() => { const hash = _crypto2.default.createHash('sha256'); hash.update(_os2.default.arch() + _os2.default.hostname() + _os2.default.platform() + _os2.default.type()); return hash.digest('hex'); }).then(mid => { visitor = (0, _universalAnalytics2.default)('UA-90044826-1', mid, { strictCidFormat: false }); queued.forEach(a => a()); queued = []; }); const track = (category, action, label = null, value = null) => { if (!!botfile.optOutStats) { return; // Don't track if bot explicitly opted out from stats collection } if (!visitor) { queued.push(() => track(category, action, label, value)); return; } visitor.event(category, action, label, value, () => { /* ignore errors */ }); }; const trackException = message => { if (!!botfile.optOutStats) { return; // Don't track if bot explicitly opted out from stats collection } if (!visitor) { queued.push(() => trackException(message)); return; } visitor.event(message, () => { /* ignore errors */ }); }; return { track, trackException }; }; //# sourceMappingURL=stats.js.map