To get advertisement placement reward a contract is required:

Interstitial ads are fullscreen ads for Android platform that can be shown between game activities.

These ads are shown as soon as a specific API method is called. For a rewarded type of ads where you first find an ad and only then show it to user, please refer to this page.

Set up

To enable this feature you need to:

  1. check of your app is opened in an iframe on our mobile platforms. If it’s still opened as an external page you can request us to enable iframe-launch for your app by sending a request to this e-mail api-support@ok.ru. Otherwise you can check old version of ads API here

  2. request us to enable FAPI support for your mobile app via this e-mail - api-support@ok.ru.

After iframe and FAPI are enabled for your app you can import FAPI SDK like this:

<script type="text/javascript" src="//api.ok.ru/js/fapi5.js" defer="defer"></script>

Then you should define a global callback function API-callback. In example:

window.API_callback = function(method, result, data) {
   console.log("method=" + method + ", result=" + result + ", data=" + data);
};

Checking for ads availability

Before showing an ad you need to check if this feature is available.

FAPI.UI.isNativeAdSupported() is used for this.

Example usage:

/*
* Ads availability check
*/
function isAdsEnabled() {
    if (FAPI && FAPI.UI.isNativeAdSupported) {
        return FAPI.UI.isNativeAdSupported();
    }
}

Result is a boolean:

  • false - if ads are not available;
  • true - if ads are available.

Showing an ad

If ads are available you can show them to user.

FAPI.UI.showAd() is used to show an ad.

Example usage:

/*
* Show in-app ad via OKAndroidSDK
*/
function requestAds() {
    if (FAPI && FAPI.UI.showAd) {
        FAPI.UI.showAd();
    }
}

Callback function

As all other FAPI-methods global FAPI-callback function is invoked when an ad is requested - API_callback(method, result, data).

Depending on a result following parameters can be passed to it:

  • if there are no ads for current user:
    • method = showAd;
    • result = error;
    • data = no_ads;
  • ad is found and is ready to be shown:
    • method = showAd;
    • result = event;
    • data = ad_prepared;
  • ad is successfully shown:
    • method = showAd;
    • result = ok;
    • data = ad_shown;
  • an error occurred on method invocation:
    • method = showAd;
    • result = error;
    • data = native ads failed.

Test application

You can view how this ads work in our test application. This app is available by a following link http://m.ok.ru/game/inappadstest

To test this type of ads you need to:

  • to show an ad - press show interstitial ad button.