> ## Documentation Index
> Fetch the complete documentation index at: https://guide.daro.so/llms.txt
> Use this file to discover all available pages before exploring further.

# 앱 오픈 광고

> Unity 프로젝트에서 DARO 앱 오픈 광고를 구현하는 방법을 알아봅니다.

## 앱 오픈 광고 형태 소개

* 앱이 백그라운드에서 포그라운드로 돌아올 때 노출하는 화면 전체를 사용하는 광고입니다.
* 첫 실행 직후가 아니라, 앱 복귀 시점에 노출하는 것을 권장합니다.

![앱 오프닝 광고 예시](https://mintcdn.com/delightroom-5a71a6a8/j3-znW7LKrbpP3mb/sdk-integration/android/ad-formats/img/appopen-ad-example.png?fit=max\&auto=format\&n=j3-znW7LKrbpP3mb\&q=85\&s=1b3c49ed5723727ee8e5311ef9a3fc05)

***

## 광고 연동하기

**1. 광고 인스턴스 생성**

```csharp theme={null}
private DaroAppOpenAd ad;

ad = new DaroAppOpenAd("your-appopen-ad-unit-key");
```

**2. 이벤트 핸들러 등록**

```csharp theme={null}
ad.OnAdLoaded += info => Debug.Log("app open loaded");
ad.OnAdFailedToLoad += error => Debug.LogWarning(error.Message);
ad.OnAdFailedToShow += error => Debug.LogWarning(error.Message);
```

**3. 앱 상태 변경 구독**

```csharp theme={null}
DaroAppStateNotifier.OnAppStateChanged += OnAppStateChanged;
```

**4. 포그라운드 복귀 시 광고 표시**

```csharp theme={null}
private void OnAppStateChanged(DaroAppStateNotifier.AppState state)
{
    if (state == DaroAppStateNotifier.AppState.Foreground
        && ad != null
        && ad.IsReady())
    {
        ad.Show();
    }
}
```

**5. 구독 해제 및 광고 해제**

```csharp theme={null}
DaroAppStateNotifier.OnAppStateChanged -= OnAppStateChanged;
ad?.Dispose();
ad = null;
```

***

## Example

```csharp expandable theme={null}
using Daro;
using UnityEngine;

public sealed class AppOpenHost : MonoBehaviour
{
    [SerializeField] private string adUnitKey = "your-appopen-ad-unit-key";
    private DaroAppOpenAd ad;
    private bool hasEnteredBackground;

    private void OnEnable()
    {
        ad = new DaroAppOpenAd(adUnitKey);
        ad.OnAdLoaded += info => Debug.Log("app open loaded");
        ad.OnAdFailedToLoad += error => Debug.LogWarning(error.Message);
        ad.OnAdFailedToShow += error => Debug.LogWarning(error.Message);
        ad.Load();

        DaroAppStateNotifier.OnAppStateChanged += OnAppStateChanged;
    }

    private void OnAppStateChanged(DaroAppStateNotifier.AppState state)
    {
        if (state == DaroAppStateNotifier.AppState.Foreground
            && ad != null
            && hasEnteredBackground
            && ad.IsReady())
        {
            ad.Show();
        }

        if (state == DaroAppStateNotifier.AppState.Background)
        {
            hasEnteredBackground = true;
        }
    }

    private void OnDisable()
    {
        DaroAppStateNotifier.OnAppStateChanged -= OnAppStateChanged;
        ad?.Dispose();
        ad = null;
    }
}
```

> [!WARNING]
>
> 앱 오픈 광고는 첫 실행 직후에 표시하지 말고, 백그라운드에서 포그라운드로 돌아오는 시점에 표시하세요.

> [!WARNING]
>
> Android에서는 `OnAdLoaded` 콜백이 네이티브 preload 흐름과 겹칠 수 있습니다. 표시 가능 여부는 `OnAdLoaded` 플래그만 믿지 말고 `IsReady()`로 확인하세요.

> [!WARNING]
>
> 앱 오픈 광고는 dismiss 후 자동 preload 정책을 사용할 수 있습니다. `OnAdDismissed`에서 반복적으로 `Load()`를 호출하지 마세요.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.