Rewarded Ads - cleveradssolutions/CAS-Unity Wiki

:zap: 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.

Enable Rewarded Ads (Fourth switch) for your game in Assets > CleverAdsSolutions > Settings menu:
image

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);

⚠️ We don’t recommend waiting for IsReadyAd to change in an Update or Coroutine. This method call the native SDK and can affect the performance of your game. Subscribe to the OnLoadedAd event instead.

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.

// Called when the ad is displayed.
manager.OnRewardedAdShown += () => Debug.Log("Rewarded ad shown");
// The same call as the `OnRewardedAdShown` but with `AdMetaData` about the impression. 
manager.OnRewardedAdOpening += (data) => Debug.Log("Rewarded ad " + data.ToString());
// Called when the ad is failed to display.
manager.OnRewardedAdFailedToShow += (error) => Debug.LogError(error);
// Called when the user clicks on the Ad.
manager.OnRewardedAdClicked += () => Debug.Log("Rewarded ad clicked");
// Called when the ad is completed.
manager.OnRewardedAdCompleted += () => Debug.Log("The user earned the reward.");
// Called when the ad is closed.
manager.OnRewardedAdClosed += () => Debug.Log("Rewarded ad closed");

⭐ Read more about event OnRewardedAdOpening with Impression Level Data and AdMetaData.

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

Muted Ads Sounds

Sounds in Interstitial and Rewarded ads mute state. Disabled by default.

CAS.MobileAds.settings.isMutedAdSounds = mute;

Allow Interstitial ads

Sometimes a situation occurs when filling Rewarded ads is not enough, in this case, you can allow the display of Interstitial ads to receiving a reward in any case.
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?