Interstitial Ad Unit’s API

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

Before you start APIs introduced in this article should be used instead of the integration methods currently in use (ironSource init, ironSource load interstitial, interstitial listeners)

There was no change in the APIs supporting rewarded ads, and it should continue to work as is, after SDK initialization

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

Step 1:  Locate the ad unit ID in the LevelPlay platform

To load and display interstitial 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 interstitial’s ad unit ID and integrate it into your code

Step 2: Initializing the ironSource SDK

To initialize the ironSource SDK, follow these steps:

Define the list of ad formats to initialize in the session. This should include all the ad formats that you would like to use in LevelPlay, integrating the ironSource APIs (supported for SDK < 8.1.0).

Implement callbacks for initialization success and failure.

Call LevelPlay init API using the appkey, ad formats, and user ID if relevant.

// Define ad formats which are not part of Multiple Ad Units flow
LevelPlayAdFormat[] legacyAdFormats = { LevelPlayAdFormat.BANNER, LevelPlayAdFormat.REWARDED };
// Define new listeners
LevelPlay.OnInitSuccess += LPInitSuccess;
LevelPlay.OnInitFailed += LPInitFailed;
// Init API
LevelPlay.Init(appKey, userId, 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)

Step 3: Create interstitial and register to events

Once you receive the OnInitSuccess callback,  you can create an ad unit using the relevant Ad Unit ID, as defined in the LevelPlay platform (step #1).
Set the interstitial listener for the interstitial ad unit created, to get informed of ad delivery.

// Create interstitial Ad
interstitialAd = new LevelPlayInterstitialAd(adUnitId);
// Register to events
interstitialAd.OnAdLoaded += OnAdLoaded;
interstitialAd.OnAdLoadFailed += OnAdLoadFailed;
interstitialAd.OnAdDisplayed += OnAdDisplayed;
interstitialAd.OnAdDisplayFailed += OnAdDisplayFailed;
interstitialAd.OnAdClicked += OnAdClicked;
interstitialAd.OnAdClosed += OnAdClosed;
interstitialAd.OnAdInfoChanged += OnAdInfoChanged;

LevelPlay interstitial Listeners

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 (optional) – Provided when the ad fails to be displayed

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

Step 4: Load interstitial ad

Once you receive the OnInitSuccess callback, you are ready to load an interstitial ad. This should be done using the method:

interstitialAd.LoadAd();

Note: For SDK 8.3.0 when calling LoadAd after the ad was already loaded (before displaying it), LevelPlay will not trigger another mediation load. This means that if you want a refreshed ad, you should either show the ad, or destroy the object. This should be changed in SDK 8.4.0.

Step 5: Show interstitial ad

You can show an interstitial ad after you receive onAdLoaded callback, using the showAd APIs.
If you are using placements you should share their name as part of the API, as described below.

// Show interstitial without placement
interstitialAd.ShowAd();
// Show interstitial with placement
interstitialAd.ShowAd(placementName);

Check ad 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 (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName))
{
    interstitialAd.ShowAd(placementName);
}

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

Implementation example

public class LevelPlaySample : MonoBehaviour
{
    private LevelPlayInterstitialAd interstitialAd;void CreateInterstitialAd(string adUnitId)
    {
        interstitialAd = new LevelPlayInterstitialAd(adUnitId);
        interstitialAd.OnAdLoaded += OnAdLoaded;
        interstitialAd.OnAdLoadFailed += OnAdLoadFailed;
        interstitialAd.OnAdDisplayed += OnAdDisplayed;
        interstitialAd.OnAdDisplayFailed += OnAdDisplayFailed;
        interstitialAd.OnAdClicked += OnAdClicked;
        interstitialAd.OnAdClosed += OnAdClosed;
        interstitialAd.OnAdInfoChanged += OnAdInfoChanged;
}

    void LoadInterstitialAd()
    {
        interstitialAd.LoadAd();
    }

    void ShowInterstitialAd(string placementName = null)
    {
        if (interstitialAd.IsAdReady() &&amp!LevelPlayInterstitialAd.IsPlacementCapped(placementName))
        {
            interstitialAd.ShowAd(placementName);
        }
    }

    bool CheckIfInterstitialAdIsReady()
    {
        return interstitialAd.IsAdReady();
    }

    bool CheckIfPlacementIsCapped(string placementName)
    {
        return LevelPlayInterstitialAd.IsPlacementCapped(placementName);
    }

    void OnAdLoaded(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Interstitial ad loaded with ad info {adInfo}");
    }

    void OnAdLoadFailed(LevelPlayAdError adError)
    {
        Debug.Log($"Interstitial ad failed to load with ad error {adError}");
    }
   
    void OnAdDisplayed(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Interstitial ad displayed with ad info {adInfo}");
    }
       
    void OnAdDisplayFailed(LevelPlayAdDisplayInfoError adInfoError)
    {
        Debug.Log($"Interstitial ad failed to display with ad infoError {adInfoError}");
    }
    
    void OnAdClicked(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Interstitial ad clicked with ad info {adInfo}");
    }
    
    void OnAdClosed(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Interstitial ad closed with ad info {adInfo}");
    }
    
    void OnAdInfoChanged(LevelPlayAdInfo adInfo)
    {
        Debug.Log($"Interstitial ad info changed with ad info {adInfo}");
    }    
}

LevelPlay Ad Info

Ad Info

Learn more about LevelPlay Ad Info implementation and available fields  here.