UNPKG

1.53 kBJavaScriptView Raw
1"use strict";
2/**
3 * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
4 * SPDX-License-Identifier: LGPL-3.0-or-later
5 */
6var __importDefault = (this && this.__importDefault) || function (mod) {
7 return (mod && mod.__esModule) ? mod : { "default": mod };
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10const insight_1 = __importDefault(require("insight"));
11const path_1 = __importDefault(require("path"));
12const read_json_sync_1 = __importDefault(require("read-json-sync"));
13const GA_TOKEN = 'UA-37033501-13';
14let insight;
15/**
16 * Initialize insight facility
17 * @return {Promise} a promise fulfilled when initialization is done
18 */
19function init() {
20 return new Promise(resolve => {
21 try {
22 const projectPkgJson = read_json_sync_1.default(path_1.default.join(process.cwd(), 'package.json'));
23 exports.PROJECT_NAME = projectPkgJson.name;
24 exports.PROJECT_VERSION = projectPkgJson.version;
25 insight = new insight_1.default({
26 trackingCode: GA_TOKEN,
27 pkg: require('../package.json'),
28 });
29 }
30 catch (err) {
31 // ignore
32 }
33 if (insight && insight.optOut === undefined) {
34 insight.askPermission(undefined, resolve);
35 }
36 else {
37 resolve();
38 }
39 });
40}
41exports.init = init;
42exports.track = (...args) => {
43 if (insight) {
44 insight.track(insight.config.get('clientId'), insight.PROJECT_NAME, ...args);
45 }
46};