Migrate to Rewarded Ad Unit API

This guide explains how to integrate the LevelPlay APIs available to use starting from SDK 8.5.0 (aka LevelPlay APIs), using an ad unit ID as a waterfall identifier, to load and display rewarded ads.

Before you start APIs introduced in this article should be used instead of the integration methods currently in use (ironSource init, ironSource load rewarded, rewarded listeners). You can find the API replacements below.

The advanced settings and regulations settings have not been changed, and they are supported before or after initializing the LevelPlay SDK.

Locate the ad unit ID in the LevelPlay platform

To load and display rewarded ads, you need to use the ad unit ID available in LevelPlay mediation platform:

In your LevelPlay account, navigate to Setup → Ad Units

Copy the rewarded ad unit ID and integrate it into your code

Initializing the ironSource SDK

To initialize the ironSource SDK, follow these steps:

  1. Implement events for initialization success and failure.
  2. Define the list of ad formats to initialize in the session. This should include all the ad formats that you would like to use non multiple ad unit APIs.
  3. Call the LevelPlay init API using the appKey, ad formats, and user ID if relevant.

using com.unity3d.mediation;
// Init the SDK when implementing the Multiple Ad Units API for Interstitial, Banner, and Rewarded 
LevelPlayAdFormat[] legacyAdFormats = new[] { LevelPlayAdFormat.REWARDED };
LevelPlay.OnInitSuccess += SdkInitializationCompletedEvent;
LevelPlay.OnInitFailed += SdkInitializationFailedEvent;
LevelPlay.Init(appKey,legacyAdFormats);

LevelPlay Init Listeners

OnInitSuccess – triggered when the initialization is completed successfully. After you receive this indication, you can create and load the ad.

OnInitFailed – the configuration was not retrieved successfully and ads cannot be loaded. It is recommended to try and initialize the ironSource SDK later (when internet connection is available, or when the failure reason is resolved).

Legacy  Ad Unit (new)
API IronSource.init LevelPlay.Init
Events  onInitializationComplete OnInitSuccess
OnInitFailed

Create Rewarded and Register to Events

Once you receive the OnInitSuccess event,  you can create an ad unit using the relevant Ad Unit ID, as defined in the LevelPlay platform (Initializing the ironSource SDK step).
Set the rewarded listener for the rewarded ad unit created, to get informed of ad delivery.

private LevelPlayRewardedAd rewardedAd;
// Create rewarded Ad
rewardedAd = new LevelPlayRewardedAd(adUnitId);
// Register to events
rewardedAd.OnAdLoaded += OnAdLoaded;
rewardedAd.OnAdLoadFailed += OnAdLoadFailed;
rewardedAd.OnAdDisplayed += OnAdDisplayed;
rewardedAd.OnAdDisplayFailed += OnAdDisplayFailed;
rewardedAd.OnAdRewarded += OnAdRewarded;
rewardedAd.OnAdClosed += OnAdClosed;
// Optional
rewardedAd.OnAdClicked += OnAdClicked;
rewardedAd.OnAdInfoChanged += OnAdInfoChanged;

LevelPlay Rewarded Ad Events

OnAdLoaded – Provided when the ad is successfully loaded.

OnAdLoadFailed – Provided when the ad fails to load. Ad Unit information is included.

OnAdDisplayed – Provided when the ad is displayed. This is equivalent to an impression.

OnAdDisplayFailed – Provided when the ad fails to be displayed.

OnAdRewarded – Provided when the ad is rewarded. Ad Unit info and the reward info are included.

OnAdClicked (optional) – Provided when the user clicks on the ad.

OnAdClosed – Provided when the ad is closed.

OnAdInfoChanged (optional) – Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate.

Legacy Ad Unit (new)
Listener IronSourceRewardedVideoEvents LevelPlayRewardedAd
Events onAdReady OnAdLoaded 
onAdLoadFailed OnAdLoadFailed
onAdOpened OnAdDisplayed
onAdClosed OnAdClosed
onAdShowFailed OnAdDisplayFailed
onAdRewarded OnAdRewarded
onAdClicked OnAdClicked
onAdShowSucceeded – (deprecated)
OnAdInfoChanged

Load Rewarded Ad

Once you receive the OnInitSuccess event, you are ready to load a rewarded ad. This should be done using the method:

// Load or reload the ad
rewardedAd.LoadAd();

Show Rewarded Ad

You can show a rewarded ad after you receive OnAdLoaded event, using the ShowAd APIs.
If you are using placements, share their name as part of the API, as shown below.

// Show ad without placement 
rewardedAd.ShowAd();
// Show ad with placement 
rewardedAd.ShowAd(placementName);

Check Ad is Ready

To avoid show failures, and to make sure the ad could be displayed correctly, we recommend using the following API, before calling the ShowAd API.

IsAdReady – returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.

IsPlacementCapped – returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.

// Check that ad is ready and that the placement is not capped
if (rewardedAd.IsAdReady() && !LevelPlayRewardedAd.IsPlacementCapped(placementName))
{
    rewardedAd.ShowAd(placementName);
}

Once the ad was displayed successfully to the player, you can load another ad, repeating the Load Rewarded Ad step. There is no need to create a new ad entity, when loading a single ad at a time.

Reward the User

The LevelPlay SDK will fire the OnAdRewarded each time the user successfully completes a video.

The OnAdRewarded and OnAdClosed are asynchronous. Make sure to set up your listener to grant rewards even in cases where OnAdRewarded is fired after the OnAdClosed.

// Subscribe to the OnAdRewarded event
ad.OnAdRewarded += (adInfo, reward) => 
{
    // Grant the reward to the user
    Debug.Log($"Ad Completed: {adInfo.PlacementName}, Reward: {reward.Name} - {reward.Amount}");
    GrantReward(reward.Name, reward.Amount);
};
// Example method to process the reward
private void GrantReward(string rewardName, int rewardAmount)
{
    // TODO: Implement logic to grant the reward to the user
    Debug.Log($"Granting reward: {rewardName} with amount: {rewardAmount}");
}

Multiple Ad Unit Rewarded APIs

Legacy Ad Unit (new)
Class IronSource LevelPlayRewardedAd
API loadRewardedVideo LoadAd
showRewardedVideo ShowAd
isRewardedVideoPlacementCapped IsPlacementCapped
isRewardedVideoAvailable IsAdReady
placement.getRewardName reward.Name
placement.getRewardAmount reward.Amount

Full Implementation Example of Rewarded Ad

public class LevelPlaySample : MonoBehaviour
{
    private LevelPlayRewardedAd rewardedAd;
    void CreateRewardedAd(string adUnitId)
    {
        rewardedAd = new LevelPlayRewardedAd(adUnitId);
        rewardedAd.OnAdLoaded += OnAdLoaded;
        rewardedAd.OnAdLoadFailed += OnAdLoadFailed;
        rewardedAd.OnAdDisplayed += OnAdDisplayed;
        rewardedAd.OnAdDisplayFailed += OnAdDisplayFailed;
        rewardedAd.OnAdRewarded += OnAdRewarded;
        rewardedAd.OnAdClicked += OnAdClicked;
        rewardedAd.OnAdClosed += OnAdClosed;
        rewardedAd.OnAdInfoChanged += OnAdInfoChanged;
    }
    void LoadRewardedAd()
    {
        rewardedAd.LoadAd();
    }
    void ShowRewardedAd(string placementName = null)
    {
        if (rewardedAd.IsAdReady() &&!LevelPlayRewardedAd.IsPlacementCapped(placementName))
        {
            rewardedAd.ShowAd(placementName);
        }
    }
    bool CheckIfRewardedAdIsReady()
    {
        return rewardedAd.IsAdReady();
    }
    bool CheckIfPlacementIsCapped(string placementName)
    {
        return LevelPlayRewardedAd.IsPlacementCapped(placementName);
    }
    void OnAdLoaded(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Rewarded ad loaded with ad info {adInfo}");
    }
    void OnAdLoadFailed(LevelPlayAdError adError)
    {
        Debug.Log($"Rewarded ad failed to load with ad error {adError}");
    }
   
    void OnAdDisplayed(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Rewarded ad displayed with ad info {adInfo}");
    }
       
    void OnAdDisplayFailed(LevelPlayAdDisplayInfoError adInfoError)
    {
        Debug.Log($"Rewarded ad failed to display with ad info and error {adInfoError}");
    }
    
    void OnAdRewarded(LevelPlayAdInfo adInfo, LevelPlayReward adReward)
    {
        Debug.Log($"Rewarded ad gained reward with adInfo {adInfo} and reward {adReward}");
    }
    void OnAdClicked(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Rewarded ad clicked with ad info {adInfo}");
    }
    
    void OnAdClosed(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Rewarded ad closed with ad info {adInfo}");
    }
    
    void OnAdInfoChanged(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Rewarded ad info changed with ad info {adInfo}");
    }    
}