From 2fea9eb874a4b01cfb87596b76e88530c9b8ab66 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 31 May 2017 22:28:58 +0900 Subject: [PATCH] setting AMA custom events --- browser/main/lib/AwsMobileAnalyticsConfig.js | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 browser/main/lib/AwsMobileAnalyticsConfig.js diff --git a/browser/main/lib/AwsMobileAnalyticsConfig.js b/browser/main/lib/AwsMobileAnalyticsConfig.js new file mode 100644 index 00000000..8d75f5fd --- /dev/null +++ b/browser/main/lib/AwsMobileAnalyticsConfig.js @@ -0,0 +1,36 @@ +const AWS = require('aws-sdk') +const AMA = require('aws-sdk-mobile-analytics') +const ConfigManager = require('browser/main/lib/ConfigManager') + +AWS.config.region = 'us-east-1' +AWS.config.credentials = new AWS.CognitoIdentityCredentials({ + IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx' +}) +const mobileAnalyticsClient = new AMA.Manager({ + appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx', + appTitle: 'xxxxxxxxxx' +}) + +function initAwsMobileAnalytics () { + AWS.config.credentials.get(function(err) { + if (!err) { + console.log("Cognito Identity ID: " + AWS.config.credentials.identityId) + } + }) + recordStaticCustomEvent() +} + +function recordDynamitCustomEvent (type) { + mobileAnalyticsClient.recordEvent(type) +} + +function recordStaticCustomEvent () { + mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', { + uiColorTheme: ConfigManager.default.get().ui.theme + }) +} + +module.exports = { + initAwsMobileAnalytics, + recordDynamitCustomEvent +}