@@ -5,47 +5,34 @@ import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
5
5
import { Services } from '../services/extensionHostServices' ;
6
6
import * as utils from '../common/utilities' ;
7
7
import * as vscode from 'vscode' ;
8
+ import * as uuid from "uuid" ;
8
9
9
10
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" ;
13
19
14
20
private _globalState : vscode . Memento ;
15
21
private _baseInfo : AnalyticsBaseInfo ;
16
22
private _gua : GUAService ;
17
23
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
- }
34
24
35
25
constructor ( globalState : vscode . Memento ) {
36
26
this . _globalState = globalState ;
37
27
38
- //TODO: Dispose
39
28
vscode . workspace . onDidChangeConfiguration ( ( ) => this . updateAnalyticsEnabled ( ) ) ;
40
29
41
30
this . _baseInfo = {
42
31
cliVersion : Services . cli ( ) . version . toString ( ) ,
43
32
extensionVersion : utils . getInstalledExtensionVersion ( ) . toString ( ) ,
44
33
operatingSystem : AnalyticsService . getOperatingSystem ( ) ,
45
- userId : AnalyticsService . generateMachineId ( )
34
+ clientId : this . getOrGenerateClientId ( )
46
35
} ;
47
-
48
- this . initializeAnalytics ( ) ;
49
36
}
50
37
51
38
public launchDebugger ( request : string , platform : string ) : Promise < any > {
@@ -82,10 +69,13 @@ export class AnalyticsService {
82
69
} ;
83
70
}
84
71
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
+ )
89
79
. then ( result => this . onAnalyticsMessageConfirmation ( result ) ) ;
90
80
91
81
return ;
@@ -94,19 +84,31 @@ export class AnalyticsService {
94
84
this . updateAnalyticsEnabled ( ) ;
95
85
}
96
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
+
97
98
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 ) ;
99
102
100
103
Services . workspaceConfigService ( ) . isAnalyticsEnabled = shouldEnableAnalytics ;
101
104
this . updateAnalyticsEnabled ( ) ;
102
- this . _globalState . update ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN , true ) ;
103
105
}
104
106
105
107
private updateAnalyticsEnabled ( ) {
106
108
this . _analyticsEnabled = Services . workspaceConfigService ( ) . isAnalyticsEnabled ;
107
109
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 ) ;
110
112
}
111
113
}
112
114
}
0 commit comments