@@ -2,55 +2,43 @@ import * as path from "path";
2
2
import { TrackActionNames } from "../constants" ;
3
3
4
4
export class OptionsTrackHelper {
5
- public static SINGLE_OBJECT_SIZE_LIMIT = 400 ;
6
- public static SINGLE_PROPERTY_SIZE_LIMIT = 300 ;
7
5
public static PASSWORD_DETECTION_STRING = "password" ;
8
- public static PASSOWRD_REPLACE_VALUE = "privateData " ;
6
+ public static PASSOWRD_REPLACE_VALUE = "private " ;
9
7
public static PATH_REPLACE_VALUE = "_localpath" ;
10
- public static SIZE_EXEEDED_REPLACE_VALUE = "popertySizeExceeded" ;
11
-
8
+ public static SIZE_EXEEDED_REPLACE_VALUE = "sizeExceeded" ;
12
9
13
10
constructor (
14
11
private $analyticsService : IAnalyticsService ) {
15
12
}
16
13
17
14
public async trackOptions ( options : IOptions ) {
18
- const trackObjects = this . getTrackObjects ( options ) ;
19
- const promises : Promise < void > [ ] = [ ] ;
20
- _ . forEach ( trackObjects , trackObject => {
21
- const json = JSON . stringify ( trackObject ) ;
22
-
23
- const trackPromise = this . $analyticsService . trackEventActionInGoogleAnalytics ( {
24
- action : TrackActionNames . Options ,
25
- additionalData : json
26
- } ) ;
15
+ const trackObject = this . getTrackObject ( options ) ;
27
16
28
- promises . push ( trackPromise ) ;
17
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
18
+ action : TrackActionNames . Options ,
19
+ additionalData : JSON . stringify ( trackObject )
29
20
} ) ;
30
-
31
- await Promise . all ( promises ) ;
32
21
}
33
22
34
- private getTrackObjects ( options : IOptions ) : Object [ ] {
23
+ private getTrackObject ( options : IOptions ) : IDictionary < any > {
35
24
const optionsArgvCopy = _ . cloneDeep ( options . argv ) ;
36
- const data = this . sanitizeTrackObject ( optionsArgvCopy , options ) ;
37
25
38
- return this . splitTrackObjects ( data ) ;
26
+ return this . sanitizeTrackObject ( optionsArgvCopy , options ) ;
39
27
}
40
28
41
29
private sanitizeTrackObject ( data : IDictionary < any > , options ?: IOptions ) : IDictionary < any > {
42
- const shorthands = options ? options . shorthands : [ ] ;
43
- const optionsDefinitions = options ? options . options : { } ;
30
+ const shorthands = options ? options . shorthands : [ ] ;
31
+ const optionsDefinitions = options ? options . options : { } ;
44
32
45
33
_ . forEach ( data , ( value , key ) => {
46
- if ( this . shouldSkipProperty ( key , value , shorthands , optionsDefinitions ) ) {
34
+ if ( this . shouldSkipProperty ( key , value , shorthands , optionsDefinitions ) ) {
47
35
delete data [ key ] ;
48
36
} else {
49
- if ( key . toLowerCase ( ) . indexOf ( OptionsTrackHelper . PASSWORD_DETECTION_STRING ) >= 0 ) {
37
+ if ( key . toLowerCase ( ) . indexOf ( OptionsTrackHelper . PASSWORD_DETECTION_STRING ) >= 0 ) {
50
38
value = OptionsTrackHelper . PASSOWRD_REPLACE_VALUE ;
51
- } else if ( typeof value === "string" && value !== path . basename ( value ) ) {
39
+ } else if ( _ . isString ( value ) && value !== path . basename ( value ) ) {
52
40
value = OptionsTrackHelper . PATH_REPLACE_VALUE ;
53
- } else if ( _ . isObject ( value ) && ! _ . isArray ( value ) ) {
41
+ } else if ( _ . isObject ( value ) && ! _ . isArray ( value ) ) {
54
42
value = this . sanitizeTrackObject ( value ) ;
55
43
}
56
44
data [ key ] = value ;
@@ -61,68 +49,29 @@ export class OptionsTrackHelper {
61
49
}
62
50
63
51
private shouldSkipProperty ( key : string , value : any , shorthands : string [ ] = [ ] , options : IDictionary < IDashedOption > = { } ) : Boolean {
64
- if ( shorthands . indexOf ( key ) >= 0 ) {
52
+ if ( shorthands . indexOf ( key ) >= 0 ) {
65
53
return true ;
66
54
}
67
55
68
- if ( key . indexOf ( "-" ) >= 0 ) {
56
+ if ( key . indexOf ( "-" ) >= 0 ) {
69
57
return true ;
70
58
}
71
59
72
- if ( key === "_" ) {
60
+ if ( key === "_" ) {
73
61
return true ;
74
62
}
75
-
63
+
76
64
const optionDef = options [ key ] ;
77
- if ( optionDef && optionDef . type === OptionType . Boolean ) {
78
- if ( optionDef . default !== true && value === false || optionDef . default === true && value === true ) {
65
+ if ( optionDef && optionDef . type === OptionType . Boolean ) {
66
+ if ( optionDef . default !== true && value === false || optionDef . default === true && value === true ) {
79
67
return true ;
80
68
}
81
69
}
82
70
83
- if ( _ . isUndefined ( value ) ) {
71
+ if ( _ . isUndefined ( value ) ) {
84
72
return true ;
85
73
}
86
74
}
87
-
88
- private splitTrackObjects ( trackData : Object ) : Object [ ] {
89
- const json = JSON . stringify ( trackData ) ;
90
- const firstObject : IDictionary < any > = { } ;
91
- const secondObject : IDictionary < any > = { } ;
92
- const bigFields : Object [ ] = [ ] ;
93
-
94
- if ( json . length > OptionsTrackHelper . SINGLE_OBJECT_SIZE_LIMIT ) {
95
- const keys = _ . keys ( trackData ) ;
96
-
97
- if ( keys . length === 1 ) {
98
- return [ trackData ] ;
99
- }
100
-
101
- for ( let i = 0 ; i < keys . length ; i ++ ) {
102
- const key = keys [ i ] ;
103
- let value = trackData [ key ] ;
104
- const valueLength = JSON . stringify ( value ) . length ;
105
-
106
- if ( valueLength > OptionsTrackHelper . SINGLE_OBJECT_SIZE_LIMIT ) {
107
- value = "SIZE_EXEEDED_REPLACE_VALUE" ;
108
- }
109
-
110
- if ( valueLength > OptionsTrackHelper . SINGLE_PROPERTY_SIZE_LIMIT ) {
111
- bigFields . push ( {
112
- [ key ] : value
113
- } ) ;
114
- } else if ( i < keys . length / 2 ) {
115
- firstObject [ key ] = value ;
116
- } else {
117
- secondObject [ key ] = value ;
118
- }
119
- }
120
-
121
- return bigFields . concat ( this . splitTrackObjects ( firstObject ) , this . splitTrackObjects ( secondObject ) ) ;
122
- } else {
123
- return [ trackData ] ;
124
- }
125
- }
126
75
}
127
76
128
77
$injector . register ( "optionsTrackHelper" , OptionsTrackHelper ) ;
0 commit comments