# 전면 광고

### 1 : 준비

* [프로젝트 설정](/adpie/unity/project-settings.md)을 통해 광고 연동을 위한 준비를 합니다.
* [사이트](http://my.adpies.com) 에서 매체를 등록하여 Media ID 를 발급받고, 슬롯을 등록하면서 광고 유형을 비디오 또는 이미지 광고를 선택하고 Slot ID 를 발급받습니다.

### 2 : SDK 초기화

* SDK 초기화를 하지 않았다면, [사이트](http://my.adpies.com)에서 발급받은 Media ID를 입력하여 초기화를 합니다.

```csharp
AdPieSDK.Instance.Initialize("AdPie-Media-ID");
```

### 3 : 광고 요청과 표출

* 사이트에서 발급받은 Slot ID를 입력하여 InterstitialAd 객체를 생성합니다.
* 광고 요청과 표출로 메소드가 각각 나누어져 있습니다.
* 광고 요청시 Load() 메소드를 호출하고, 표출 시 Show()를 호출을 합니다.
* 광고 컨텐츠가 로드되지 않을 가능성이 있기에 IsLoaded()를 통해 확인 후 Show() 메소드를 호출합니다.

```csharp
{
    // 광고 연동을 위한 슬롯 ID를 필수로 입력합니다.
    InterstitialAd interstitialAd = new InterstitialAd("AdPie-Slot-ID");
    interstitialAd.Load();
}
```

### 4 : 광고 리스너 사용

* 전면 (이미지, 비디오) 광고 요청에 대한 이벤트를 수신할 수 있습니다.
* [에러코드](/adpie/unity/common/errorcode.md)를 통해 광고 실패에 대한 이유를 알 수 있습니다.

```csharp
{
    InterstitialAd interstitialAd = new InterstitialAd("AdPie-Slot-ID");
    interstitialAd.OnAdLoaded += InterstitialAd_OnAdLoaded;
    interstitialAd.OnAdFailedToLoad += InterstitialAd_OnAdFailedToLoad;
    interstitialAd.OnAdClicked += InterstitialAd_OnAdClicked;
    interstitialAd.OnAdShown += InterstitialAd_OnAdShown;
    interstitialAd.OnAdDismissed += InterstitialAd_OnAdDismissed;
    interstitialAd.Load();
}

void InterstitialAd_OnAdLoaded()
{
    // 광고 로딩 완료 후 이벤트 발생
    
    // 광고 요청 후 즉시 노출하고자 할 경우 아래의 코드를 추가합니다.
    if (interstitialAd != null && interstitialAd.IsLoaded())
    {
        interstitialAd.Show();
    }
    
}

void InterstitialAd_OnAdFailedToLoad(int errorCode)
{
    // 광고 요청 또는 표출 실패 후 이벤트 발생
}

void InterstitialAd_OnAdClicked()
{
    // 광고 클릭 후 이벤트 발생
}

void InterstitialAd_OnAdShown()
{
    // 광고 표출 후 이벤트 발생
}

void InterstitialAd_OnAdDismissed()
{
    // 광고가 표출한 뒤 사라질 때 이벤트 발생
}
```

* 비디오 광고의 경우 비디오 플레이에 대한 이벤트를 받을 수 있습니다.

```csharp
{
    // optional
    VideoAdPlaybackListener videoAdPlaybackListener = new VideoAdPlaybackListener();
    videoAdPlaybackListener.OnVideoAdStarted += OnVideoAdStarted;
    videoAdPlaybackListener.OnVideoAdPaused += OnVideoAdPaused;
    videoAdPlaybackListener.OnVideoAdStopped += OnVideoAdStopped;
    videoAdPlaybackListener.OnVideoAdSkipped += OnVideoAdSkipped;
    videoAdPlaybackListener.OnVideoAdError += OnVideoAdError;
    videoAdPlaybackListener.OnVideoAdCompleted += OnVideoAdCompleted;
    interstitialAd.setVideoAdPlaybackListener(videoAdPlaybackListener);
}

void OnVideoAdStarted()
{
    // 비디오 광고 시작 이벤트 알림
}

void OnVideoAdPaused()
{
    // 비디오 광고 일시중지 이벤트 알림
}

void OnVideoAdStopped()
{
    // 비디오 광고 중지 이벤트 알림
}

void OnVideoAdSkipped()
{
    // 비디오 광고 건너뜀 이벤트 알림
}

void OnVideoAdError()
{
    // 비디오 광고 오류 이벤트 알림
}

void OnVideoAdCompleted()
{
    // 비디오 광고 완료 이벤트 알림
}

```


---

# 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/adpie/unity/integration/interstitial.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.
