Skip to content

Rewarded Ads

Denis edited this page Jul 5, 2021 · 26 revisions

⚡ Before you start
Make sure you have correctly Initialize SDK.

Implementation by UnityEditor | Script C#


Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards.

This guide shows you how to integrate rewarded ads into a Unity app.

For easier ads integration using the Unity Editor, try the new RewardedAdObject.

Load an Ad

By default, the auto-load ads mode is used and a load method does not need to be called.
If you use LoadingManagerMode.Manual then please call load before each show ad.

manager.LoadAd(AdType.Rewarded);

You can get a callback for the successful loading of the ads with using OnLoadedAd event.

Ad Availability

You can ask for the ad availability directly by calling the following function:

bool adLoaded = manager.IsReadyAd(AdType.Rewarded);

Show the Ad

Before displaying a rewarded ad to users, you must present the user with an explicit choice to view rewarded ad content in exchange for a reward. Rewarded ads must always be an opt-in experience.

To display the ad, call the following method with AdType.Rewarded:

manager.ShowAd(AdType.Rewarded);

When you show a rewarded ad, you will subscribe to OnRewardedAdCompleted event to handle reward.

Ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle: loading, opening, closing, and so on. Listen for these events by registering a delegate for the appropriate event, as shown below.

void OnEnable () {
    ...
    // Invoked when the ad is displayed.
    manager.OnRewardedAdShown += () => Debug.Log("Rewarded ad shown");
    // Invoked when the ad is failed to display.
    manager.OnRewardedAdFailedToShow += (error) => Debug.LogError(error);
    // Invoked when the user clicks on an Ad.
    manager.OnRewardedAdClicked += () => Debug.Log("Rewarded ad clicked");
    // Invoked when a user should be rewarded for watching a video. 
    manager.OnRewardedAdCompleted += () => Debug.Log("The user earned the reward.");
    // Executed when the ad is closed.
    manager.OnRewardedAdClosed += () => Debug.Log("Rewarded ad closed");
}

⚠️ Callbacks from CleverAdsSolutions are not guaranteed to be called on Unity thread. Read more about Execute events on Unity Thread.

Allow Interstitial ads

Redirect rewarded video ad impressions to interstitial ads at higher cost per impression or rewarded ad not ready.
Disabled by default.
This option will compare ad cost and serve regular interstitial ads when rewarded video ads are expected to generate less revenue.
Interstitial Ads does not require to watch the video to the end, but the OnRewardedAdCompleted event will be invoked in any case.

Change the flag at any time using the following method:

CAS.MobileAds.settings.allowInterstitialAdsWhenVideoCostAreLower = allow;

Samples


What’s Next?