Migrate to Banner Ad Units API
This guide explains how to transition to the LevelPlay Banner APIs (using an ad unit ID) from your current implementation, to load and display banner ads.
Create Banner Ad Object and Set Size
The creation of the banner ad object should be done after receiving OnInitSuccess callback.
// Create the banner object and set the ad unit id
bannerAd = new LevelPlayBannerAd(bannerAdUnitId);
Banner Sizes
Legacy |
Ad Unit (new) |
Dimensions in dp |
ISBannerSize | LevelPlayAdSize | (Width X Height) |
BANNER | BANNER | 320 x 50 |
LARGE | LARGE | 320 x 90 |
RECTANGLE | MEDIUM_RECTANGLE | 300 x 250 |
SMART | Replaced by Adaptive Ad Size (see below) | Automatically renders ads to adjust size and orientation for mobile & tablets |
To create the ad size follow one of these options:
Adaptive ad size that adjusts to the screen width (recommended):
This option returns BANNER or LEADERBOARD according to the device type.
Networks that supports adaptive feature (Google, Yandex) will return the a height based on their optimization logic.
LevelPlayAdSize adSize = LevelPlayAdSize.CreateAdaptiveAdSize();
Specific banner size:
This option allows you to set specifically a banner size: BANNER, LARGE, MEDIUM_RECTANGLE.
LevelPlayAdSize adSize = LevelPlayAdSize.BANNER;
Placements
We support placements in banners for reporting only. They should be set before the LoadAd to affect all reloaded ads.
// Set the placement name
LevelPlayBannerAd bannerAd = new LevelPlayBannerAd("bannerAdUnitId", LevelPlayAdSize.BANNER, placementName:"placementName");
Implement Banner Events
Listen to the LevelPlayBannerAd events in your code. The SDK will notify all possible events listed below.
- It is recommended to set the listener before loading the banner ad.
- Please note that each banner ad should have its own listener implementation.
- Callbacks run on the main thread.
// Register to the events
bannerAd.OnAdLoaded += BannerOnAdLoadedEvent;
bannerAd.OnAdLoadFailed += BannerOnAdLoadFailedEvent;
bannerAd.OnAdDisplayed += BannerOnAdDisplayedEvent;
bannerAd.OnAdDisplayFailed += BannerOnAdDisplayFailedEvent;
bannerAd.OnAdClicked += BannerOnAdClickedEvent;
bannerAd.OnAdCollapsed += BannerOnAdCollapsedEvent;
bannerAd.OnAdLeftApplication += BannerOnAdLeftApplicationEvent;
bannerAd.OnAdExpanded += BannerOnAdExpandedEvent;
// Implement the events
void BannerOnAdLoadedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) {}
void BannerOnAdClickedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdDisplayedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError adInfoError) {}
void BannerOnAdCollapsedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdLeftApplicationEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdExpandedEvent(LevelPlayAdInfo adInfo) {}
Legacy | Ad Unit (new) | |
Listener | LevelPlayBannerListener | LevelPlayBannerAd |
Callbacks | onAdLoaded | onAdLoaded |
onAdLoadFailed | onAdLoadFailed | |
onAdClicked | onAdClicked | |
onAdScreenPresented | onAdExpanded | |
onAdScreenDismissed | onAdCollapsed | |
onAdLeftApplication | onAdLeftApplication | |
onAdDisplayed | ||
onAdDisplayFailed |
LevelPlay Ad Info
The LevelPlayAdInfo parameter includes information about the loaded ad.
Learn more about its implementation and available fields here.
Load Banner Ad
To load a banner ad use LoadAd instead of IronSource.loadBanner.
bannerAd.LoadAd();
Pause and Resume Banner Refresh
You can pause banner refresh in your code if the refresh value was defined in the platform. Use the following methods to stop the automatic refresh of the banner ad, or re-enable it after pausing.
When the banner is displayed again, it will complete the time till refresh, from the time it was paused.
- pauseAutoRefresh – pauses auto-refresh of the banner ad.
- resumeAutoRefresh – resumes auto-refresh of the banner ad after it has been paused.
// Pause refresh
bannerAd.PauseAutoRefresh();
// Resume refresh
bannerAd.ResumeAutoRefresh();
Hide and Show Banners
As part of the banner constructor, you can load your banner in the background and share it on screen only when relevant. To control the ad visibility after loading, you can use these APIs:
- ShowAd – banner will be displayed on screen
- HideAd – banner will be hidden
// Show ad
bannerAd.ShowAd();
// Hide ad
bannerAd.HideAd();
Display Cutouts (Android Only)
A display cutout in Android devices is a designated area reserved for essential components such as cameras, sensors, or speakers, commonly used in smartphones and devices with edge-to-edge displays. The cutout can potentially limit the game view, affecting the placement of banners on the screen. To avoid overlap of the banner ad and the displayed cutouts, create LevelPlayBannerAd and set the respectSafeArea to true.
You can learn more about Google’s solution for display cutout here.
To support Android cutouts, create a LevelPlayBannerAd object with the respectSafeArea value as true (default value is false).
bannerAd = new LevelPlayBannerAd(bannerAdUnitId, respectSafeArea:true);
Destroy Banner Ad
To destroy a banner, call the Destroy method instead of IronSource.destroyBanner.
A destroyed banner can no longer be shown again. To display more ads, create a new LevelPlayBannerAd object.
bannerAd.DestroyAd();
Multiple Ad Unit Interstitial APIs
Legacy | Ad Unit (new) | |
Class | IronSource | LevelPlayBannerAd |
API | loadBanner | LoadAd |
destroyBanner | DestroyAd | |
LevelPlayAdSize.Width | ||
– | LevelPlayAdSize.Height | |
– | PauseAutoRefresh | |
– | ResumeAutoRefresh | |
– | ShowAd | |
– | HideAd |
Full Implementation Example of Banner Ads
Here is an example for creating and loading a banner ad using adaptive banner size.
private LevelPlayBannerAd bannerAd;
string bannerAdUnitId = "adUnitId";
LevelPlayAdSize adSize = LevelPlayAdSize.CreateAdaptiveAdSize();
bannerAd = new LevelPlayBannerAd(bannerAdUnitId, adSize);
m_BannerAd = new LevelPlayBannerAd(YOUR_AD_UNIT, adSize, LevelPlayBannerPosition.TopCenter, YOUR_PLACEMENT, false);
// Register to Banner events
bannerAd.OnAdLoaded += BannerOnAdLoadedEvent;
bannerAd.OnAdLoadFailed += BannerOnAdLoadFailedEvent;
bannerAd.OnAdDisplayed += BannerOnAdDisplayedEvent;
bannerAd.OnAdDisplayFailed += BannerOnAdDisplayFailedEvent;
bannerAd.OnAdClicked += BannerOnAdClickedEvent;
bannerAd.OnAdCollapsed += BannerOnAdCollapsedEvent;
bannerAd.OnAdLeftApplication += BannerOnAdLeftApplicationEvent;
bannerAd.OnAdExpanded += BannerOnAdExpandedEvent;
bannerAd.LoadAd();
void BannerOnAdLoadedEvent(LevelPlayAdInfo adInfo)
{
//To get actual banner size(either custom/standard size or adaptive)
LevelPlayAdSize size = adInfo.adSize;
int width = size.Width;
int height = size.Height;
}
void BannerOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) {}
void BannerOnAdClickedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdDisplayedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError adInfoError) {}
void BannerOnAdCollapsedEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdLeftApplicationEvent(LevelPlayAdInfo adInfo) {}
void BannerOnAdExpandedEvent(LevelPlayAdInfo adInfo) {}
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate banner Ad Unit APIs in your app.
Download Unity Demo Application
Done!
You are now all set up to serve banner ads in your application using our new Multiple Ad Unit APIs.