{"_id":"588861fb165af631008ee207","category":{"_id":"588861fa165af631008ee1bf","__v":0,"version":"588861fa165af631008ee1b8","project":"54861bb654b3ce0b00367292","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-21T09:41:28.604Z","from_sync":false,"order":6,"slug":"android-setup","title":"Cordova / Essentials KIt"},"project":"54861bb654b3ce0b00367292","version":{"_id":"588861fa165af631008ee1b8","__v":1,"project":"54861bb654b3ce0b00367292","createdAt":"2017-01-25T08:29:46.061Z","releaseDate":"2017-01-25T08:29:46.061Z","categories":["588861fa165af631008ee1b9","588861fa165af631008ee1ba","588861fa165af631008ee1bb","588861fa165af631008ee1bc","588861fa165af631008ee1bd","588861fa165af631008ee1be","588861fa165af631008ee1bf","588861fa165af631008ee1c0","588861fa165af631008ee1c1","588861fa165af631008ee1c2","588861fa165af631008ee1c3","588861fa165af631008ee1c4","588861fa165af631008ee1c5","588861fa165af631008ee1c6","588861fa165af631008ee1c7","588861fa165af631008ee1c8","588861fa165af631008ee1c9"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.0.0","version":"5.0"},"__v":0,"parentDoc":null,"user":"548d74b716fc980b00e2a786","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-18T17:03:51.723Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":47,"body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var app = {\\n    // Application Constructor\\n    initialize: function() {\\n        this.bindEvents();\\n    },\\n    // Bind Event Listeners\\n    //\\n    // Bind any events that are required on startup. Common events are:\\n    // 'load', 'deviceready', 'offline', and 'online'.\\n    bindEvents: function() {\\n        document.addEventListener('deviceready', this.onDeviceReady, false);\\n    },\\n    // deviceready Event Handler\\n    //\\n    // The scope of 'this' is the event. In order to call the 'receivedEvent'\\n    // function, we must explicitly call 'app.receivedEvent(...);'\\n    onDeviceReady: function() {\\n   \\t\\tapp.receivedEvent('deviceready');\\n      \\n      // basic setup - iOS/android key\\n      window.elasticode.setAndroidApiKey(\\\"<AndroidAPIKey>\\\");\\n      window.elasticode.setIOSApiKey(\\\"<iOSAPIKey>\\\");\\n      \\n      // set actions\\n      window.elasticode.setActions({\\n  \\t\\t\\t\\\"Show video\\\" : function (context){\\n\\t    \\t\\t// video showing logic\\n\\t  \\t\\t}\\n\\t\\t\\t});\\n      \\n      // set 3rd party analytics\\n      window.elasticode.setThirdPartyAnalytics(\\n  \\t\\t\\t\\\"mixpanel\\\", \\n\\t  \\t\\tfunction(eventName){\\n    \\t\\t\\t//console.log(\\\"mixpanel - \\\"+eventName);\\n\\t\\t    \\t//window.mixpanel.track(eventName, {}, function(){}, function(){});\\n  \\t\\t\\t}\\n\\t\\t\\t);\\n      \\n      // onLaunch callback\\n      window.elasticode.setOnLaunchCallback(\\n      \\tfunction(didAppear){ \\n        }\\n      );\\n      window.elasticode.ready();\\n    },\\n    // Update DOM on a Received Event\\n    receivedEvent: function(id) {\\n        var parentElement = document.getElementById(id);\\n        var listeningElement = parentElement.querySelector('.listening');\\n        var receivedElement = parentElement.querySelector('.received');\\n\\n        listeningElement.setAttribute('style', 'display:none;');\\n        receivedElement.setAttribute('style', 'display:block;');\\n\\n        console.log('Received Event: ' + id);\\n    }\\n};\\n\\napp.initialize();\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"integration-example-1","type":"basic","title":"Integration example"}

Integration example


[block:code] { "codes": [ { "code": "var app = {\n // Application Constructor\n initialize: function() {\n this.bindEvents();\n },\n // Bind Event Listeners\n //\n // Bind any events that are required on startup. Common events are:\n // 'load', 'deviceready', 'offline', and 'online'.\n bindEvents: function() {\n document.addEventListener('deviceready', this.onDeviceReady, false);\n },\n // deviceready Event Handler\n //\n // The scope of 'this' is the event. In order to call the 'receivedEvent'\n // function, we must explicitly call 'app.receivedEvent(...);'\n onDeviceReady: function() {\n \t\tapp.receivedEvent('deviceready');\n \n // basic setup - iOS/android key\n window.elasticode.setAndroidApiKey(\"<AndroidAPIKey>\");\n window.elasticode.setIOSApiKey(\"<iOSAPIKey>\");\n \n // set actions\n window.elasticode.setActions({\n \t\t\t\"Show video\" : function (context){\n\t \t\t// video showing logic\n\t \t\t}\n\t\t\t});\n \n // set 3rd party analytics\n window.elasticode.setThirdPartyAnalytics(\n \t\t\t\"mixpanel\", \n\t \t\tfunction(eventName){\n \t\t\t//console.log(\"mixpanel - \"+eventName);\n\t\t \t//window.mixpanel.track(eventName, {}, function(){}, function(){});\n \t\t\t}\n\t\t\t);\n \n // onLaunch callback\n window.elasticode.setOnLaunchCallback(\n \tfunction(didAppear){ \n }\n );\n window.elasticode.ready();\n },\n // Update DOM on a Received Event\n receivedEvent: function(id) {\n var parentElement = document.getElementById(id);\n var listeningElement = parentElement.querySelector('.listening');\n var receivedElement = parentElement.querySelector('.received');\n\n listeningElement.setAttribute('style', 'display:none;');\n receivedElement.setAttribute('style', 'display:block;');\n\n console.log('Received Event: ' + id);\n }\n};\n\napp.initialize();", "language": "javascript" } ] } [/block]