Skip to content

Commit 8333d04

Browse files
committed
Final fixes
1 parent b7a247c commit 8333d04

8 files changed

+54
-40
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Your application will be launched and the VSCode debugger will attach. If you wa
3131

3232
### NativeScript commands
3333

34-
Type `NativeScript` in the Command Palette and you will see all available commands.
34+
Type `NativeScript` in the Command Palette and you will see all available commands.
3535

3636
![NativeScript Commands](https://raw.githubusercontent.com/NativeScript/nativescript-vscode-extension/master/images/screenshots/nativescript-commands.png)
3737

@@ -50,7 +50,7 @@ If your version of NativeScript is incompatible with the extension you will see
5050
npm install
5151
npm run build # compiles TypeScript source files to JavaScript
5252
npm run package # produces nativescript-*.*.*.vsix in the root folder
53-
```
53+
```
5454
5555
3. To test the extension run the following commands in the root repository folder:
5656
@@ -60,6 +60,17 @@ If your version of NativeScript is incompatible with the extension you will see
6060
npm run launch-as-server # launches the debug adapter in server mode
6161
# execute this in a separate terminal
6262
npm run test-mac # run tests on ios device
63-
```
63+
```
6464
6565
4. To install the extension drag and drop the `nativescript-*.*.*.vsix` package in the VS Code.
66+
67+
### How to disable the analytics
68+
NativeScript Extension for Visual Studio Code collects usage data and sends it to Progress to help improve our products and services.
69+
70+
If you don’t wish to send usage data to Progress, you can set the **nativescript.analytics.enabled** to **false**.
71+
72+
From **File > Preferences > Settings** (macOS: **Code > Preferences > Settings**), add the following option to disable analytics:
73+
74+
```
75+
"nativescript.analytics.enabled": false
76+
```

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"source-map": "0.6.1",
3030
"tree-kill": "^1.2.0",
3131
"universal-analytics": "0.4.13",
32+
"uuid": "^3.2.1",
3233
"vscode-chrome-debug-core": "~3.9.0",
3334
"vscode-debugadapter": "1.26.0",
3435
"vscode-debugprotocol": "1.26.0",

src/analytics/analyticsBaseInfo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export interface AnalyticsBaseInfo {
99
operatingSystem: OperatingSystem,
1010
cliVersion: string,
1111
extensionVersion: string,
12-
userId: string
12+
clientId: string
1313
}

src/analytics/analyticsService.ts

+33-31
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,34 @@ import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
55
import { Services } from '../services/extensionHostServices';
66
import * as utils from '../common/utilities';
77
import * as vscode from 'vscode';
8+
import * as uuid from "uuid";
89

910
export class AnalyticsService {
10-
private static HAS_ANALYTICS_PROMPT_SHOWN = "nativescript.hasAnalyticsPromptShown";
11-
private static ANALYTICS_PROMPT_MESSAGE = "Help improve NativeScript Extension by allowing Progress to collect data usage.";
12-
private static ANALYTICS_PROMPT_ACTION = "Track";
11+
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = "nativescript.hasAnalyticsPromptShown";
12+
private static CLIENT_ID_KEY = "nativescript.analyticsClientId";
13+
private static ANALYTICS_PROMPT_MESSAGE = "Help improve NativeScript Extension by allowing Progress to collect data usage. " +
14+
"Read our [privacy statement](https://www.telerik.com/about/privacy-policy) and " +
15+
"learn how to [disable analytics settings.](https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics). " +
16+
"Do you want to enable analytics?";
17+
private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes";
18+
private static ANALYTICS_PROMPT_DENY_ACTION = "No";
1319

1420
private _globalState: vscode.Memento;
1521
private _baseInfo: AnalyticsBaseInfo;
1622
private _gua: GUAService;
1723
private _analyticsEnabled: boolean;
18-
private disposables: vscode.Disposable[] = [];
19-
20-
public static generateMachineId(): string {
21-
let machineId = '';
22-
try {
23-
let netInterfaces = os.networkInterfaces();
24-
Object.keys(netInterfaces).forEach(interfName => {
25-
netInterfaces[interfName].forEach(interf => {
26-
if (!interf.internal) {
27-
machineId += `${interf.mac}-`;
28-
}
29-
});
30-
});
31-
} catch(e) {}
32-
return machineId;
33-
}
3424

3525
constructor(globalState: vscode.Memento) {
3626
this._globalState = globalState;
3727

38-
//TODO: Dispose
3928
vscode.workspace.onDidChangeConfiguration(() => this.updateAnalyticsEnabled());
4029

4130
this._baseInfo = {
4231
cliVersion: Services.cli().version.toString(),
4332
extensionVersion: utils.getInstalledExtensionVersion().toString(),
4433
operatingSystem: AnalyticsService.getOperatingSystem(),
45-
userId: AnalyticsService.generateMachineId()
34+
clientId: this.getOrGenerateClientId()
4635
};
47-
48-
this.initializeAnalytics();
4936
}
5037

5138
public launchDebugger(request: string, platform: string): Promise<any> {
@@ -82,10 +69,13 @@ export class AnalyticsService {
8269
};
8370
}
8471

85-
private initializeAnalytics() : void {
86-
const hasAnalyticsPromptShown = this._globalState.get(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN);
87-
if(hasAnalyticsPromptShown) {
88-
vscode.window.showInformationMessage(AnalyticsService.ANALYTICS_PROMPT_MESSAGE, AnalyticsService.ANALYTICS_PROMPT_ACTION)
72+
public initialize() : void {
73+
const hasAnalyticsPromptShown = this._globalState.get<boolean>(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY);
74+
if(!hasAnalyticsPromptShown) {
75+
vscode.window.showInformationMessage(AnalyticsService.ANALYTICS_PROMPT_MESSAGE,
76+
AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION,
77+
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION
78+
)
8979
.then(result => this.onAnalyticsMessageConfirmation(result));
9080

9181
return;
@@ -94,19 +84,31 @@ export class AnalyticsService {
9484
this.updateAnalyticsEnabled();
9585
}
9686

87+
private getOrGenerateClientId(): string {
88+
let clientId = this._globalState.get<string>(AnalyticsService.CLIENT_ID_KEY);
89+
90+
if(!clientId) {
91+
clientId = uuid.v4();
92+
this._globalState.update(AnalyticsService.CLIENT_ID_KEY, clientId);
93+
}
94+
95+
return clientId;
96+
}
97+
9798
private onAnalyticsMessageConfirmation(result: string) : void {
98-
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACTION ? true : false;
99+
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false;
100+
101+
this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY, true);
99102

100103
Services.workspaceConfigService().isAnalyticsEnabled = shouldEnableAnalytics;
101104
this.updateAnalyticsEnabled();
102-
this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN, true);
103105
}
104106

105107
private updateAnalyticsEnabled() {
106108
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
107109

108-
if(this._analyticsEnabled) {
109-
this._gua = this._gua || new GUAService('UA-111455-29', this._baseInfo);
110+
if(this._analyticsEnabled && !this._gua) {
111+
this._gua = new GUAService('UA-111455-29', this._baseInfo);
110112
}
111113
}
112114
}

src/analytics/guaService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export class GUAService {
99
private _getBasePayload: () => any;
1010

1111
constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
12-
this._visitor = ua(trackingId, baseInfo.userId, { requestOptions: {}, strictCidFormat: false });
12+
this._visitor = ua(trackingId, baseInfo.clientId, { requestOptions: {}, strictCidFormat: false });
1313
this._getBasePayload = () => {
1414
return {
15-
uid: baseInfo.userId,
15+
cid: baseInfo.clientId,
1616
dh: 'ns-vs-extension.org',
1717
cd5: baseInfo.cliVersion,
1818
cd6: OperatingSystem[baseInfo.operatingSystem],

src/common/workspaceConfigService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class WorkspaceConfigService {
66
}
77

88
public set isAnalyticsEnabled(isAnalyticsEnabled: boolean) {
9-
vscode.workspace.getConfiguration('nativescript').update('analytics.enabled', isAnalyticsEnabled);
9+
vscode.workspace.getConfiguration('nativescript').update('analytics.enabled', isAnalyticsEnabled, vscode.ConfigurationTarget.Global);
1010
}
1111

1212
public get tnsPath(): string {

src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function activate(context: vscode.ExtensionContext) {
1010
Services.globalState = context.globalState;
1111
Services.cliPath = Services.workspaceConfigService().tnsPath || Services.cliPath;
1212
Services.extensionServer().start();
13+
Services.analyticsService().initialize();
1314

1415
// Check for newer extension version
1516
Services.extensionVersionService().isLatestInstalled.then(result => {

src/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
"./debug-adapter/webKitDebug.ts",
2424
"./main.ts",
25-
"./tests/adapter.test.ts",
26-
"./analytics/eqatecMonitor.min.js"
25+
"./tests/adapter.test.ts"
2726
]
2827
}

0 commit comments

Comments
 (0)