Search code examples
androidcordovaamazon-web-servicesamazon-mobile-analytics

AWS Mobile Analytics


I have added AWS Mobile Analytics in cordova app using the instructions defined in the Dashboard for my app.

<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 **********");

    }

Both the logs are printed on the console and after that I am getting the issue :

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

The same code is working for iOS and events are recorded, but for Android, no event is recorded yet.


Solution

  • Sounds like it could be your CSP (Content-Security-Policy).

    Try adding it to your app with:

    <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)