1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import Insight from 'insight';
|
7 | import path from 'path';
|
8 | import readJsonSync from 'read-json-sync';
|
9 |
|
10 | const GA_TOKEN = 'UA-37033501-13';
|
11 |
|
12 | export let PROJECT_NAME;
|
13 | export let PROJECT_VERSION;
|
14 |
|
15 | let insight;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export function init() {
|
22 | return new Promise(resolve => {
|
23 | try {
|
24 | const projectPkgJson = readJsonSync(
|
25 | path.join(process.cwd(), 'package.json')
|
26 | );
|
27 |
|
28 | PROJECT_NAME = projectPkgJson.name;
|
29 | PROJECT_VERSION = projectPkgJson.version;
|
30 |
|
31 | insight = new Insight({
|
32 | trackingCode: GA_TOKEN,
|
33 | pkg: require('../package.json'),
|
34 | });
|
35 | } catch (err) {
|
36 |
|
37 | }
|
38 |
|
39 | if (insight && insight.optOut === undefined) {
|
40 | insight.askPermission(undefined, resolve);
|
41 | } else {
|
42 | resolve();
|
43 | }
|
44 | });
|
45 | }
|
46 |
|
47 | export const track = (...args) => {
|
48 | if (insight) {
|
49 | insight.track(
|
50 | insight.config.get('clientId'),
|
51 | insight.PROJECT_NAME,
|
52 | ...args
|
53 | );
|
54 | }
|
55 | };
|