@@ -7,7 +7,7 @@ const os = require('os')
7
7
let mobileAnalyticsClient
8
8
9
9
AWS . config . region = 'us-east-1'
10
- if ( process . env . NODE_ENV === 'production' && ConfigManager . default . get ( ) . amaEnabled ) {
10
+ if ( ! getSendEventCond ( ) ) {
11
11
AWS . config . credentials = new AWS . CognitoIdentityCredentials ( {
12
12
IdentityPoolId : 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx'
13
13
} )
@@ -34,8 +34,15 @@ function convertPlatformName (platformName) {
34
34
}
35
35
}
36
36
37
+ function getSendEventCond ( ) {
38
+ const isDev = process . env . NODE_ENV !== 'production'
39
+ const isDisable = ! ConfigManager . default . get ( ) . amaEnabled
40
+ const isOffline = ! window . navigator . onLine
41
+ return isDev || isDisable || isOffline
42
+ }
43
+
37
44
function initAwsMobileAnalytics ( ) {
38
- if ( process . env . NODE_ENV !== 'production' || ! ConfigManager . default . get ( ) . amaEnabled ) return
45
+ if ( getSendEventCond ( ) ) return
39
46
AWS . config . credentials . get ( ( err ) => {
40
47
if ( ! err ) {
41
48
console . log ( 'Cognito Identity ID: ' + AWS . config . credentials . identityId )
@@ -46,7 +53,7 @@ function initAwsMobileAnalytics () {
46
53
}
47
54
48
55
function recordDynamicCustomEvent ( type , options = { } ) {
49
- if ( process . env . NODE_ENV !== 'production' || ! ConfigManager . default . get ( ) . amaEnabled ) return
56
+ if ( getSendEventCond ( ) ) return
50
57
try {
51
58
mobileAnalyticsClient . recordEvent ( type , options )
52
59
} catch ( analyticsError ) {
@@ -57,7 +64,7 @@ function recordDynamicCustomEvent (type, options = {}) {
57
64
}
58
65
59
66
function recordStaticCustomEvent ( ) {
60
- if ( process . env . NODE_ENV !== 'production' || ! ConfigManager . default . get ( ) . amaEnabled ) return
67
+ if ( getSendEventCond ( ) ) return
61
68
try {
62
69
mobileAnalyticsClient . recordEvent ( 'UI_COLOR_THEME' , {
63
70
uiColorTheme : ConfigManager . default . get ( ) . ui . theme
0 commit comments