Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Video ads

fan-t-kinami edited this page Apr 13, 2023 · 17 revisions

Preparation

If you have not created ad spaces or downloaded SDK, please refer to the link below.

SDK Implementation

If you have not imported Unity package into project, please follow the link below.


Implementation procedure

Implementation procedure of Interstitial Video ad

  1. Create an NendAdInterstitialVideo object using NewVideoAd method of NendAdInterstitialVideo.

  2. If you want to receive response event from NendAdInterstitialVideo process, please register event call backs. The events are as follows.

    public event NendAdVideoLoaded AdLoaded;
    public event NendAdVideoFailedToLoad AdFailedToLoad;
    public event NendAdVideoFailedToPlay AdFailedToPlay;
    public event NendAdVideoShown AdShown;
    public event NendAdVideoClick AdStarted; //Never called on AdType.Playable!!
    public event NendAdVideoClick AdStopped; //Never called on AdType.Playable!!
    public event NendAdVideoClick AdCompleted; //Never called on AdType.Playable!!
    public event NendAdVideoClick AdClicked;
    public event NendAdVideoClick InformationClicked;
    public event NendAdVideoClosed AdClosed;
  3. To load an interstitial video, call the NendAdInterstitialVideo object's Load method.
    When failed to Load, you've receive same error code via callbacks. Error code is as follows.

    Code Description
    204 No delivery ads
    400 BAD request
    5XX Server error
    600 Error in SDK
    601 Ad download failed
    602 Fallback fullscreen ad failed
    603 Invalid network
    604 Advertisement acquisition network error (timeout etc.)

    You can get ad type information by AdType property.

    AdType Description
    Normal Normal video ads
    Playable User-controllable ads
  4. Call NendAdInterstitialVideo object's Show method to show interstitial video ad, after loading is completed.

  5. Please make sure to call the NendAdInterstitialVideo object's Release method after your video ad session has been completed.

Example of interstitial video ad.

using UnityEngine;
using NendUnityPlugin.AD.Video;

public class VideoObject : MonoBehaviour
{
    #if UNITY_IOS
    private int spotId = 802557;
    private string apiKey = "b6a97b05dd088b67f68fe6f155fb3091f302b48b";
    #else
    private int spotId = 802559;
    private string apiKey = "e9527a2ac8d1f39a667dfe0f7c169513b090ad44";
    #endif
    private NendAdInterstitialVideo m_InterstitialVideoAd;

    // Use this for initialization
    void Start ()
    {
        m_InterstitialVideoAd =
            NendAdInterstitialVideo.NewVideoAd (spotId, apiKey);

        m_InterstitialVideoAd.AdLoaded += (instance) => {
            // loading of ad is completed
        };
        m_InterstitialVideoAd.AdFailedToLoad += (instance, errorCode) => {
            // loading of ad is failed
        };
        m_InterstitialVideoAd.AdFailedToPlay += (instance) => {
            // playing of video is failed
        };
        m_InterstitialVideoAd.AdShown += (instance) => {
            // ad shown
        };
        m_InterstitialVideoAd.AdStarted += (instance) => {
            // video started (never called on AdType.Playable)
        };
        m_InterstitialVideoAd.AdStopped += (instance) => {
            // video stopped (never called on AdType.Playable)
        };
        m_InterstitialVideoAd.AdCompleted += (instance) => {
            // video completed playing to the end (never called on AdType.Playable)
        };
        m_InterstitialVideoAd.AdClicked += (instance) => {
            // ad clicked
        };
        m_InterstitialVideoAd.InformationClicked += (instance) => {
            // information button clicked
        };
        m_InterstitialVideoAd.AdClosed += (instance) => {
            // ad closed
        };
    }

    void OnDestroy () {
        m_InterstitialVideoAd.Release ();
    }

    public void Load ()
    {
        m_InterstitialVideoAd.Load ();
    }

    public void Show ()
    {
        if (m_InterstitialVideoAd.IsLoaded()) {
            m_InterstitialVideoAd.Show ();
        }
    }
}

Optional settings for Interstitial video ad.

You can also set user id, Features of User, fallback fullboard ad, and set mute state to play video.

Set user id 【deprecated】

⚠️【deprecated】⚠️
After version 5.0.0, UserId property is no longer supported in iOS.
Android support will be discontinued soon.

Call NendAdInterstitialVideo object's UserId property. This is your app's original identifier.

m_InterstitialVideoAd.UserId = "user id";

Set Features of User 【deprecated】

⚠️【deprecated】⚠️
After version 5.0.0, UserFeature property is no longer supported in iOS.
Android support will be discontinued soon.

In the Unity-plugin version 2.3.3 or higher, targeting-ad option of video ad is available to using Features of User.
Here are available options.

  • Gender
  • Birthday
  • Age
  • Others: could be customized from own your app.

Call NendAdInterstitialVideo object's UserFeature property.

//e.g. Only single feature
NendAdUserFeature userFeature = new NendAdUserFeature ();
userFeature.SetBirthday (1985, 12, 31); // Birthday (e.g. Dec 31, 1985)
m_InterstitialVideoAd.UserFeature = userFeature;

...

//e.g. Multiple features
NendAdUserFeature userFeature = new NendAdUserFeature ();
userFeature.gender = NendAdUserFeature.Gender.Female;
userFeature.SetBirthday (1985, 12, 31); // Birthday (e.g. Dec 31, 1985)
userFeature.age = 10; // age
userFeature.AddCustomFeature ("someString", "TestText"); // Others: customized parameters that formatted key-value type.
userFeature.AddCustomFeature ("someInt", 1);
userFeature.AddCustomFeature ("someDouble", 23.4);
userFeature.AddCustomFeature ("someBool", true);
m_InterstitialVideoAd.UserFeature = userFeature;

Note:

  • Birthday is high priority than age if set both parameters.
  • You can only using string or int or double or bool value at custom parameters.
  • If you want to set age group, please use custom parameters not age.

Add fallback fullboard ad.

Call NendAdInterstitialVideo object's AddFallbackFullboard method.
If you can not display interstitial video for reasons such as out of stock, you can display fullscreen ads instead.
In order to use this function, you need to register ad space of fullscreen ads separately on the management screen.

m_InterstitialVideoAd.AddFallbackFullboard (fullboard_spotid, "fullboard_apikey");

If you want to customize background-color of area that outside of iPhoneX Safe Area, use following function instead of above one.

using UnityEngine;
...

// e.g. gray color
m_InterstitialVideoAd.AddFallbackFullboard (fullboard_spotid, "fullboard_apikey", Color.gray);

Set mute state to play video

Call NendAdInterstitialVideo object's IsMuteStartPlaying property.
Default is true.

m_InterstitialVideoAd.IsMuteStartPlaying = false;

Implementation procedure of Rewarded Video ad

  1. Create an NendAdRewardedVideo object using NewVideoAd method of NendAdRewardedVideo.

  2. Please register event call backs to receive Rewarded event. And optionally, if you want to receive other response event from NendAdRewardedVideo process. The events are as follows.

    public event NendAdVideoLoaded AdLoaded;
    public event NendAdVideoFailedToLoad AdFailedToLoad;
    public event NendAdVideoFailedToPlay AdFailedToPlay;
    public event NendAdVideoShown AdShown;
    public event NendAdVideoClick AdStarted; //Never called on AdType.Playable!!
    public event NendAdVideoClick AdStopped;  //Never called on AdType.Playable!!
    public event NendAdVideoClick AdCompleted; //Never called on AdType.Playable!!
    public event NendAdVideoClick AdClicked;
    public event NendAdVideoClick InformationClicked;
    public event NendAdVideoClosed AdClosed;
    public event NendAdVideoRewarded Rewarded; //Please register to receive reward!!
  3. To load an interstitial video, call the NendAdRewardedVideo object's Load method. When failed to Load, you've receive same error code as via callbacks.
    Error code is as follows.
    Ad type information is as follows.

  4. Call NendAdRewardedVideo object's Show method to show interstitial video ad, after loading is completed.

  5. Please make sure to call the NendAdRewardedVideo object's Release method after your video ad session has been completed.

Example of rewarded video ad.

using UnityEngine;
using NendUnityPlugin.AD.Video;

public class VideoObject : MonoBehaviour
{
    #if UNITY_IOS
    private int spotId = 802555;
    private string apiKey = "ca80ed7018734d16787dbda24c9edd26c84c15b8";
    #else
    private int spotId = 802558;
    private string apiKey = "a6eb8828d64c70630fd6737bd266756c5c7d48aa";
    #endif
    private NendAdRewardedVideo m_RewardedVideoAd;

    // Use this for initialization
    void Start ()
    {
        m_RewardedVideoAd =
            NendAdRewardedVideo.NewVideoAd (spotId, apiKey);

        m_RewardedVideoAd.AdLoaded += (instance) => {
            // loading of ad is completed
        };
        m_RewardedVideoAd.AdFailedToLoad += (instance, errorCode) => {
            // loading of ad is failed
        };
        m_RewardedVideoAd.AdFailedToPlay += (instance) => {
            // playing of video is failed
        };
        m_RewardedVideoAd.AdShown += (instance) => {
            // ad shown
        };
        m_RewardedVideoAd.AdStarted += (instance) => {
            // video started (never called on AdType.Playable)
        };
        m_RewardedVideoAd.AdStopped += (instance) => {
            // video stopped (never called on AdType.Playable)
        };
        m_RewardedVideoAd.AdCompleted += (instance) => {
            // video completed playing to the end (never called on AdType.Playable)
        };
        m_RewardedVideoAd.AdClicked += (instance) => {
            // ad clicked
        };
        m_RewardedVideoAd.InformationClicked += (instance) => {
            // information button clicked
        };
        m_RewardedVideoAd.AdClosed += (instance) => {
            // ad closed
        };
        m_RewardedVideoAd.Rewarded += (instance, rewardedItem) => {
            // Rewards
            Debug.Log ("CurrencyName = " + rewardedItem.currencyName);
            Debug.Log ("CurrencyAmount = " + rewardedItem.currencyAmount);
        };
    }

    void OnDestroy () {
        m_RewardedVideoAd.Release ();
    }

    public void Load ()
    {
        m_RewardedVideoAd.Load ();
    }

    public void Show ()
    {
        if (m_RewardedVideoAd.IsLoaded()) {
            m_RewardedVideoAd.Show ();
        }
    }
}

Optional settings for Rewarded video ad.

You can also set user id, Features of User.

Set user id 【deprecated】

⚠️【deprecated】⚠️
After version 5.0.0, UserId property is no longer supported in iOS.
Android support will be discontinued soon.

Call NendAdRewardedVideo object's UserId property. This is your app's original identifier.

m_RewardedVideoAd.UserId = "user id";

Verification

Please use one of the following test modes for video ads.

Register Advertisement ID

You must register Advertisement ID on management screen of nend. Please check how to test these platforms:

Clone this wiki locally