Migrate to banner ad unit API for Unity

Transition to the LevelPlay Banner Ad Units API by initializing the SDK, defining ad formats, and using ad unit IDs for loading and displaying banner ads.

Read time 8 minutes

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.

Prerequisites

  • The min supported SDK is 8.6.0. You can download the latest SDK here.
  • Ensure that you initialize the SDK using LevelPlay Initialization API. Learn more here.
  • Find the AdUnitID in LevelPlay dashboard. Learn more 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);
LegacyAd Unit (new)Dimensions in dp
ISBannerSizeLevelPlayAdSize(Width X Height)
BANNERBANNER320 x 50
LARGELARGE320 x 90
RECTANGLEMEDIUM_RECTANGLE300 x 250
SMARTReplaced 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.
  • 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) {}

LegacyAd Unit (new)
ListenerLevelPlayBannerListenerLevelPlayBannerAd
CallbacksonAdLoadedonAdLoaded
onAdLoadFailedonAdLoadFailed
onAdClickedonAdClicked
onAdScreenPresentedonAdExpanded
onAdScreenDismissedonAdCollapsed
onAdLeftApplicationonAdLeftApplication
onAdDisplayed
onAdDisplayFailed

LevelPlay Ad Info

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. 

  • 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 DestroyAd 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

LegacyAd Unit (new)
ClassIronSourceLevelPlayBannerAd
APIloadBannerLoadAd
destroyBannerDestroyAd
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.

public class BannerAdSample {
    private LevelPlayBannerAd bannerAd;
    void CreateBannerAd() {
        //Create banner instance
        bannerAd = new LevelPlayBannerAd("bannerAdUnitId");
        //Subscribe BannerAd 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;
    }
    void LoadBannerAd() {
        //Load the banner ad 
        bannerAd.LoadAd();
    }
    void ShowBannerAd() {
        //Show the banner ad, call this method only if you turned off the auto show when you created this banner instance.
        bannerAd.ShowAd();
    }
    void HideBannerAd() {
        //Hide banner
        bannerAd.HideAd();
    }
    void DestroyBannerAd() {
        //Destroy banner
        bannerAd.DestroyAd();
    }
    //Implement BannAd 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) {}
}

Done!

You are now all set up to serve banner ads in your application using our new Multiple Ad Unit APIs.