4-1. Rewarded Video Ads for Unity

This is an ad type where users are rewarded after watching the video ad to completion.

Before you begin

04. Unity-Plugin Guide

ONEAdMax SDK initialization

ONEAdMax initialization is required before loading ads. The ONEAdMaxClient.Initialize() should be performed only once.

...
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
            });
        }
    }
}

User identifier setting

It is used to identify users for reward distribution when they complete watching a reward video.

string userId = "bXlBY2NvdW50X25hbWU";
ONEAdMaxClient.SetUserId(userId);
  • Each user should have a unique user identifier that is not a variable value.

  • It should not include personal information (such as email, name, phone number, or identifiable user IDs).

  • If the identifier contains Korean, special characters, or spaces, it must be URL encoded before use.

  • The user identifier should be set before the user enters the ad.


Reward Video AD Sample Code

You can create an OAMRewardVideo instance and handle events to extend its functionality.

Create a Reward Video Ad instance

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();
    }
}

Network schedule timeout setting (optional)

Set the network schedule timeout for Reward Video Ads. When loading the Reward Video Ad, you can set a timeout for each network. If the ad is not received within the specified time, it will move on to the next network.

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

Setting up event listeners for Reward Video Ads (optional)

/// <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

Create a Reward Video Ad

Once all settings are complete, create the OAMInterstitialVideo.

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

_rewardVideoAd.Create(_placementId);

Load the Reward Video Ad

Call the Load() API for the Reward Video Ad to request an ad from the server.

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

    _rewardVideoAd.Load();
}

Excessive ad requests can result in a block, so please be careful!

Display the Reward Video Ad

Once the ad has finished loading, call the Show() API at the desired point to display the ad on the screen.

/// <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.");
    }
}

Destroys the ad

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

Check if the Reward Video Ad has been loaded

Check the load status of the Reward Video Ad. (returns true | false)

_rewardVideoAd.IsLoaded();

Extending the application's lifecycle

You need to implement checking the onPause / onResume status of the application where the ad is being displayed.

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

If not handled, it may result in missing report data when using third-party mediation.

Call the CS page

This is the API to display the ad CS page.

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

Mediation settings

For stable fill rates and eCPM, it is recommended to set up mediation with AppLovin, Unity Ads, and Vungle.

📌Starting Mediation

Last updated