@@ -4,94 +4,94 @@ exports.ViroTelemetry = void 0;
4
4
const ViroVersion_1 = require ( "../Utilities/ViroVersion" ) ;
5
5
const react_native_1 = require ( "react-native" ) ;
6
6
class ViroTelemetry {
7
- static _isDisabled = false ;
8
- static _isDebugging = false ;
9
- // TODO: use custom domain
10
- // private static _telemetryUrl = "https://telemetry.nativevision.xyz";
11
- static _telemetryUrl = "https://native-vision-telemetry.onrender.com" ;
12
- static _timeout = 8000 ;
13
- /**
14
- * Allow a user to start debugging the telemetry to see what is sent.
15
- */
16
- static setDebugging ( ) {
17
- this . _isDebugging = true ;
7
+ static _isDisabled = false ;
8
+ static _isDebugging = false ;
9
+ // TODO: use custom domain
10
+ // private static _telemetryUrl = "https://telemetry.reactvision.org";
11
+ static _telemetryUrl = "https://telemetry.reactvision.org" ;
12
+ static _timeout = 8000 ;
13
+ /**
14
+ * Allow a user to start debugging the telemetry to see what is sent.
15
+ */
16
+ static setDebugging ( ) {
17
+ this . _isDebugging = true ;
18
+ }
19
+ /**
20
+ * Allow a user to opt out of telemetry.
21
+ */
22
+ static optOutTelemetry ( ) {
23
+ this . _isDisabled = true ;
24
+ }
25
+ static recordTelemetry ( eventName , payload = { } ) {
26
+ // Skip recording telemetry if the feature is disabled
27
+ if ( this . _isDisabled ) return ;
28
+ // Do not send the telemetry data if debugging. Users may use this feature
29
+ // to preview what data would be sent.
30
+ if ( this . _isDebugging ) {
31
+ console . log (
32
+ `[telemetry] ` + JSON . stringify ( { eventName, payload } , null , 2 )
33
+ ) ;
34
+ return ;
18
35
}
19
- /**
20
- * Allow a user to opt out of telemetry.
21
- */
22
- static optOutTelemetry ( ) {
23
- this . _isDisabled = true ;
36
+ const controller = new AbortController ( ) ;
37
+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , this . _timeout ) ;
38
+ payload = { ...payload , ...this . getAnonymousMeta ( ) } ;
39
+ fetch ( `${ this . _telemetryUrl } /api/v1/record` , {
40
+ method : "PUT" ,
41
+ body : JSON . stringify ( { eventName, payload } ) ,
42
+ headers : { "content-type" : "application/json" } ,
43
+ signal : controller . signal ,
44
+ } )
45
+ . catch ( ( e ) => console . error ( e ) )
46
+ . finally ( ( ) => clearTimeout ( timeoutId ) ) ;
47
+ }
48
+ static getAnonymousMeta ( ) {
49
+ let isExpo = false ;
50
+ try {
51
+ const myModule = require ( "expo" ) ;
52
+ isExpo = true ;
53
+ } catch ( err ) {
54
+ // send error to log file
24
55
}
25
- static recordTelemetry ( eventName , payload = { } ) {
26
- // Skip recording telemetry if the feature is disabled
27
- if ( this . _isDisabled )
28
- return ;
29
- // Do not send the telemetry data if debugging. Users may use this feature
30
- // to preview what data would be sent.
31
- if ( this . _isDebugging ) {
32
- console . log ( `[telemetry] ` + JSON . stringify ( { eventName, payload } , null , 2 ) ) ;
33
- return ;
34
- }
35
- const controller = new AbortController ( ) ;
36
- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , this . _timeout ) ;
37
- payload = { ...payload , ...this . getAnonymousMeta ( ) } ;
38
- fetch ( `${ this . _telemetryUrl } /api/v1/record` , {
39
- method : "PUT" ,
40
- body : JSON . stringify ( { eventName, payload } ) ,
41
- headers : { "content-type" : "application/json" } ,
42
- signal : controller . signal ,
43
- } )
44
- . catch ( ( e ) => console . error ( e ) )
45
- . finally ( ( ) => clearTimeout ( timeoutId ) ) ;
46
- }
47
- static getAnonymousMeta ( ) {
48
- let isExpo = false ;
49
- try {
50
- const myModule = require ( "expo" ) ;
51
- isExpo = true ;
52
- }
53
- catch ( err ) {
54
- // send error to log file
55
- }
56
- try {
57
- const traits = {
58
- // expo
59
- isExpo :
60
- // @ts -ignore
61
- Boolean ( window ?. expo ) || false ,
62
- sdkVersion :
63
- // @ts -ignore
64
- window ?. expo ?. modules ?. ExponentConstants ?. sdkVersion || undefined ,
65
- androidPackage :
66
- // @ts -ignore
67
- window ?. expo ?. modules ?. ExponentConstants ?. android ?. package ||
68
- undefined ,
69
- iosBundleIdentifier :
70
- // @ts -ignore
71
- window ?. expo ?. modules ?. ExponentConstants ?. ios ?. bundleIdentifier ||
72
- undefined ,
73
- expoDebugMode :
74
- // @ts -ignore
75
- window ?. expo ?. modules ?. ExponentConstants ?. debugMode || undefined ,
76
- isDevice :
77
- // @ts -ignore
78
- window ?. expo ?. modules ?. ExponentConstants ?. isDevice || undefined ,
79
- // library version
80
- viroVersion : ViroVersion_1 . VIRO_VERSION ,
81
- platform : react_native_1 . Platform . OS ,
82
- deviceOsVersion : react_native_1 . Platform . Version ,
83
- reactNativeVersion : react_native_1 . Platform . constants . reactNativeVersion . major +
84
- "." +
85
- react_native_1 . Platform . constants . reactNativeVersion . minor +
86
- "." +
87
- react_native_1 . Platform . constants . reactNativeVersion . patch ,
88
- } ;
89
- return traits ;
90
- }
91
- catch ( e ) {
92
- console . error ( e ) ;
93
- }
94
- return { } ;
56
+ try {
57
+ const traits = {
58
+ // expo
59
+ isExpo :
60
+ // @ts -ignore
61
+ Boolean ( window ?. expo ) || false ,
62
+ sdkVersion :
63
+ // @ts -ignore
64
+ window ?. expo ?. modules ?. ExponentConstants ?. sdkVersion || undefined ,
65
+ androidPackage :
66
+ // @ts -ignore
67
+ window ?. expo ?. modules ?. ExponentConstants ?. android ?. package ||
68
+ undefined ,
69
+ iosBundleIdentifier :
70
+ // @ts -ignore
71
+ window ?. expo ?. modules ?. ExponentConstants ?. ios ?. bundleIdentifier ||
72
+ undefined ,
73
+ expoDebugMode :
74
+ // @ts -ignore
75
+ window ?. expo ?. modules ?. ExponentConstants ?. debugMode || undefined ,
76
+ isDevice :
77
+ // @ts -ignore
78
+ window ?. expo ?. modules ?. ExponentConstants ?. isDevice || undefined ,
79
+ // library version
80
+ viroVersion : ViroVersion_1 . VIRO_VERSION ,
81
+ platform : react_native_1 . Platform . OS ,
82
+ deviceOsVersion : react_native_1 . Platform . Version ,
83
+ reactNativeVersion :
84
+ react_native_1 . Platform . constants . reactNativeVersion . major +
85
+ "." +
86
+ react_native_1 . Platform . constants . reactNativeVersion . minor +
87
+ "." +
88
+ react_native_1 . Platform . constants . reactNativeVersion . patch ,
89
+ } ;
90
+ return traits ;
91
+ } catch ( e ) {
92
+ console . error ( e ) ;
95
93
}
94
+ return { } ;
95
+ }
96
96
}
97
97
exports . ViroTelemetry = ViroTelemetry ;
0 commit comments