UNPKG

@cto.ai/ops

Version:

💻 CTO.ai Ops - The CLI built for Teams 🚀

41 lines (40 loc) • 1.42 kB
"use strict"; /** * @author: JP Lew (jp@cto.ai) * @date: Sunday, 28th April 2019 1:16:46 am * @lastModifiedBy: JP Lew (jp@cto.ai) * @lastModifiedTime: Wednesday, 4th September 2019 3:08:35 pm * @copyright (c) 2019 CTO.ai */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const analytics_node_1 = tslib_1.__importDefault(require("analytics-node")); const debug_1 = tslib_1.__importDefault(require("debug")); const env_1 = require("../constants/env"); const Feathers_1 = require("./Feathers"); const debug = debug_1.default('ops:AnalyticsService'); class AnalyticsService { constructor(writeKey = env_1.OPS_SEGMENT_KEY) { this.segmentClient = new analytics_node_1.default(writeKey); this.api = new Feathers_1.FeathersClient(); } /* The track method lets you record the actions your users perform. */ track(payload, accessToken) { if (env_1.OPS_DEBUG) { return null; } if (accessToken) { this.api .create('/private/log/event', { metadata: payload, tags: ['track'] }, { headers: { Authorization: accessToken, }, }) .catch(err => { debug('%O', err); }); } return this.segmentClient.track(payload); } } exports.AnalyticsService = AnalyticsService;