-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathGUAService.ts
45 lines (40 loc) · 1.54 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
import * as ua from 'universal-analytics';
import { AnalyticsBaseInfo, OperatingSystem } from './AnalyticsBaseInfo';
/**
* Google Universal Analytics Service
*/
export class GUAService {
private _visitor: any;
private _getBasePayload: () => any;
constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
this._visitor = ua(trackingId, baseInfo.userId, { requestOptions: {}, strictCidFormat: false });
this._getBasePayload = () => {
return {
uid: baseInfo.userId,
dh: 'ns-vs-extension.org',
cd5: baseInfo.cliVersion,
cd6: OperatingSystem[baseInfo.operatingSystem],
cd7: baseInfo.extensionVersion
};
};
}
public launchDebugger(request: string, platform: string): Promise<any> {
let 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> {
let 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<any>((res, rej) => {
this._visitor.event(params, err => {
return err ? rej(err) : res();
});
});
}
}