Interstitial Integration for Android - MADU DRAFT
The Unity LevelPlay Interstitial is a full-screen ad unit, usually served at natural transition points during the app lifecycle. We support both static and video interstitials. You can also serve interstitials through the Unity LevelPlay Mediation.
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.
mInterstitialAd = new LevelPlayInterstitialAd("adUnitId");
mInterstitialAd.setListener(this);
// LevelPlayInterstitialAdListener methods
// Provided when the ad is successfully loaded
@Override
public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {}
// Provided when the ad fails to load. Ad Unit information is included
@Override
public void onAdLoadFailed(@NonNull LevelPlayAdError error) {}
// Provided when the ad is displayed. This is equivalent to an impression
@Override
public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {}
// Provided when the ad is closed
@Override public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {}
// Optional - Provided when the ad fails to be displayed
@Override
public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {}
// Optional - Provided when the user clicks on the ad
@Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {}
// Optional - Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate
@Override
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {}
mInterstitialAd = new LevelPlayInterstitialAd("adUnitId");
mInterstitialAd.setListener(this);
// LevelPlayInterstitialAdListener methods:
// Provided when the ad is successfully loaded
override fun onAdLoaded(adInfo: LevelPlayAdInfo) {}
// Provided when the ad fails to load. Ad Unit information is included
override fun onAdLoadFailed(error: LevelPlayAdError) {}
// Provided when the ad is displayed. This is equivalent to an impression
override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {}
// Provided when the ad is closedÂ
override fun onAdClosed(adInfo: LevelPlayAdInfo) {}
// Optional - Provided when the ad fails to be displayed
override fun onAdDisplayFailed(error: LevelPlayAdError, adInfo: LevelPlayAdInfo) {}
// Optional - Provided when the user clicks on the ad
override fun onAdClicked(adInfo: LevelPlayAdInfo) {}
// Optional - Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate
override fun onAdInfoChanged(adInfo: LevelPlayAdInfo) {}
- 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:
// Load or reload the ad
mInterstitialAd.loadAd();
// Load or reload the ad
mInterstitialAd.loadAd()
Step 3. Show Interstitial Ad
You can show an interstitial ad after you receive onAdLoaded callback, using the showAd APIs.
Using this API you are required to share Activity. If you are using placements you should share their name as part of the API, as described below.
// Show ad without placement
mInterstitialAd.showAd(this);
// Show ad with placement
mInterstitialAd.showAd(this, placementName);
// Show ad without placement
mInterstitialAd.showAd(this)
// Show ad with placement
mInterstitialAd.showAd(this, 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(mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) {
mInterstitialAd.showAd(this, placementName);
}
// check that ad is ready and that the placement is not capped
if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) {
mInterstitialAd.showAd(this, 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 InterstitialAdActivity extends Activity
implements LevelPlayInterstitialAdListener
{
private LevelPlayInterstitialAd mInterstitialAd;
void createInterstitialAd() {
mInterstitialAd = new LevelPlayInterstitialAd("adUnitId");
mInterstitialAd.setListener(this);
}
void loadInterstitialAd() {
// used to load or reload the ad
mInterstitialAd.loadAd();
}
void showInterstitialAd() {
if(mInterstitialAd.isAdReady()) {
mInterstitialAd.showAd(this);
}
}
void showInterstitialAd(@NonNull String placmentName) {
// check that ad is ready and that the placement is not capped
if(mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) {
mInterstitialAd.showAd(this, placementName);
}
}
// LevelPlayInterstitialAdListener methods
@Override
public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdLoadFailed(@NonNull LevelPlayAdError error) {}
@Override
public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {}
@Override
public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {}
}
class InterstitialAdActivity : Activity(), LevelPlayInterstitialAdListener {
private lateinit var mInterstitialAd: LevelPlayInterstitialAd
fun createInterstitialAd() {
mInterstitialAd = LevelPlayInterstitialAd("adUnitId")
mInterstitialAd.setListener(this)
}
fun loadInterstitialAd() {
mInterstitialAd.loadAd()
}
fun showInterstitialAd() {
if (mInterstitialAd.isAdReady()) {
mInterstitialAd.showAd(this)
}
}
fun showInterstitialAd(placementName: String) {
// check that ad is ready and that the placement is not capped
if (mInterstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped(placementName)) {
mInterstitialAd.showAd(this, placementName)
}
}
// LevelPlayInterstitialAdListener methods
override fun onAdLoaded(adInfo: LevelPlayAdInfo) {}
override fun onAdLoadFailed(error: LevelPlayAdError) {}
override fun onAdInfoChanged(adInfo: LevelPlayAdInfo) {}
override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {}
override fun onAdDisplayFailed(error: LevelPlayAdError, adInfo: LevelPlayAdInfo) {}
override fun onAdClicked(adInfo: LevelPlayAdInfo) {}
override fun onAdClosed(adInfo: LevelPlayAdInfo) {}
}
Done!
You can now deliver Interstitial Ads on your app!
Follow our integration guides to integrate additional Interstitial Ad networks or configure additional Ad Units:
- Mediating ad networks
- Rewarded Ad
- Banner Ad