# Banner Ad

## 1. 기본 요건

* [<mark style="color:blue;">ADX Unity SDK</mark>](/adx/unity/integrate.md)를 프로젝트에 추가합니다.
* Banner Ad용으로 발급받은 ADX Ad Unit ID를 사용합니다.
* 광고를 요청하기 전에 [<mark style="color:blue;">SDK 초기화</mark>](/adx/unity/sdk-integration/initialize.md)를 먼저 진행합니다.
  * **SDK 초기화는 앱 실행 시 한 번만 호출**하여 주시고, **광고 요청은 초기화가 완료된 후**에 이뤄져야 합니다.

## 2. 구현

1. Android와 iOS 모두 배포된 경우 플랫폼 별로 발급받은 Ad Unit ID를 입력합니다.
2. `AdxBannerAd`를 인스턴스화 하고 필요한 콜백을 등록합니다.
3. `Load()` 를 호출하여 광고를 로드합니다.

```csharp
#if UNITY_ANDROID
    string adxBannerAdUnitId = "<ANDROID_ADX_BANNER_AD_UNIT_ID>";
#elif UNITY_IOS
    string adxBannerAdUnitId = "<IOS_ADX_BANNER_AD_UNIT_ID>";
#endif

void LoadBannerAd()
{
    if (bannerAd != null)
    {
        bannerAd.Destroy();
        bannerAd = null;
    }

    bannerAd = new AdxBannerAd(adxBannerAdUnitId, AdxBannerAd.AD_SIZE_320x50, AdxBannerAd.POSITION_TOP);
    bannerAd.OnAdLoaded += BannerAd_OnAdLoaded;
    bannerAd.OnAdFailedToLoad += BannerAd_OnAdFailedToLoad;
    bannerAd.OnAdClicked += BannerAd_OnAdClicked;
    bannerAd.Load();
}
```

배너 광고에서 지원하는 `POSITION`과 `AD_SIZE`는 다음과 같습니다.

```
// -------- 배너 광고 크기 --------
// AdxBannerAd.AD_SIZE_320x50
// AdxBannerAd.AD_SIZE_728x90
// AdxBannerAd.AD_SIZE_320x100
// AdxBannerAd.AD_SIZE_300x250

// -------- 배너 광고 위치 --------
// AdxBannerAd.POSITION_TOP
// AdxBannerAd.POSITION_BOTTOM
// AdxBannerAd.POSITION_TOP_LEFT
// AdxBannerAd.POSITION_TOP_RIGHT
// AdxBannerAd.POSITION_BOTTOM_LEFT
// AdxBannerAd.POSITION_BOTTOM_RIGHT
// AdxBannerAd.POSITION_CENTER
```

## 3. Callback

특정 이벤트를 수신할 수 있습니다. 필요에 따라 구현해주세요.

```csharp
public event Action OnAdLoaded = delegate { };
public event Action<int> OnAdFailedToLoad = delegate { };
public event Action OnAdClicked = delegate { };
public event Action<double> OnPaidEvent = delegate { };
```

## 4. Ad Revenue (OnPaidEvent)

광고 노출에 대한 예상 광고 수익을 확인할 수 있습니다.

{% hint style="info" %}

* 아래 예제와 같이' OnPaidEvent' 콜백을 사용하여 예상되는 eCPM 값을 확인할 수 있습니다.
* 미디에이션 설정 과정에서 수동적으로 설정한 값과 정확한 값이 섞여 있어서 **예상 값으로 사용**하시는 것을 권장드립니다.
* eCPM의 통화(Currency) 단위는 USD입니다.
* 광고 매출 데이터를 MMP와 연동할 수 있습니다. 자세한 사항은 아래 SDK 연동 가이드를 참조해 주십시오.
  * [애드저스트(Adjust)의 AD(X) SDK 연동 가이드](https://dev.adjust.com/ko/sdk/unity/integrations/adx)
  * [에어브릿지(Airbridge)의 AD(X) SDK 연동 가이드](https://help.airbridge.io/ko/developers/ad-x-ad-revenue-integration#sdk-%EC%97%B0%EB%8F%99%ED%95%98%EA%B8%B0-unity)
    {% endhint %}

```csharp
bannerAd.OnPaidEvent += BannerAd_OnPaidEvent;

void BannerAd_OnPaidEvent(double ecpm)
{
   double revenue = ecpm / 1000f;
   
   // Firebase Analytics 샘플
   var impressionParameters = new[] {
    new Firebase.Analytics.Parameter("ad_platform", "AD(X)"),
    new Firebase.Analytics.Parameter("ad_unit_name", "ADX Banner Ad"),
    new Firebase.Analytics.Parameter("ad_format", "BannerAd"),
    new Firebase.Analytics.Parameter("value", revenue),
    new Firebase.Analytics.Parameter("currency", "USD")
   };

   Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", impressionParameters);
   
   // AppsFlyer 샘플
   Dictionary<string, string> dic = new Dictionary<string, string>();
   dic.Add("AdUnitName", "ADX Banner Ad")
   dic.Add("AdType", "BannerAd");

   AppsFlyerAdRevenue.logAdRevenue("AD(X)", AppsFlyerAdRevenueMediationNetworkType.AppsFlyerAdRevenueMediationNetworkTypeCustomMediation, revenue, "USD", dic);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform-business.gitbook.io/adx/unity/sdk-integration/ad-formats/banner-ad.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
