【问题标题】:AWS Mobile AnalyticsAWS 移动分析
【发布时间】:2016-06-29 13:25:57
【问题描述】:

我已使用仪表板中为我的应用程序定义的说明在 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,尚未记录任何事件。

【问题讨论】:

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


    【解决方案1】:

    听起来可能是您的 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)

    【讨论】:

    • CSP 已经添加到 html 文件中,但是添加白名单插件就可以了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    相关资源
    最近更新 更多