The YaftaMobile Plugin for Cordova enables developers to quickly integrate YaftaMobile ads into their Cordova apps. The plugin supports android 2.3 or higher.
Run the following command to install the YaftaMobile plugin
$ cordova plugin add https://github.com/MustamaraLabs/yaftamobile-cordova-plugin.git --variable APP_ID="your-app-id"
To display banner ads in your app use the showBanner(adSize, bannerPositionn, refreshRate)
method where:
FLEXIBLE
, S300X50
, S320X50
, S468X60
, S728X90
TOP_CENTER
, TOP_LEFT
, TOP_RIGHT
, BOTTOM_CENTER
, BOTTOM_LEFT
, BOTTOM_RIGHT
Add the following code to show banner:
YaftaMobile.showBanner(AdSize.FLEXIBLE,
BannerPosition.BOTTOM_CENTER , 60);
Use the following to hide/re-show the banner:
YaftaMobile.pauseBanner(); // hide banner if visible
YaftaMobile.resumeBanner(); // show banner if not visible
To show an interstitial ad you need to load it first using the loadInterstitial()
method, then if loaded successfuly, call the method showInterstitial()
to show the ad on the screen.
You can detect if an interstitial has been loaded and is ready to be displayed by listening to the onInterstitialLoaded event.
Here is sample code showing the two-step process for showing the interstitial ad:
...
//register listener for onInterstitialLoaded event
document.addEventListener(YaftaMobile.Event.onInterstitialLoaded,
app.onInterstitialLoaded, false);
...
// request an interstitial ad
YaftaMobile.loadInterstitial();
.....
// show the interstitial ad
onInterstitialLoaded: function ()
{
YaftaMobile.showInterstitial();
}
The YaftaMobile SDK emits events that let you know what happens during the ad life-cycle. To listen to ad events, you need to register for them using the document.addEventListener()
method
The available ad events to listen to are listed below:
Event :{
//Fired when an ad is successfully loaded.
onAdLoaded: "onAdLoaded",
//Fired when an ad is clicked.
onAdClicked: "onAdClicked",
//Fired when a failure occurred during ad loading.
onAdError: "onAdError",
//Fired when an interstitial ad is loaded.
onInterstitialLoaded: "onInterstitialLoaded",
//Fired when an interstitial ad is clicked.
onInterstitialClicked: "onInterstitialClicked",
//Fired when a failure occurred during interstitial ad loading.
onInterstitialError: "onInterstitialError",
//Fired when an interstitial ad is closed.
onInterstitialDismissed: "onInterstitialDismissed"
}
The following code shows how to subscribe to onInterstitialError
event
onDeviceReady: function() {
document.addEventListener(YaftaMobile.Event.onInterstitialError,
app.onInterstitialError, false);
},
onAdError: function (result){
console.log('code: ' + result.errorCode + ' ,msg: '+ result.errorMessage); // print error code and message
}
The Plugin Integration can be tested by enabling test mode to verify that the set up Plugin side has been completed correctly. You can enable test mode using the setTestMode(testMode)
method
Add the following to enable test mode:
YaftaMobile.setTestMode(true);