This guide explains how to transition to the LevelPlay Interstitial APIs (using an ad unit ID) from your current implementation, to load and display interstitial ads.
Prerequisites
- The minimum supported SDK is 8.6.0. You can download the latest SDK here.
- Ensure that you initialize the SDK using LevelPlay Initialization API.
- Find the AdUnitID in LevelPlay dashboard.
Create Interstitial Ad Object
The creation of the interstitial ad object must be performed after receiving the OnInitSuccess callback.
The object is a reusable instance that can handle multiple loads and shows throughout the session. After creation, it should be used to load and show ads for the same ad unit.
For more advanced implementations, you may create multiple interstitial ad objects if necessary.
// Create interstitial ad object interstitialAd = new LevelPlayInterstitialAd(interstitialAdUnitId);
Register to Interstitial Events
Implement the LevelPlayInterstitialAdListener in your code instead of LevelPlayInterstitialListener to get informed of ad delivery.
- It is recommended to set the listener before loading the interstitial ad.
- Each interstitial ad should have its own listener implementation.
- Callbacks run on the main thread.
// Register to interstitial events interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent; interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent; interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent; interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent; interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent; interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent; interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent; // Implement the events void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo){} void InterstitialOnAdLoadFailedEvent(LevelPlayAdError error){} void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo){} void InterstitialOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError infoError){} void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo){} void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo){} void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo){}
Legacy | Ad Unit (new) | |
---|---|---|
Listener | IronSourceInterstitialEvents | LevelPlayInterstitialAdListener |
Callbacks | OnAdReady | OnAdLoaded |
OnAdLoadFailed | OnAdLoadFailed | |
OnAdOpened | OnAdDisplayed | |
OnAdClosed | OnAdClosed | |
OnAdShowFailed | OnAdDisplayFailed | |
OnAdClicked | OnAdClicked | |
OnAdShowSucceeded | - (deprecated) | |
- | OnAdInfoChanged |
LevelPlay Ad Info
The AdInfo class returned by the interstitial listener callbacks has been replaced by LevelPlayAdInfo.
Learn more about its implementation and available fields here.
Load Interstitial Ad
To load an interstitial ad, use LoadAd instead of LoadInterstitial.
// Load interstitial ad interstitialAd.LoadAd();
Show Interstitial Ad
Show an interstitial ad after you receive the OnAdLoaded callback using the LevelPlayInterstitialAdListener APIs.
- It is required to share Activity.
- If using placements, pass the placement name in the ShowAd API as shown in the Placements section below.
- After the ad has been successfully displayed to the user, you can load another ad by repeating the loading step.
// Show ad without placement interstitialAd.ShowAd(); // Show ad with placement interstitialAd.ShowAd(placementName: "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 (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName)) { interstitialAd.ShowAd(placementName); }
Placements
We support placements pacing and capping for interstitial on the LevelPlay dashboard.
If placements are set up for interstitial ads, call the ShowAd method to serve the ad for a specific placement.
// Check that ad is ready and that the placement is not capped if (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName)) { interstitialAd.ShowAd(placementName); }
Multiple Ad Unit Interstitial APIs
Legacy | Ad Unit (new) | |
---|---|---|
Class | IronSource | LevelPlayInterstitialAd |
API | LoadInterstitial | LoadAd |
ShowInterstitial | ShowAd | |
IsInterstitialPlacementCapped | IsPlacementCapped | |
IsInterstitialReady | IsAdReady |
Full Implementation Example of Interstitial Ads
public class InterstitialAdSample { private LevelPlayInterstitialAd interstitialAd void CreateInterstitialAd() { //Create InterstitialAd instance interstitialAd= new LevelPlayInterstitialAd("interstitialAdUnitId"); //Subscribe InterstitialAd events interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent; interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent; interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent; interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent; interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent; interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent; interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent; } void LoadInterstitialAd() { //Load or reload InterstitialAd interstitialAd.LoadAd(); } void ShowInterstitialAd() { //Show InterstitialAd, check if the ad is ready before showing if (interstitialAd.IsAdReady()) { interstitialAd.ShowAd(); } } void DestroyInterstitialAd() { //Destroy InterstitialAd interstitialAd.DestroyAd(); } //Implement InterstitialAd events void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) { } void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError adInfoError) { } void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo) { } }
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate interstitial Ad Unit APIs in your app.