From f54b49db1aee2a98e3d00bf89f273f000ef70cfb Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Tue, 5 Dec 2017 18:23:18 +0900 Subject: [PATCH 1/5] detect internet disconnection --- browser/main/Main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index 3fefdb45..90dbbebf 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -20,7 +20,9 @@ class Main extends React.Component { constructor (props) { super(props) - if (process.env.NODE_ENV === 'production') { + const isOnline = window.navigator.onLine + + if (process.env.NODE_ENV === 'production' && isOnline) { mobileAnalytics.initAwsMobileAnalytics() } From bdb3406dcb6e3c448bf1864701c32acbe5753b28 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Tue, 5 Dec 2017 19:23:49 +0900 Subject: [PATCH 2/5] modify: change the file where detect Internet disconnection --- browser/main/Main.js | 4 +--- browser/main/lib/AwsMobileAnalyticsConfig.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index 90dbbebf..3fefdb45 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -20,9 +20,7 @@ class Main extends React.Component { constructor (props) { super(props) - const isOnline = window.navigator.onLine - - if (process.env.NODE_ENV === 'production' && isOnline) { + if (process.env.NODE_ENV === 'production') { mobileAnalytics.initAwsMobileAnalytics() } diff --git a/browser/main/lib/AwsMobileAnalyticsConfig.js b/browser/main/lib/AwsMobileAnalyticsConfig.js index f10d0b66..e6d028dc 100644 --- a/browser/main/lib/AwsMobileAnalyticsConfig.js +++ b/browser/main/lib/AwsMobileAnalyticsConfig.js @@ -7,7 +7,7 @@ const os = require('os') let mobileAnalyticsClient AWS.config.region = 'us-east-1' -if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled) { +if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled && window.navigator.onLine) { AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx' }) From d09f8dff18878f3b8040e167a2a7141d283d09ad Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Tue, 5 Dec 2017 19:28:42 +0900 Subject: [PATCH 3/5] detect internet connection when send events --- browser/main/lib/AwsMobileAnalyticsConfig.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/browser/main/lib/AwsMobileAnalyticsConfig.js b/browser/main/lib/AwsMobileAnalyticsConfig.js index e6d028dc..4a6c58ad 100644 --- a/browser/main/lib/AwsMobileAnalyticsConfig.js +++ b/browser/main/lib/AwsMobileAnalyticsConfig.js @@ -35,7 +35,7 @@ function convertPlatformName (platformName) { } function initAwsMobileAnalytics () { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return + if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return AWS.config.credentials.get((err) => { if (!err) { console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId) @@ -46,7 +46,7 @@ function initAwsMobileAnalytics () { } function recordDynamicCustomEvent (type, options = {}) { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return + if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return try { mobileAnalyticsClient.recordEvent(type, options) } catch (analyticsError) { @@ -57,7 +57,7 @@ function recordDynamicCustomEvent (type, options = {}) { } function recordStaticCustomEvent () { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return + if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return try { mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', { uiColorTheme: ConfigManager.default.get().ui.theme From b5e2d21f33b9ca1addc94e45ccfde6ae9d70f305 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Tue, 5 Dec 2017 20:54:06 +0900 Subject: [PATCH 4/5] split to function send event conditions --- browser/main/lib/AwsMobileAnalyticsConfig.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/browser/main/lib/AwsMobileAnalyticsConfig.js b/browser/main/lib/AwsMobileAnalyticsConfig.js index 4a6c58ad..a19774f8 100644 --- a/browser/main/lib/AwsMobileAnalyticsConfig.js +++ b/browser/main/lib/AwsMobileAnalyticsConfig.js @@ -34,8 +34,15 @@ function convertPlatformName (platformName) { } } +function getSendEventCond () { + const isDev = process.env.NODE_ENV !== 'production' + const isDisable = !ConfigManager.default.get().amaEnabled + const isOffline = !window.navigator.onLine + return isDev || isDisable || isOffline +} + function initAwsMobileAnalytics () { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return + if (getSendEventCond()) return AWS.config.credentials.get((err) => { if (!err) { console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId) @@ -46,7 +53,7 @@ function initAwsMobileAnalytics () { } function recordDynamicCustomEvent (type, options = {}) { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return + if (getSendEventCond()) return try { mobileAnalyticsClient.recordEvent(type, options) } catch (analyticsError) { @@ -57,7 +64,7 @@ function recordDynamicCustomEvent (type, options = {}) { } function recordStaticCustomEvent () { - if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled || !window.navigator.onLine) return + if (getSendEventCond()) return try { mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', { uiColorTheme: ConfigManager.default.get().ui.theme From a17ddf6d54b64a9f9ee6eb0331ba34a5fd087b16 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 16 Dec 2017 14:25:18 +0900 Subject: [PATCH 5/5] use getSendEventCond func --- browser/main/lib/AwsMobileAnalyticsConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/lib/AwsMobileAnalyticsConfig.js b/browser/main/lib/AwsMobileAnalyticsConfig.js index a19774f8..1ef4f8da 100644 --- a/browser/main/lib/AwsMobileAnalyticsConfig.js +++ b/browser/main/lib/AwsMobileAnalyticsConfig.js @@ -7,7 +7,7 @@ const os = require('os') let mobileAnalyticsClient AWS.config.region = 'us-east-1' -if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled && window.navigator.onLine) { +if (!getSendEventCond()) { AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx' })