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

# App Open Ads

> Implement app open ads in your Unity project.

## App Open Ad Format

* Full-screen ads shown when the app returns from background to foreground.
* Prefer showing them on warm foreground returns, not immediately on first launch.

***

## Integrating Ads

<Steps>
  <Step title="Create Ad Instance">
    ```csharp theme={null}
    private DaroAppOpenAd ad;

    ad = new DaroAppOpenAd("your-appopen-ad-unit-id");
    ```
  </Step>

  <Step title="Register Event Handlers">
    ```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);
    ```
  </Step>

  <Step title="Subscribe to App State Changes">
    ```csharp theme={null}
    DaroAppStateNotifier.OnAppStateChanged += OnAppStateChanged;
    ```
  </Step>

  <Step title="Show on Foreground Return">
    ```csharp theme={null}
    private void OnAppStateChanged(DaroAppStateNotifier.AppState state)
    {
        if (state == DaroAppStateNotifier.AppState.Foreground
            && ad != null
            && ad.IsReady())
        {
            ad.Show();
        }
    }
    ```
  </Step>

  <Step title="Unsubscribe and Dispose">
    ```csharp theme={null}
    DaroAppStateNotifier.OnAppStateChanged -= OnAppStateChanged;
    ad?.Dispose();
    ad = null;
    ```
  </Step>
</Steps>

***

## Example

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

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

    private void OnEnable()
    {
        ad = new DaroAppOpenAd(adUnitId);
        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>
  Do not show app open ads immediately on first launch. Show them when the app returns from background to foreground.
</Warning>

<Warning>
  On Android, `OnAdLoaded` can overlap with native preload flow. Check display readiness with `IsReady()` instead of relying only on an `OnAdLoaded` flag.
</Warning>

<Warning>
  App open ads can use automatic preload after dismiss. Do not repeatedly call `Load()` from `OnAdDismissed`.
</Warning>
