AWS Mobile Analytics

时间:2016-06-29 13:25:57

标签: android cordova amazon-web-services amazon-mobile-analytics

我已使用我的应用程序的仪表板中定义的说明在cordova应用程序中添加了AWS Mobile Analytics。

<script type="text/javascript" src="js/aws-sdk.min.js"></script>
<script type="text/javascript" src="js/aws-sdk-mobile-analytics.min.js"></script>

document.addEventListener("deviceready", function(){
setUpAWSMobileAnalytics();
        }, false);

function setUpAWSMobileAnalytics()
    {
        console.log("SET UP AWS **********");
            AWS.config.region = 'us-east-1';
            AWS.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: 'MY_APP_COGNITO_IDENTITY_POOL_ID' //Amazon Cognito Identity Pool ID
     });


            var options = {
                    appId : 'MY_APP_AMAZON_MOBILE_ANALYTICS_APP_ID', //Amazon Mobile Analytics App ID
                    appTitle : 'APP_TITLE'
                };

            var mobileAnalyticsClient = new AMA.Manager(options);

            mobileAnalyticsClient.recordEvent('CUSTOM_EVENT', {
                                                        'ATTRIBUTE_1_NAME': 'APP_USAGE'
                                                        }, {
                                                        'METRIC_1_NAME': 1
                                                        });
              mobileAnalyticsClient.submitEvents();

        console.log("SET UP AWS END **********");

    }

两个日志都打印在控制台上,之后我就遇到了问题:

Failed to load resource: the server responded with a status of 404 (Not Found) https://cognito-identity.us-east-1.amazonaws.com/

相同的代码适用于iOS并记录事件,但对于Android,尚未记录任何事件。

1 个答案:

答案 0 :(得分:0)

听起来它可能是您的CSP(内容安全政策)。

尝试将其添加到您的应用中:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Cordova 5.3.1 Android app can't access the internet

Apache Cordova: Failed to load resource: the server responded with a status of 404 (Not Found)