Integration Steps for Cocos2d-x JavaScript Android
Integrate Chocolate Platform SDK into your Cocos2dx project using Javascript
Chocolate Platform SDK Cocos2dx plugin supports the following ad units:
• Full Screen Interstitial
• Rewarded Video
Integration Steps
Step 1:
Download the javascript plugin that you can integrate
Step 2:
Integrate the javascript methods defined in VdopiaPlugin.js to your own javascript. See our code snipets below and refer to VdopiaDemo.js (extracted from Step 1) to see how to load, prefetch, and listen for ad events.
Code snipets
Initialize the plugin
setupVdopiaAd: function () { if (this.VdopiaAd) { console.log("Vdopia Plugin Already Initialized..."); } else { console.log("Vdopia Plugin Not Initialized..."); this.VdopiaAd = require('VdopiaPlugin'); //Init VdopiaPlugin //Set Ad Event Receiver function for listening Vdopia SDK Ad Event this.VdopiaAd.prototype.callbackFunction = this.vdopiaCallback; //Set USER parameter used for better Ad targeting and higher yield (Not Complsory) //Developer can pass empty string for any Param like "" //Param 1 : Age //Param 2 : BirthDate (dd/MM/yyyy) //Param 3 : Gender (m/f/u) //Param 4 : Marital Status (single/married/unknown) //Param 5 : Ethinicty (example : Africans/Asian/Russians) //Param 6 : DMA Code (in String format) //Param 7 : Postal Code (in String format) //Param 8 : Current Postal Code (in String format) //Param 9 : Location latitude in string format //Param 10 : Location longitude in string format this.VdopiaAd.prototype.setAdRequestUserData("23", "23/11/1990", "m", "single", "Asian", "999", "123123", "321321", "28.70", "77.10"); //Set APP parameter used better Ad targeting and higher yield (Not Complsory) //Developer can pass empty string for any Param like "" //Param 1 : App Name //Param 2 : Publisher Name //Param 3 : App Domain //Param 4 : Publisher Domain //Param 5 : PlayStore URL of the App //Param 6 : Ad Category this.VdopiaAd.prototype.setAdRequestAppData("CocosDemo", "Vdopia", "cocos-demo.com", "vdopia.com", "", "IAB1"); //Set Test Mode parameter used for Getting Test AD (Not Complsory) //Param 1 : boolean : true if test mode enabled else false //Param 2 : Hash ID (If you are testing Facebook/Google Partner Test Ad you can get from ADB Logcat) //this.VdopiaAd.prototype.setAdRequestTestMode(true, "XXXXXXXXXXXXXXXX"); /** * Chocolate Init */ this.VdopiaAd.prototype.chocolateInit( YOUR_CHOCOLATE_API_KEY ); } }
Load Interstitial Ad
this.VdopiaAd.prototype.loadInterstitialAd( YOUR_CHOCOLATE_API_KEY );
Load Reward Ad
this.VdopiaAd.prototype.loadRewardAd( YOUR_CHOCOLATE_API_KEY );
Listen for Ad Events and finally showing the ad
vdopiaCallback: function (adType, adEvent) { console.log("Publisher Event : Ad Type : " + adType + " Ad Event : " + adEvent); if (adEvent === VdopiaGlobal.INTERSTITIAL_AD_LOADED) { console.log("Interstitial Ad Loaded..."); //Interstitial ad has been fetched, so let's show it now. this.VdopiaAd.prototype.showInterstitialAd(); /* * OPTIONAL: prefetch the next interstitial ad. */ this.VdopiaAd.prototype.prefetchInterstitialAd( YOUR_CHOCOLATE_API_KEY ); } if (adEvent === VdopiaGlobal.REWARD_AD_LOADED) { console.log("Is Reward Ad Loaded..."); //Reward ad has been fetched, so let's show it now. this.VdopiaAd.prototype.showRewardAd("qj5ebyZ0F0vzW6yg", "Chocolate1", "coin", "30"); /* * OPTIONAL: prefetch the next reward ad. */ this.VdopiaAd.prototype.prefetchRewardAd( YOUR_CHOCOLATE_API_KEY ); } if (adEvent === VdopiaGlobal.REWARD_AD_COMPLETED) { console.log("Is Reward Ad Completed..."); } }
Step 3: Export to Android Studio
When you are done with javascript integration, build the project out to an Android Studio project using Cocos Creator.
Step 4: (big step)
Now, open the Android Studio project. We need to update build.gradle and AndroidManifest.xml in your Android Studio Project:
Carefully follow Steps 1-4 in our general Android Project Setup:
https://chocolateplatform.com/android/?app_dev_framework=android
There is a small section where it talks about including our Cocos2dx plugin.
That’s it.
Sample Code:
We have a cocos2dx javascript sample app for Android:
https://github.com/chocolateplatform/cocos2dx-js-sample