Get Started

The YaftaMobile Unity SDK enables developers to quickly integrate YaftaMobile ads into their Unity applications. The SDK supports android 2.3 or higher.

Step 1: Import the YaftaMobile Unity package into your project.

In the Unity Editor

  1. Select from the menu 'Assets' > Import Package > Custom Package.
  2. Navigate to the directory where you downloaded the YaftaMobile for Unity SDK, select YaftaMobile.unitypackage, and then click Open.
  3. Import all the package's items by pressing "All" and then "Import".

    If you are using a custom AndroidManifest.xml and don't want to override it with the one provided by this package, just uncheck the "AndroidManifest.xml". In this case, you must update the manifest manually as described in the next step.

  4. Drag and drop the YaftaMobileManager.prefab file found at /Assets/Plugins/YaftaMobile/prefabs into your Unity scene in the Scene view.

Step 2: Update AndroidManifest.xml file.

For YaftaMobile to work, you need to make the following changes in the AndroidManifest.xml file.

  • Add Mandatory Permissions INTERNET, ACCESS_NETWORK_STATE
  • Add a 'Meta Data' item called , with a value of your AppID
  • (Required for interstitials) Add Mandatory activity InterstitialActivity
  • Also Add the Google Play services version 'Meta-data' to work properly

Your AndroidManifest.xml file should have the following:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<meta-data android:name=""
android:value="<YOUR-APPID>" />

<activity android:configChanges="keyboard|keyboardHidden|orientation"
android:name="" />

<!-- For Google Play Services (required by YaftaMobile) -->
<meta-data android:name="" 
android:value="@integer/google_play_services_version" />

Showing Banner Ads

To display banner ads in your app use the showBanner(adSize:AdSize, bannerPosition:BannerPosition, refreshRate:int) 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

Before you can use YaftaMobile SDK in your code, you need to add the following namespace declaration:

 using YaftaMobileUnity;

add the following code to show banner:

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 onInterstitialLoadedEvent event.

Here is sample code showing the two-step process for showing the interstitial ad:

void Start () {
   //subscribe for onInterstitialLoadedEvent event
   YaftaMobileManager.onInterstitialLoadedEvent += onInterstitialLoadedEvent;

// request an interstitial ad
// show the interstitial ad
void onInterstitialLoadedEvent(){
  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 subscribe to them using += operator

The available ad events to listen to are listed below:

//Fired when an ad is successfully loaded.
public static event Action onAdLoadedEvent;

//Fired when an ad is clicked.
public static event Action onAdClickedEvent;

//Fired when a failure occurred during ad loading.
public static event Action< int , string> onAdErrorEvent;

//Fired when an interstitial ad is loaded.
public static event Action onInterstitialLoadedEvent;

//Fired when an interstitial ad is clicked.
public static event Action onInterstitialClickedEvent;

//Fired when a failure occurred during interstitial ad loading.
public static event Action< int , string> onInterstitialErrorEvent;

//Fired when an interstitial ad is closed.
public static event Action onInterstitialDismissedEvent;

The following code shows how to subscribe to onInterstitialErrorEvent event

void Start () {
YaftaMobileManager.onInterstitialErrorEvent += onInterstitialErrorEvent;

void onInterstitialErrorEvent(int code,string message){
    Debug.Log ("onInterstitialErrorEvent fired with code: " + code+ " ,and message: "+ message); // print error code and message


Testing the Integration

The SDK Integration can be tested by enabling test mode to verify that the set up SDK side has been completed correctly. You can enable test mode using the setTestMode(boolean testMode) method

Add the following to enable test mode: