Skip to content

Commit b4b6d3d

Browse files
authored
Merge pull request #1243 from BoostIO/detect-AMA-errors
Detect ama errors
2 parents 9007bac + a17ddf6 commit b4b6d3d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

browser/main/lib/AwsMobileAnalyticsConfig.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const os = require('os')
77
let mobileAnalyticsClient
88

99
AWS.config.region = 'us-east-1'
10-
if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled) {
10+
if (!getSendEventCond()) {
1111
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
1212
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx'
1313
})
@@ -34,8 +34,15 @@ function convertPlatformName (platformName) {
3434
}
3535
}
3636

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+
3744
function initAwsMobileAnalytics () {
38-
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
45+
if (getSendEventCond()) return
3946
AWS.config.credentials.get((err) => {
4047
if (!err) {
4148
console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId)
@@ -46,7 +53,7 @@ function initAwsMobileAnalytics () {
4653
}
4754

4855
function recordDynamicCustomEvent (type, options = {}) {
49-
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
56+
if (getSendEventCond()) return
5057
try {
5158
mobileAnalyticsClient.recordEvent(type, options)
5259
} catch (analyticsError) {
@@ -57,7 +64,7 @@ function recordDynamicCustomEvent (type, options = {}) {
5764
}
5865

5966
function recordStaticCustomEvent () {
60-
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
67+
if (getSendEventCond()) return
6168
try {
6269
mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', {
6370
uiColorTheme: ConfigManager.default.get().ui.theme

0 commit comments

Comments
 (0)