1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var GA_TRACKING_CODE = 'UA-64283057-7';
|
23 |
|
24 | var pkg = require('../package.json');
|
25 | var Insight = require('insight');
|
26 | var insight = new Insight({
|
27 | trackingCode: GA_TRACKING_CODE,
|
28 | pkg: pkg
|
29 | });
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function showPrompt () {
|
35 | return new Promise(function (resolve, reject) {
|
36 | var msg = 'May Cordova anonymously report usage statistics to improve the tool over time?';
|
37 | insight._permissionTimeout = module.exports.timeoutInSecs || 30;
|
38 | insight.askPermission(msg, function (unused, optIn) {
|
39 | var EOL = require('os').EOL;
|
40 | if (optIn) {
|
41 | console.log(EOL + 'Thanks for opting into telemetry to help us improve cordova.');
|
42 | module.exports.track('telemetry', 'on', 'via-cli-prompt-choice', 'successful');
|
43 | } else {
|
44 | console.log(EOL + 'You have been opted out of telemetry. To change this, run: cordova telemetry on.');
|
45 |
|
46 | module.exports.track('telemetry', 'off', 'via-cli-prompt-choice', 'successful');
|
47 | }
|
48 | resolve(optIn);
|
49 | });
|
50 | });
|
51 | }
|
52 |
|
53 | function track () {
|
54 |
|
55 | for (var property in arguments) {
|
56 | var val = arguments[property];
|
57 | if (!val || val.length === 0) {
|
58 | delete arguments.property;
|
59 | }
|
60 | }
|
61 | insight.track.apply(insight, arguments);
|
62 | }
|
63 |
|
64 | function turnOn () {
|
65 | insight.optOut = false;
|
66 | }
|
67 |
|
68 | function turnOff () {
|
69 | insight.optOut = true;
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | function clear () {
|
78 | insight.optOut = undefined;
|
79 | }
|
80 |
|
81 | function isOptedIn () {
|
82 | return !insight.optOut;
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | function hasUserOptedInOrOut () {
|
89 | var insightOptOut = insight.optOut === undefined;
|
90 | return !(insightOptOut);
|
91 | }
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function isCI (env) {
|
97 | return !!env.CI;
|
98 | }
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | function isNoTelemetryFlag (args) {
|
104 | return args.indexOf('--no-telemetry') > -1;
|
105 | }
|
106 |
|
107 |
|
108 | module.exports = {
|
109 | track: track,
|
110 | turnOn: turnOn,
|
111 | turnOff: turnOff,
|
112 | clear: clear,
|
113 | isOptedIn: isOptedIn,
|
114 | hasUserOptedInOrOut: hasUserOptedInOrOut,
|
115 | isCI: isCI,
|
116 | showPrompt: showPrompt,
|
117 | isNoTelemetryFlag: isNoTelemetryFlag,
|
118 | timeoutInSecs: 30
|
119 | };
|