Banner Integration for Unity
Banners are a rectangular, system-initiated ads that can be either static or animated, and are served in a designated area around your live app content.
- Make sure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.
- Make sure to initialize the SDK using LevelPlay Initialization API.
- You can find the AdUnitID in LevelPlay dashboard. Learn more here.
- This documentation is relevant for SDK 8.4.0+ (APIs in beta). Documentation for legacy banner APIs can be found here.
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
LevelPlayAdSize | Description | Dimensions in dp (Width X Height) |
BANNER | Standard banner | 320 x 50 |
LARGE | Large banner | 320 x 90 |
MEDIUM_RECTANGLE | Medium Rectangular (MREC) | 300 x 250 |
Adaptive | Automatically renders ads to adjust size and orientation for mobile & tablets |
Device width X recommended height |
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 the 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) {}
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.
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.
A destroyed banner can no longer be shown again. To display more ads, create a new LevelPlayBannerAd object.
bannerAd.DestroyAd();
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 banners in your application. Verify your integration with our Integration Test Suite.
Follow our integration guides to integrate additional Banner Ad networks or configure additional ad formats: