Get Started

The YaftaMobile Plugin for Cordova enables developers to quickly integrate YaftaMobile ads into their Cordova apps. The plugin supports android 2.3 or higher.

Prerequisites

  • Cordova 5.0.0 or higher
  • Latest version of Google Play Services and Google repository must be installed. You can install them by using the Android SDK Manager, they are available under Extras

Step 1: add the YaftaMobile Codova Plugin to your project.

  1. Open command line/terminal.
  2. Navigate to your cordova project directory.
  3. Install YaftaMobile plugin from github using the cordova command-line interface.

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"

Showing Banner Ad

To display banner ads in your app use the showBanner(adSize, bannerPositionn, refreshRate)method where:

  • adSize: is one of the following supported ad sizes : FLEXIBLE, S300X50, S320X50, S468X60, S728X90
  • bannerPosition: is one of the following constants, which specify the location of the banner: TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT
  • refreshRate: is an interval between 30 and 120 seconds.

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

Showing Interstitials

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();
}

Listening to ad events

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
}

Testing the Integration

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