Skip to content

Commit 8f2337b

Browse files
authored
Merge pull request #171 from NativeScript/iiivanov/analytics-opt-out
GDPR Changes
2 parents 19ac2db + adc4444 commit 8f2337b

11 files changed

+106
-147
lines changed

README.md

+16-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,19 @@ 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+
The anonymous usage data collected by Progress from the NativeScript extension for Visual Studio Code is used strictly to improve the product and its services, and enhance the overall user experience.
69+
70+
If you have previously enabled the analytics option, you can disable it by following the steps outlined below:
71+
72+
1. Open the Visual Studio Code Settings
73+
- on Windows, select **File > Preferences > Settings**
74+
- on macOS, select **Code > Preferences > Settings**
75+
2. Add the following option (or update the existing one) to disable the analytics:
76+
```
77+
"nativescript.analytics.enabled": false
78+
```

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"node-ipc": "8.10.3",
2929
"source-map": "0.6.1",
3030
"universal-analytics": "0.4.13",
31+
"uuid": "^3.2.1",
3132
"vscode-chrome-debug-core": "~3.9.0",
3233
"vscode-debugadapter": "1.26.0",
3334
"vscode-debugprotocol": "1.26.0",
@@ -66,7 +67,7 @@
6667
"properties": {
6768
"nativescript.analytics.enabled": {
6869
"type": "boolean",
69-
"default": true,
70+
"default": false,
7071
"description": "Enables the extension tracking."
7172
},
7273
"nativescript.tnsPath": {

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

+78-40
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,114 @@
11
import * as os from 'os';
22
import { Version } from '../common/version';
33
import { GUAService } from './guaService';
4-
import { TelerikAnalyticsService } from './telerikAnalyticsService';
54
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
65
import { Services } from '../services/extensionHostServices';
76
import * as utils from '../common/utilities';
7+
import * as vscode from 'vscode';
8+
import * as uuid from "uuid";
89

910
export class AnalyticsService {
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 us improve the NativeScript extension by allowing Progress to collect anonymous usage data.
14+
For more information about the gathered information and how it is used, read our [privacy statement](https://www.telerik.com/about/privacy-policy).
15+
You can [disable the analytics and data collection](https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics) at any given time.
16+
Do you want to enable analytics?`;
17+
private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes";
18+
private static ANALYTICS_PROMPT_DENY_ACTION = "No";
19+
20+
private _globalState: vscode.Memento;
1021
private _baseInfo: AnalyticsBaseInfo;
1122
private _gua: GUAService;
12-
private _ta: TelerikAnalyticsService;
1323
private _analyticsEnabled: boolean;
1424

15-
public static generateMachineId(): string {
16-
let machineId = '';
17-
try {
18-
let netInterfaces = os.networkInterfaces();
19-
Object.keys(netInterfaces).forEach(interfName => {
20-
netInterfaces[interfName].forEach(interf => {
21-
if (!interf.internal) {
22-
machineId += `${interf.mac}-`;
23-
}
24-
});
25-
});
26-
} catch(e) {}
27-
return machineId;
28-
}
25+
constructor(globalState: vscode.Memento) {
26+
this._globalState = globalState;
2927

30-
constructor() {
31-
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
32-
let operatingSystem = OperatingSystem.Other;
33-
switch(process.platform) {
34-
case 'win32': { operatingSystem = OperatingSystem.Windows; break; }
35-
case 'darwin': { operatingSystem = OperatingSystem.OSX; break; }
36-
case 'linux':
37-
case 'freebsd': { operatingSystem = OperatingSystem.Linux; break; }
38-
};
28+
vscode.workspace.onDidChangeConfiguration(() => this.updateAnalyticsEnabled());
3929

4030
this._baseInfo = {
4131
cliVersion: Services.cli().version.toString(),
4232
extensionVersion: utils.getInstalledExtensionVersion().toString(),
43-
operatingSystem: operatingSystem,
44-
userId: AnalyticsService.generateMachineId()
33+
operatingSystem: AnalyticsService.getOperatingSystem(),
34+
clientId: this.getOrGenerateClientId()
4535
};
46-
47-
if(this._analyticsEnabled) {
48-
this._gua = new GUAService('UA-111455-29', this._baseInfo);
49-
this._ta = new TelerikAnalyticsService('b8b2e51f188f43e9b0dfb899f7b71cc6', this._baseInfo);
50-
}
5136
}
5237

5338
public launchDebugger(request: string, platform: string): Promise<any> {
5439
if(this._analyticsEnabled) {
5540
try {
56-
return Promise.all([
57-
this._gua.launchDebugger(request, platform),
58-
this._ta.launchDebugger(request, platform)
59-
]);
41+
return this._gua.launchDebugger(request, platform);
6042
} catch(e) {}
6143
}
44+
6245
return Promise.resolve();
6346
}
6447

6548
public runRunCommand(platform: string): Promise<any> {
6649
if(this._analyticsEnabled) {
6750
try {
68-
return Promise.all([
69-
this._gua.runRunCommand(platform),
70-
this._ta.runRunCommand(platform)
71-
]);
51+
return this._gua.runRunCommand(platform);
7252
} catch(e) { }
7353
}
54+
7455
return Promise.resolve();
7556
}
57+
58+
private static getOperatingSystem() : OperatingSystem {
59+
switch(process.platform) {
60+
case 'win32':
61+
return OperatingSystem.Windows;
62+
case 'darwin':
63+
return OperatingSystem.OSX;
64+
case 'linux':
65+
case 'freebsd':
66+
return OperatingSystem.Linux;
67+
default:
68+
return OperatingSystem.Other;
69+
};
70+
}
71+
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+
)
79+
.then(result => this.onAnalyticsMessageConfirmation(result));
80+
81+
return;
82+
}
83+
84+
this.updateAnalyticsEnabled();
85+
}
86+
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+
98+
private onAnalyticsMessageConfirmation(result: string) : void {
99+
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false;
100+
101+
this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY, true);
102+
103+
Services.workspaceConfigService().isAnalyticsEnabled = shouldEnableAnalytics;
104+
this.updateAnalyticsEnabled();
105+
}
106+
107+
private updateAnalyticsEnabled() {
108+
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
109+
110+
if(this._analyticsEnabled && !this._gua) {
111+
this._gua = new GUAService('UA-111455-29', this._baseInfo);
112+
}
113+
}
76114
}

0 commit comments

Comments
 (0)