-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathguaService.ts
52 lines (42 loc) · 1.69 KB
/
guaService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as ua from 'universal-analytics';
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
/**
* Google Universal Analytics Service
*/
export class GUAService {
private _visitor: ua.Visitor;
private _getBasePayload: () => any;
constructor(trackingId: string, baseInfo: IAnalyticsBaseInfo) {
const proxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const requestOptions = proxy ? { proxy } : {};
this._visitor = ua(trackingId, baseInfo.clientId, { requestOptions, strictCidFormat: false });
this._getBasePayload = () => {
return {
cd5: baseInfo.cliVersion,
cd6: OperatingSystem[baseInfo.operatingSystem],
cd7: baseInfo.extensionVersion,
cid: baseInfo.clientId,
dh: 'ns-vs-extension.org',
};
};
}
public launchDebugger(request: string, platform: string): Promise<any> {
const payload = this._getBasePayload();
payload.ec = 'vscode-extension-debug'; // event category
payload.ea = `debug-${request}-on-${platform}`; // event action
return this.sendEvent(payload);
}
public runRunCommand(platform: string): Promise<any> {
const payload = this._getBasePayload();
payload.ec = 'vscode-extension-command'; // event category
payload.ea = `command-run-on-${platform}`; // event action
return this.sendEvent(payload);
}
private sendEvent(params): Promise<any> {
return new Promise<void>((res, rej) => {
this._visitor.event(params, (err) => {
return err ? rej(err) : res();
});
});
}
}