1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const tslib_1 = require("tslib");
|
11 | const analytics_node_1 = tslib_1.__importDefault(require("analytics-node"));
|
12 | const debug_1 = tslib_1.__importDefault(require("debug"));
|
13 | const env_1 = require("../constants/env");
|
14 | const Feathers_1 = require("./Feathers");
|
15 | const debug = debug_1.default('ops:AnalyticsService');
|
16 | class AnalyticsService {
|
17 | constructor(writeKey = env_1.OPS_SEGMENT_KEY) {
|
18 | this.segmentClient = new analytics_node_1.default(writeKey);
|
19 | this.api = new Feathers_1.FeathersClient();
|
20 | }
|
21 |
|
22 | track(payload, accessToken) {
|
23 | if (env_1.OPS_DEBUG) {
|
24 | return null;
|
25 | }
|
26 | if (accessToken) {
|
27 | this.api
|
28 | .create('/log/event', { metadata: payload, tags: ['track'] }, {
|
29 | headers: {
|
30 | Authorization: accessToken,
|
31 | },
|
32 | })
|
33 | .catch(err => {
|
34 | debug('%O', err);
|
35 | });
|
36 | }
|
37 | return this.segmentClient.track(payload);
|
38 | }
|
39 | }
|
40 | exports.AnalyticsService = AnalyticsService;
|