4-1. 보상형 비디오 광고 for Unity

비디오 광고 시청 완료 시, 유저에게 리워드가 지급되는 광고 타입 입니다.

사전 작업

04. Unity-Plugin Guide

ONEAdMax SDK 초기화

광고를 로드하기 전 ONEAdMax 초기화가 필요하며, ONEAdMaxClient.Initialize() 는 최초 한 번만 수행해야 합니다.

...
using ONEAdMax;
...
public class ONEAdMaxDemo : MonoBehaviour
{
    private static bool _isInitialized = false;
    
    void Start()
    {
        if (!_isInitialized)
        {
            // Initialize the ONEAdMax SDK.
            ONEAdMaxClient.Initialize(() =>
            {
                // This callback is called once the ONEAdMax SDK is initialized.
                _isInitialized = true
            });
        }
    }
}

유저 식별값 설정

보상형 비디오 시청 완료 시 리워드 지급 유저를 식별하기 위해 사용됩니다.

string userId = "bXlBY2NvdW50X25hbWU";
ONEAdMaxClient.SetUserId(userId);

꼭! 확인해주세요!


Reward Video AD Sample Code

OAMRewardVideo 인스턴스를 생성하고, 이벤트를 처리하여 기능을 확장할 수 있습니다.

Reward Video AD 인스턴스 생성하기

public class RewardVideoAdController : MonoBehaviour
{
    OAMRewardVideo _rewardVideoAd
    
    /// <summary>
    /// Creates the ad.
    /// </summary>
    public void CreateRewardVideoAd()
    {
        Debug.Log("Creating Reward video ad.");
        
        if (_rewardVideoAd != null)
        {
            Debug.LogWarning("Already have a Reward video ad.");
            return;
        }
    
        _rewardVideoAd = new OAMRewardVideo();
    }
}

네트워크 스케줄 타임아웃 설정 (선택사항)

리워드 비디오 광고에 대한 네트워크 스케줄 타임아웃을 설정합니다.

리워드 비디오 광고 로딩 시 각 네트워크 별로 타임아웃 시간을 설정하여 해당 시간 안에 광고를 받지 못할 경우 , 다음 네트워크로 넘어갑니다.

_rewardVideoAd.SetNetworkScheduleTimeout(5); // Default 5 seconds

Reward Video AD 이벤트 리스너 설정 (선택사항)

/// <summary>
/// Register to events the reward video ad may raise.
/// </summary>
private void RegisterEvents(OAMRewardVideo ad)
{
    // Raised when an ad is loaded into the reward video ad.
    ad.OnLoaded += () =>
    {
        Debug.Log("Reward video ad loaded.");
    };

    // Raised when an ad fails to load into the reward video ad.
    ad.OnLoadFailed += (OAMError error) =>
    {
        Debug.LogError("Reward video ad failed to load an ad with error : " + error);
    };

    // Raised when an ad opened full screen content.
    ad.OnOpened += () =>
    {
        Debug.Log("Reward video ad has been opened.");
    };

    // Raised when the ad failed to open full screen content.
    ad.OnOpenFailed += (OAMError error) =>
    {
        Debug.LogError("Reward video ad failed to open an ad with error : " + error);
    };

    // Raised when the ad closed full screen content.
    ad.OnClosed += () =>
    {
        Debug.LogError("Reward video ad is closed.");
    };

    // Raised when the ad completed full screen content.
    ad.OnCompleted += (int adNetworkNo, bool compledted) =>
    {
        Debug.Log("Reward video ad completed : " + "adNetworkNo=" + adNetworkNo + ", compledted=" + compledted);
    };

    // Raised when a click is recorded for an ad. on completed 에서 completed 가 true 일 때만 리워드 지급
    ad.OnClicked += () =>
    {
        Debug.Log("Reward video ad was clicked.");
    };
}
ONE AdMax SDK Error Codes

리워드 비디오 광고 생성하기

모든 설정을 완료하고 OAMInterstitialVideo를 만듭니다.

// These ad units are configured to always serve test ads.   
private readonly string _placementId = "string your placement ID";

_rewardVideoAd.Create(_placementId);

리워드 비디오 광고 로드 하기

리워드비디오 광고 Load() API를 호출하여 서버에 광고를 요청합니다.

/// <summary>
/// Loads the ad.
/// </summary>
public void Load()
{
    if (_rewardVideoAd == null)
    {
        Debug.LogWarning("The reward video ad is null.");
        return;
    }

    _rewardVideoAd.Load();
}

리워드 비디오 광고 노출하기

광고 로드가 완료되면 광고를 노출을 원하는 시점에 Show() API를 호출하여 화면에 노출 시킵니다.

/// <summary>
/// Shows the ad.
/// </summary>
public void Show()
{
    if (_rewardVideoAd != null && _rewardVideoAd.IsLoaded())
    {
        Debug.Log("Showing reward video ad.");
        _rewardVideoAd.Show();
    }
    else
    {
        Debug.LogError("The reward video ad hasn't loaded yet.");
    }
}

리워드 비디오 광고 메모리 해지하기

광고의 인스턴스 내의 메모리를 해지 합니다.

/// <summary>
/// Destroys the ad.
/// </summary>
public void Destroy()
{
    if (_rewardVideoAd != null)
    {
        Debug.Log("Destroying reward video ad.");
        _rewardVideoAd.Destroy();
        _rewardVideoAd = null;
    }
}

보상형 비디오 광고 로드 여부 체크하기

보상형 비디오 광고의 로드 여부를 체크합니다. (return ture | false)

_rewardVideoAd.IsLoaded();

어플리케이션의 라이프사이클 확장하기

광고가 노출되고 있는 어플리케이션의 onPause / onResume여부를 체크하기 위해 구현해야 합니다.

public class RewardVideoAdController : MonoBehaviour
{
    void OnApplicationPause(bool pauseStatus)
    {
        // You should call events for pause and resume in the application lifecycle.
        _rewardVideoAd?.OnPause(pauseStatus);
    }
}

주의사항

CS 페이지 호출

광고 CS 페이지를 노출 시키는 API 입니다.

string userId = "bXlBY2NvdW50X25hbWU";
ONEAdMaxClient.OpenRewardVideoCSPage(userId);

미디에이션 설정

안정적인 Fill-rate 및 eCPM을 위해 AppLovin, Unityads, Vungle의 미디에이션 작업을 추천합니다.

📌미디에이션 시작하기

Last updated