---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://boost.yandex.com/doc/en/ad-monetization/easy/integration/unity/formats/banner.md
  - https://boost.yandex.com/doc/ru/ad-monetization/easy/integration/unity/formats/banner.md
  - href: en/ad-monetization/easy/integration/unity/formats/banner.md
    type: text/markdown
    title: Markdown version
  - href: ../../../../dev/unity/llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://boost.yandex.com/doc/en/llms.txt

# Banner

## Banner types

The Yandex Mobile Ads SDK supports three banner types:

#|
||

**Banner**

|

**Description**

|

**When to use**

||
||

Sticky banner

|

A banner that is pinned to the screen edge and displayed on top of other elements. Banners of this type are unaffected by scrolling.

|

When you want a banner to “stick”, which means to remain in its place and be shown on top of content even if a user scrolls the screen.

||
||

Inline banner

|

A banner that is embedded in your app (for example, in content or a list) as if it's a UI element.

|

When the banner should be part of the page content, appearing in a news feed, between posts, or as a list item.

||
||

Fixed banner

|

A banner that is fixed in a certain place or used for spaces with fixed height.

|

When you need to place a banner in a static location, for example, under a toolbar or at the bottom of the screen.

||
|#

Banners of all types automatically refresh creatives every 60 seconds.

{% note tip %}

To set a custom auto‑refresh period, contact your personal manager.

{% endnote %}

Code-wise, these banners only differ in how you set their sizes. Examples:

{% list tabs %}

- Sticky banners

    ```C#
    BannerAdSize.Sticky(int width)
    ```

- Inline banners

    ```C#
    BannerAdSize.Inline(int width, int maxHeight)
    ```

- Fixed banners

    ```C#
    BannerAdSize.Fixed(int width, int height)
    ```

{% endlist %}


<!-- source: en/ad-monetization/easy/_includes/notes-unity-easy-guide.md -->
{% note info %}

Examples showing how all the format types work are available in the [demo project](https://boost.yandex.com/doc/en/ad-monetization/easy/integration/unity/testing.md#demo).

{% endnote %}
<!-- endsource: en/ad-monetization/easy/_includes/notes-unity-easy-guide.md -->


#|
||

**Entity**

|

**Description**

||
||

`BannerAdSize`

|

The banner height:

- **Mustn't** exceed 15% of the screen height.

- Must be at least 50 **dp/pt** (**Android/iOS**).

All banner sizes must be specified in **dp**.

||
||

`adUnitIdAndroid` /
`adUnitIdiOS`

|

Use:

- **Development mode** to work with [demo ad units](https://boost.yandex.com/doc/en/ad-monetization/easy/integration/unity/testing.md#blocks).

- **Production mode** to work with `R-M-XXXXXX-Y` (for the actual ID, check the Boost interface). `R-M-XXXXXX-Y` is a template for your actual ad unit ID that will be used to receive various creatives.

||
|#


## Example of creating a banner

```C#
using UnityEngine;
using UnityEngine.Events;
using YandexMobileAds;
using YandexMobileAds.Base;
using System;

[AddComponentMenu("Yandex Ads/Banner Component")]
public class BannerComponent : MonoBehaviour
{
    public enum BannerType
    {
        Inline,
        Sticky,
        Fixed
    }

    [Header("Banner Settings")]
    public string bannerName = "Default Banner";
    public BannerType bannerType = BannerType.Inline;

    [Header("Ad Unit IDs")]
    [Tooltip("Ad Unit ID for Android")]
    public string adUnitIdAndroid = "demo-banner-yandex";

    [Tooltip("Ad Unit ID for iOS")]
    public string adUnitIdiOS = "demo-banner-yandex";

    [Header("Banner Configuration")]
    public AdPosition bannerPosition = AdPosition.BottomCenter;
    public bool useScreenWidth = false;
    public int manualWidth = 320;
    public int bannerHeight = 50;
    public bool showAfterLoading = true;

    private Banner banner;

    [System.Serializable]
    public class AdEvent : UnityEvent { }

    [System.Serializable]
    public class AdEventString : UnityEvent<string> { }

    [System.Serializable]
    public class AdEventWithBanner : UnityEvent<Banner> { }

    [Header("Load Callbacks")]
    public AdEventWithBanner OnAdLoaded;
    public AdEventString OnAdFailedToLoad;

    [Header("Interaction Callbacks")]
    public AdEventWithBanner OnAdClicked;
    public AdEventWithBanner OnLeftApplication;
    public AdEventWithBanner OnReturnedToApplication;
    public AdEventString OnImpression;

    [Header("Configure Callbacks")]
    public AdEventWithBanner OnAdConfigured;
    public AdEventString OnAdConfigurationFailed;

    private string currentAdUnitId
    {
        get
        {
#if UNITY_IOS
            return adUnitIdiOS;
#elif UNITY_ANDROID
            return adUnitIdAndroid;
#else
            Debug.LogWarning("Unsupported platform for Yandex Ads. Using IOS Ad Unit ID by default.");
            return adUnitIdAndroid;
#endif
        }
    }

    private void Start()
    {
        if (!string.IsNullOrEmpty(currentAdUnitId))
        {
            this.load();
        }
        else
        {
            Debug.LogError("Banner configuration failed. Ad Unit ID is missing.");
        }
    }

    private void ConfigureBanner()
    {
        int widthDp = useScreenWidth ? ScreenUtils.ConvertPixelsToDp((int)Screen.safeArea.width) : manualWidth;
        BannerAdSize adSize = bannerType == BannerType.Sticky
            ? BannerAdSize.Sticky(widthDp)
            : bannerType == BannerType.Fixed
            ? BannerAdSize.Fixed(widthDp, bannerHeight)
            : BannerAdSize.Inline(widthDp, bannerHeight);

        banner = new Banner(adSize, bannerPosition);

        banner.OnAdLoaded += HandleAdLoaded;
        banner.OnAdFailedToLoad += HandleAdFailedToLoad;
        banner.OnAdClicked += HandleAdClicked;
        banner.OnLeftApplication += HandleLeftApplication;
        banner.OnReturnedToApplication += HandleReturnedToApplication;
        banner.OnImpression += HandleImpression;
    }

    private void load()
    {
        ConfigureBanner();
        banner.LoadAd(new AdRequest(currentAdUnitId));
    }

    public void loadAd()
    {
        this.load();
    }
    
    public void OnDestroy()
    {
        banner.OnAdLoaded -= HandleAdLoaded;
        banner.OnAdFailedToLoad -= HandleAdFailedToLoad;
        banner.OnAdClicked -= HandleAdClicked;
        banner.OnLeftApplication -= HandleLeftApplication;
        banner.OnReturnedToApplication -= HandleReturnedToApplication;
        banner.OnImpression -= HandleImpression;

        banner.Destroy();
        banner = null;
    }

    #region Event Handlers
    private void HandleAdLoaded(object sender, EventArgs args)
    {
        OnAdLoaded?.Invoke(banner);
        if (showAfterLoading)
        {
            banner.Show();
        }
    }

    private void HandleAdFailedToLoad(object sender, AdFailureEventArgs args) => OnAdFailedToLoad?.Invoke(args.Message);
    private void HandleAdClicked(object sender, EventArgs args) => OnAdClicked?.Invoke(banner);
    private void HandleLeftApplication(object sender, EventArgs args) => OnLeftApplication?.Invoke(banner);
    private void HandleReturnedToApplication(object sender, EventArgs args) => OnReturnedToApplication?.Invoke(banner);
    private void HandleImpression(object sender, ImpressionData impressionData) =>
        OnImpression?.Invoke(impressionData?.rawData ?? string.Empty);
    #endregion
}
```



## Checking integration

<!-- source: en/ad-monetization/easy/_includes/notes-unity-easy-guide.md -->
Build and run your project. You can check if the integration is successful by searching the `YandexAds` keyword in **Logcat** in **Android Studio**:
<!-- endsource: en/ad-monetization/easy/_includes/notes-unity-easy-guide.md -->

```
[Integration] Ad type banner was integrated successfully
```
