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.

function show_ad()
    if enhance.isRewardedAdReady() then
        enhance.showRewardedAd(on_reward_granted, on_reward_declined, on_reward_unavailable)
    end
end

function on_reward_granted(self, reward_value, reward_type)
    if reward_type == "REWARDTYPE_ITEM" then
        write_log("Reward granted (item)")

    elseif reward_type == "REWARDTYPE_COINS" then
        write_log("Reward granted (coins), value: " .. reward_value)
    end
end

function on_reward_declined()
    write_log("Reward declined")
end

function on_reward_unavailable()
    write_log("Reward unavailable")
end

Methods

enhance.isRewardedAdReady

boolean enhance.isRewardedAdReady(
    optional string placement = "default"
)

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

Parameters:

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

Return Value:

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

enhance.showRewardedAd

nil enhance.showRewardedAd(
    optional string placement = "default",
    function onRewardGrantedCallback,
    function onRewardDeclinedCallback,
    function onRewardUnavailableCallback
)

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

Parameters:

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

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, and its value as an integer (if applicable, depending on ad network's configuration). The type is either equal to "REWARDTYPE_ITEM" or "REWARDTYPE_COINS".

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.