-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This wiki describes how to integrate plugin as relative path into a cordova app.
After downloading GDApi plugin, place it somewhere in your project so that you can access its path easily.
Inside your cordova app, open a terminal window. To able to add plugin using relative path, command is : cordova plugin add "PATH_WHERE_PLUGIN_LOCATED" (direct path where plugin.xml located).
Open the terminal on cordova project folder and run the command below according to where you put plugin in order to add plugin into the project.
cordova plugin add ~/GDApi
-
cordova.plugins.gdApi.init(["GAME_ID","USER_ID"]);
-
cordova.plugins.gdApi.showBanner();
-
cordova.plugins.gdApi.showPreload(); If there is a preloaded ad, this method show the ad. Otherwise, you ll get events about it.
-
cordova.plugins.gdApi.setAdListener(onEventReceivedCallbackFunction,errorCallbackFunction);
-
cordova.plugins.gdApi.enableTestAds(); If enabled, api will return a test ads.
When you attach onEventReceivedCallbackFunction to listener, this method is invoked with data. This data will contain: "event" , "message" and "adType" (only for banner received event).
"event" parameter contains the name of event.
BANNER_RECEIVED: This event is fired when an ad is received. Also "adType" of data contains the type of ads loaded.
BANNER_STARTED: This event is fired when an ad starts to show up.
BANNER_CLOSED: This event is fired when an ad is closed.
BANNER_FAILED: This event is fired when an ad is failed to load. Also, "message" of data contains why.
API_IS_READY: This event means the api is ready to serve ads. You can invoke "showBanner".
API_NOT_READY: When something goes wrong with the api, this event is invoked. Api is supposed to be init again.
PRELOAD_FAILED: This event is fired when preloaded ad is failed to show. Also, "message" of data contains why.
PRELOAD_COMPLETE: This event is fired when preloaded ad is closed.
PRELOAD_AD: This event is fired when preload ad is received.
//index.js which is an example javascript file handles cordova and our plugin
var app = {
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
onDeviceReady: function() {
this.receivedEvent('deviceready');
},
receivedEvent: function(id) {
var gameId = "853f13d525a54ce79c102a5c46b56715";
var userId= "82B343C2-7535-41F8-A620-C518E96DE8F6-s1";
// cordova.plugins.gdApi.enableTestAds();
// Handling ad events such as "ad received, started, closed"
cordova.plugins.gdApi.setAdListener(this.onBannerEvent,this.error);
// Init also means requesting preroll ad if developer enables it on analytic side.
cordova.plugins.gdApi.init([gameId,userId],this.succes,this.error);
},
succes: function(data){
console.log(data);
},
error: function(data) {
console.log(data);
},
onBannerEvent: function (data) {
switch(data.event){
case 'API_IS_READY':
cordova.plugins.gdApi.showBanner();
break;
case 'PRELOAD_AD':
cordova.plugins.gdApi.showPreload();
break;
}
console.log(JSON.stringify(data));
}
};
app.initialize();
To be able to test , we need to add "GDApi.js" and "index.js" into www/index.html of our cordova project.
//on index.html
//our plugin path on project. It must be put after "cordova.js"
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="plugins\cordova-plugin-gdapi\www\gdApi.js"></script>
<script type="text/javascript" src="js/index.js"></script>