Home


Rewarded Ads

Rewarded Ads are usually full-screen video ads which users can view to receive a reward inside the app, like an additional in-game currency or a health bonus for example.

var callback = function(result) {
    if(!result) {
        app.writeLog('Rewarded ad is not ready');
        return;
    }

    // The ad is ready
    var onRewardGranted = function(rewardValue, rewardType) {
        if(rewardType == Enhance.RewardType.ITEM) 
            app.writeLog("Reward granted (item)");

        else if(rewardType == Enhance.RewardType.COINS)
            app.writeLog("Reward granted (coins), value: " + rewardValue);
    };

    var onRewardDeclined = function() {
        app.writeLog('Reward declined');
    };

    var onRewardUnavailable = function() {
        app.writeLog('Reward unavailable');
    };

    Enhance.showRewardedAd(onRewardGranted, onRewardDeclined, onRewardUnavailable);
};

Enhance.isRewardedAdReady(callback);

Methods

Enhance.isRewardedAdReady

void Enhance.isRewardedAdReady(
    Function resultCallback,
    optional String placement = "default"
)

Check if an ad from any of the included SDK providers is ready to be shown.

Parameters:

Function  resultCallback - Specifices the callback function.

optional String  placement - Specifies the internal placement of the ad (from the Enhance mediation editor).

Return Value:

Returns true to the callback function if any ad is ready, false otherwise. When app is not Enhanced, always returns true.

Enhance.showRewardedAd

void Enhance.showRewardedAd(
    Function onRewardGrantedCallback,
    Function onRewardDeclinedCallback,
    Function onRewardUnavailableCallback,
    optional String placement = "default"
)

Display an ad if any is currently available. The ad provider is selected based on your app's mediation settings.

Parameters:

Function  onRewardGrantedCallback - Called when an ad is finished and a reward is granted to the user. As parameters, this function will receive the reward's type as a string (which usually is either "item" or "coins"), and its value as an integer (if applicable, depending on ad network's configuration).

Function  onRewardDeclinedCallback - Called when a reward is declined (e.g. user closed the ad before it finished displaying).

Function  onRewardUnavailableCallback - Called when a reward is unavailable for an unknown reason and cannot be granted.

optional String  placement - Specifies the internal placement of the ad (from the Enhance mediation editor).

String Enhance.RewardType.ITEM

Indicates that the granted reward is a game-defined item.


String Enhance.RewardType.COINS

Indicates that the granted reward is a specific number of coins.