Skip to content

Banner Ads

Denis edited this page Mar 16, 2021 · 34 revisions

⚡ Before you start
Make sure you have correctly Initialize SDK.


Banner ads are rectangular image or text ads that occupy a spot on screen. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.

This guide shows you how to integrate banner ads from CAS into a Unity app. In addition to code snippets and instructions, it also includes information about sizing banners properly and links to additional resources.

For easier ads integration using the Unity Editor, try the new Ad Placements Beta.

Ad size

Size in dp (WxH) Description Availability CASSize constant
320x50 Standard Banner Phones and Tablets Banner
728x90 IAB Leaderboard Tablets Leaderboard
300x250 IAB Medium Rectangle Phones and Tablets MediumRectangle
Adaptive Adaptive banner Phones and Tablets AdaptiveBanner
320x50 or 728x90 Smart Banner Phones and Tablets SmartBanner

Change the banner size using the following method:

manager.bannerSize = bannerSize;

We do not recommend resizing your banner frequently while playing as this will result in the loss of expensive ad impressions.

Adaptive banners

Adaptive banners are the next generation of responsive ads, maximizing performance by optimizing ad size for each device.
To pick the best ad size, adaptive banners use fixed aspect ratios instead of fixed heights. This results in banner ads that occupy a more consistent portion of the screen across devices and provide opportunities for improved performance. You can read more in this article.

Smart Banners

Typically, Smart Banners on phones have a Banner size. Or on tablets a Leaderboard size.

Load an Ad

By default, the auto-load ads mode is used and a load method does not need to be called.
If you use LoadingManagerMode.Manual then please call load after initialize manager and change banner size.
Also you can use the load for cancel current impression and load next ad.

manager.LoadAd(AdType.Banner);

You can get a callback for the successful loading of the ads with using OnLoadedAd event.

Ad Availability

You can ask for the ad availability directly by calling the following function:

bool bannerLoaded = manager.IsReadyAd(AdType.Banner);

Display the Ad

To show the ad, call the following method with AdType.Banner:

manager.ShowAd(AdType.Banner);

Hide the Ad

To hide Banner Ad from screen, call the following method:

manager.HideBanner();

Ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle: loading, opening, closing, and so on. Listen for these events by registering a delegate for the appropriate event, as shown below.

void OnEnable () {
    ...
    // Executed when the ad is displayed.
    manager.OnBannerAdShown += CASBannerShown;
    // Executed when the ad is failed to display.
    // The Banner may automatically appear when the Ad is ready again.
    // This will trigger the OnBannerAdShown callback again.
    manager.OnBannerAdFailedToShow += CASBannerFailedToShow;
    // Executed when the user clicks on an Ad.
    manager.OnBannerAdClicked += CASBannerClicked;
    // Executed when the ad is hidden from screen.
    manager.OnBannerAdHidden += CASBannerAdHidden;
}

⚠️ Callbacks from CleverAdsSolutions are not guaranteed to be called on Unity thread. Read more about Execute events on Unity Thread.

Ad position

The position where the banner ad should be placed. The CAS.AdPosition enum lists the valid ad position values.
By default, the banner ad is centered at the bottom.
Changing the position of a banner ad does not destroy the current banner and load a new one.

Change the banner position on screen using the following method:

manager.bannerPosition = AdPosition.TopCenter;

Ad Refresh rate

An ad unit’s automatic refresh rate (in seconds) determines how often a new ad request is generated for that ad unit.
We recomended using refresh rate 30 seconds. However, you can choose any value you want longer than 10 seconds.

Ad requests should not be made when the device screen is turned off.

Change the banner automatic refresh rate using the following method:

CAS.MobileAds.settings.bannerRefreshInterval = refreshInterval;

What’s Next?

Clone this wiki locally