Interstitial Integration for Unity - MADU DRAFT
Step 1.Create interstitial and register to events
Create an ad unit using the relevant Ad Unit ID, as defined in the LevelPlay platform (learn more here). Set the interstitial listener for the interstitial ad unit created, to get informed of ad delivery.
It’s recommended to create and load the ad unit only after receiving OnInitSuccess callback.
// Create interstitial Ad
interstitialAd = new LevelPlayInterstitialAd(adUnitId);
// Register to events
// Provided when the ad is successfully loaded
interstitialAd.OnAdLoaded += OnAdLoaded;
// Provided when the ad fails to load. Ad Unit information is included
interstitialAd.OnAdLoadFailed += OnAdLoadFailed;
// Provided when the ad is displayed. This is equivalent to an impression
interstitialAd.OnAdDisplayed += OnAdDisplayed;
// Provided when the ad is closed
interstitialAd.OnAdClosed += OnAdClosed;
// Optional - Provided when the ad fails to be displayed
interstitialAd.OnAdDisplayFailed += OnAdDisplayFailed;
// Optional - Provided when the user clicks on the ad
interstitialAd.OnAdClicked += OnAdClicked;
// Optional - Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate
interstitialAd.OnAdInfoChanged += OnAdInfoChanged;
- Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from ironSource callbacks need to be passed to the main thread before executing.
- Make sure to set the listeners before SDK initialization. This will ensure the SDK sends all relevant information.
- The creation of the ad unit object, should be done after receiving onInitSucess callback
LevelPlay Ad Info
The LevelPlay Ad Info is created once an ad was loaded successfully, and is returned as part of all callbacks. Learn more about the LevelPlayAdInfo object and implementation here.
Step 2. Load Interstitial Ad
We recommend requesting an interstitial ad after receiving the init success callback. To request an interstitial ad, call the following method:
interstitialAd.LoadAd();
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, and AdClosed callback is received, you can load another ad. 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() &&!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}");
}
}
Done!
You can now deliver LevelPlay Interstitial Ads through the Interstitial Mediation platform!
Follow our integration guides to integrate additional Interstitial Ad networks or configure additional Ad Units:
- Mediating ad networks
- Rewarded Ad
- Banner Ad