# 비디오 믹스 광고

## 1. 유저 식별값 입력

유저 식별값은 리워드 비디오 시청 완료 시 완료 유저를 식별하기 위해 사용되는 값입니다.

해당 유저 정보를 넘겨주어야 CS 접수 시, 유저를 특정 가능합니다. 단, CS 기능을 오픈하지 않을 경우에는 연동 진행하지 않아도 됩니다.

{% hint style="danger" %}
**주의 사항**

1. 1명의 유저는 1개의 고유한 유저 식별값을 가져야 하며, 가변적인 값을 사용해서는 안됩니다.
2. 개인정보(이메일, 이름, 전화번호, 식별 가능한 유저 아이디 등)이 포함되어서는 안됩니다.
3. 한글, 특수 문자, 공백 등이 포함된 경우에는 반드시 URL 인코딩 처리를 하여 사용하여야 합니다.
4. 유저가 비디오 광고 로딩 전에 설정되어야 합니다.
   {% endhint %}

위 주의사항에 유의하여 유저 식별값을 입력합니다.

```csharp
AdPopcornSSPPluginIOS.SetUserId("TEST_UNITY_IOS");
```

## 2. 비디오 믹스 광고 인스턴스 설정

아래 코드를 추가하여 비디오 믹스 광고 인스턴스를 생성합니다.

```csharp
public class APSSPSampleScene : MonoBehaviour{
	void Start(){   
		AdPopcornSSPPluginIOS.SSPVideoMixAdInitWithKey("YOUR_APP_KEY", "VIDEO_MIX_PLACEMENT_ID");
	}
}
```

{% hint style="info" %}
VIDEO\_MIX\_PLACEMENT\_ID : [애드팝콘 SSP 콘솔페이지](https://www.console.adpopcorn.com/)에서 생성한 비디오 믹스 광고 placementId
{% endhint %}

## 3. 비디오 믹스 광고 요청

SSPVideoMixAdLoadRequest API 를 호출하여 광고를 요청합니다.

```csharp
AdPopcornSSPPluginIOS.SSPVideoMixAdLoadRequest();
```

{% hint style="warning" %}
loadRequst 호출에 대한 결과로 광고 수신에 실패한 경우에는 loadAd 재호출을 하시면 안됩니다. 과도한 광고 요청 api 호출은 block 사유가 됩니다.
{% endhint %}

## 4. 비디오 믹스 광고 노출

SSPVideoMixAdPresentFromViewController API 를 호출하여 광고를 노출합니다.

```csharp
AdPopcornSSPPluginIOS.SSPVideoMixAdPresentFromViewController();
```

## 5. 비디오 믹스광고 델리게이트 설정

비디오 믹스광고 요청 및 노출에 대한/성공, 실패, 완료 대한 델리게이트를 제공합니다.&#x20;

콜백을 받을 scene 이름 매칭 및 델리게이트 활성화 API를 호출합니다.

관련된 자세한 사항은 연동 기본 설정 내 [델리게이트 설정](https://adpopcornssp.gitbook.io/ssp-sdk/sdk/unity/undefined#id-3)을 확인해 주세요

```csharp
AdPopcornSSPPluginIOS.AdPopcornSSPSetCallbackHandler("your_scene_name");
AdPopcornSSPPluginIOS.SSPVideoMixAdSetDelegate();	
```

* 지원되는 이벤트 delegate

<table><thead><tr><th width="324">delegate</th><th>설명</th></tr></thead><tbody><tr><td>sspVideoMixAdLoadSuccess</td><td>광고 로딩 성공</td></tr><tr><td>sspVideoMixAdLoadFail</td><td>광고 로드 실패. <a href="../undefined">에러코드 값</a></td></tr><tr><td>sspVideoMixAdShowSuccess</td><td>광고 노출 성공</td></tr><tr><td>sspVideoMixAdShowFail</td><td>광고 노출 실패</td></tr><tr><td>sspVideoMixAdClosed</td><td>광고 닫기</td></tr><tr><td>ㄴ campaignType</td><td>2: 전면, 4: 리워드 비디오, 6 : 전면 비디오</td></tr><tr><td>sspVideoMixAdPlayCompleted</td><td>비디오 믹스 광고 중, 리워드 비디오 광고 재생 완료</td></tr></tbody></table>

## 6. 비디오 믹스 광고 샘플 코드

```csharp
public class MySampleScene : MonoBehaviour {																						
    void Start () {									
        AdPopcornSSPPluginIOS.SetUserId("TEST_UNITY_IOS");
  	    AdPopcornSSPPluginIOS.AdPopcornSSPSetCallbackHandler("MySampleScene");		
	      AdPopcornSSPPluginIOS.SSPVideoMixAdInitWithKey("your_app_key", "placement_id");
      	AdPopcornSSPPluginIOS.SSPVideoMixAdSetDelegate();																
											
        AdPopcornSSPPluginIOS.sspVideoMixAdLoadSuccess += HandleSSPVideoMixAdLoadSuccess;
        AdPopcornSSPPluginIOS.sspVideoMixAdLoadFail += HandleSSPVideoMixAdLoadFail;
       	AdPopcornSSPPluginIOS.sspVideoMixAdShowSuccess += HandleSSPVideoMixAdShowSuccess;
        AdPopcornSSPPluginIOS.sspVideoMixAdShowFail += HandleSSPVideoMixAdShowFail;
        AdPopcornSSPPluginIOS.sspVideoMixAdClosed += HandleSSPVideoMixAdClosed;
       	AdPopcornSSPPluginIOS.sspVideoMixAdPlayCompleted += HandleSSPVideoMixAdPlayCompleted;
        AdPopcornSSPPluginIOS.SSPVideoMixAdLoadRequest();
    }
    
    // 델리게이트 구현									
    public void HandleSSPVideoMixAdLoadSuccess()
    {
    }

    public void HandleSSPVideoMixAdLoadFail(string error)
    {
    }

    public void HandleSSPVideoMixAdShowSuccess()
    {
    }

    public void HandleSSPVideoMixAdShowFail()
    {
    }

    public void HandleSSPVideoMixAdClosed(int campaignType)
    {
    }

    public void HandleSSPVideoMixAdPlayCompleted(int adNetworkNo, bool isCompleted)
    {
    }	
								
    void onDestroy(){									
    	  // 델리게이트 해제										
    	  AdPopcornSSPPluginIOS.sspVideoMixAdLoadSuccess -= HandleSSPVideoMixAdLoadSuccess;
        AdPopcornSSPPluginIOS.sspVideoMixAdLoadFail -= HandleSSPVideoMixAdLoadFail;
       	AdPopcornSSPPluginIOS.sspVideoMixAdShowSuccess -= HandleSSPVideoMixAdShowSuccess;
        AdPopcornSSPPluginIOS.sspVideoMixAdShowFail -= HandleSSPVideoMixAdShowFail;
        AdPopcornSSPPluginIOS.sspVideoMixAdClosed -= HandleSSPVideoMixAdClosed;
       	AdPopcornSSPPluginIOS.sspVideoMixAdPlayCompleted -= HandleSSPVideoMixAdPlayCompleted;
     }										
}

```


---

# 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://adpopcornssp.gitbook.io/ssp-sdk/sdk/unity/unity-ios/undefined-1.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.
