Implementing banner ads in Unity

Banner ads require a specific type of dedicated Banner Ad Unit.

Note: Starting from SDK version 4.4.1, the Unity Ads package is now called the Advertisement Legacy package in the Unity Editor. The Advertisement Legacy package version 4.4.2 is still functional but will not receive any further updates for new or enhanced features. From SDK versions beyond 4.4.2, only native updates will be supported for Android and iOS developers, with no further updates provided for Unity developers.

Important: app-ads.txt is an IAB initiative to combat fraud and create transparency in the advertising ecosystem. Ensure that you implement app-ads.txt as described. Otherwise, banner demand might significantly decrease.

Script implementation

In your script header, declare the UnityEngine.Advertisements namespace, which contains the Banner class. Next, initialize the SDK, then use the Banner.Load and Banner.Show methods to load and display a banner ad.

The following example script shows you how to set up buttons in a Scene to test this functionality. To create a button in the Unity Editor, select Game Object > UI > Button.

Note: Only load content after the SDK is initialized, otherwise the script will not work. In this example, initialization is handled in a different script.

Implementing banner ads in C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class BannerAdExample : MonoBehaviour
    // For the purpose of this example, these buttons are for functionality testing:
    [SerializeField] Button _loadBannerButton;
    [SerializeField] Button _showBannerButton;
    [SerializeField] Button _hideBannerButton;
    [SerializeField] BannerPosition _bannerPosition = BannerPosition.BOTTOM_CENTER;
    [SerializeField] string _androidAdUnitId = "Banner_Android";
    [SerializeField] string _iOSAdUnitId = "Banner_iOS";
    string _adUnitId = null; // This will remain null for unsupported platforms.
    void Start()
        // Get the Ad Unit ID for the current platform:
        _adUnitId = _iOSAdUnitId;
        _adUnitId = _androidAdUnitId;

        // Disable the button until an ad is ready to show:
        _showBannerButton.interactable = false;
        _hideBannerButton.interactable = false;
        // Set the banner position:
        // Configure the Load Banner button to call the LoadBanner() method when clicked:
        _loadBannerButton.interactable = true;
    // Implement a method to call when the Load Banner button is clicked:
    public void LoadBanner()
        // Set up options to notify the SDK of load events:
        BannerLoadOptions options = new BannerLoadOptions
            loadCallback = OnBannerLoaded,
            errorCallback = OnBannerError
        // Load the Ad Unit with banner content:
        Advertisement.Banner.Load(_adUnitId, options);
    // Implement code to execute when the loadCallback event triggers:
    void OnBannerLoaded()
        Debug.Log("Banner loaded");
        // Configure the Show Banner button to call the ShowBannerAd() method when clicked:
        // Configure the Hide Banner button to call the HideBannerAd() method when clicked:
        // Enable both buttons:
        _showBannerButton.interactable = true;
        _hideBannerButton.interactable = true;     
    // Implement code to execute when the load errorCallback event triggers:
    void OnBannerError(string message)
        Debug.Log($"Banner Error: {message}");
        // Optionally execute additional code, such as attempting to load another ad.
    // Implement a method to call when the Show Banner button is clicked:
    void ShowBannerAd()
        // Set up options to notify the SDK of show events:
        BannerOptions options = new BannerOptions
            clickCallback = OnBannerClicked,
            hideCallback = OnBannerHidden,
            showCallback = OnBannerShown
        // Show the loaded Banner Ad Unit:
        Advertisement.Banner.Show(_adUnitId, options);
    // Implement a method to call when the Hide Banner button is clicked:
    void HideBannerAd()
        // Hide the banner:
    void OnBannerClicked() { }
    void OnBannerShown() { }
    void OnBannerHidden() { }
    void OnDestroy()
        // Clean up the listeners:

By default, banner ads display anchored on the bottom-center of the screen, supporting 320 x 50 or 728 x 90 pixel resolution. To specify the banner anchor, use the Banner.SetPosition API. For example:

Advertisement.Banner.SetPosition (BannerPosition.TOP_CENTER);

Next steps: Review the monetization strategy guide and test your implementation.