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

Implementation for interstitial video ads

fan-mi-baba edited this page Oct 3, 2023 · 3 revisions

Advance Preparation

Please refer to the link below if you have not created ad spot or downloaded the SDK.

SDK Implementation

If you have not added the SDK to project, please add it with the following method.


Interstitial Video Ad Implementation

Implementation of interstitial video ad will be done with the following five steps.

  1. Generate Video Ad
  2. Load Video Ad
  3. Show Video Ad
  4. Release Video Ad
  5. Implement optional function

Generate Video Ad

First, generate the instance of NendAdInterstitialVideo.

Kotlin
import net.nend.android.NendAdInterstitialVideo
...

class VideoActivity : AppCompatActivity() {

    private lateinit var nendAdInterstitialVideo: NendAdInterstitialVideo

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        nendAdInterstitialVideo = NendAdInterstitialVideo(this, spotId, "apikey")
    }
}
Java
import net.nend.android.NendAdInterstitialVideo;
...

public class MainActivity extends AppCompatActivity {

    NendAdInterstitialVideo mNendAdInterstitialVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNendAdInterstitialVideo = new NendAdInterstitialVideo(this, spotId, "apikey");
    }
}

Information necessary for instance generation

Argument Type Description
context Context
spotId int Unique spot id for your app given by nend console
apiKey String Unique api key for your app given by nend console

Load Video Ad

Load the ad using loadAd.

Kotlin
nendAdInterstitialVideo.loadAd()
Java
mNendAdInterstitialVideo.loadAd();

You can get ad type information by type property.

type Description
NORMAL Interstitial video ads
PLAYABLE User-controllable ads

Show Video Ad

Kotlin
if (nendAdInterstitialVideo.isLoaded) {
    nendAdInterstitialVideo.showAd(this)
}
Java
if (mNendAdInterstitialVideo.isLoaded()) {
    mNendAdInterstitialVideo.showAd(this);
}

Release Video Ad

Please make sure to call the releaseAd method if your video ad session has been completed or will not use video ad again on onDestroy of Activity. Discard unnecessary resources for video ad with releaseAd method. Also, if called during loading of ad will also cancel that load. Also, if want to use video ad again after calling the releaseAd method, create an instance of NendAdInterstitialVideo again.

Kotlin
nendAdInterstitialVideo.releaseAd()  // release ad
Java
mNendAdInterstitialVideo.releaseAd();  // release ad

Implement optional function

Please implement the following option as necessary.

Register Event Listener

Register event listener of NendAdVideoActionListener using setActionListener. NendAdVideo is the parent class of NendAdInterstitialVideo and NendAdRewardedVideo. The argument nendAdVideo in each NendAdVideoActionListener listener is an object of NendAdInterstitialVideo.

⚠️Notice about ads callback⚠️
Interactive ads (NendAdVideoType.PLAYABLE) cannot receive any event from NendAdVideoPlayingStateListener

Normal Video ads (NendAdVideoType.NORMAL) can receive callbacks when the video ads were played or stopped or finished.

Interactive ads (NendAdVideoType.PLAYABLE) is not video but working on the WebView.
Because of that, Interactive ads can't receive callback when the video ads were played or stopped or finished.

Kotlin
import net.nend.android.NendAdVideoActionListener
import net.nend.android.NendAdVideo
...

nendAdInterstitialVideo.setActionListener(object : NendAdVideoActionListener {
    override fun onLoaded(nendAdVideo: NendAdVideo) {
        // loading of ad is completed

        when (nendAdVideo.type) {
            NendAdVideoType.PLAYABLE -> Log.d(TAG, "Playable ad is not provide playing state listener")
            NendAdVideoType.NORMAL -> {
                nendAdInterstitialVideo.playingState()?.let {
                    it.playingStateListener = object : NendAdVideoPlayingStateListener {
                        override fun onStarted(nendAdVideo: NendAdVideo) {
                            // video started
                        }

                        override fun onStopped(nendAdVideo: NendAdVideo) {
                            // video stopped
                        }

                        override fun onCompleted(nendAdVideo: NendAdVideo) {
                            // video completed playing to the end
                        }
                    }
                }
            }
            else -> Log.d(TAG, nendAdVideo.type.toString())
        }
    }

    override fun onFailedToLoad(nendAdVideo: NendAdVideo, errorCode: Int) {
        // loading of ad is failed
        Log.d(TAG, "errorCode: $errorCode")
    }

    override fun onFailedToPlay(nendAdVideo: NendAdVideo) {
        // playing of ad content is failed
    }

    override fun onShown(nendAdVideo: NendAdVideo) {
        // ad shown
    }

    override fun onClosed(nendAdVideo: NendAdVideo) {
        // ad closed
    }

    override fun onAdClicked(nendAdVideo: NendAdVideo) {
        // ad clicked
    }

    override fun onInformationClicked(nendAdVideo: NendAdVideo) {
        // information button clicked
    }
})
Java
import net.nend.android.NendAdVideoActionListener;
import net.nend.android.NendAdVideo;
...

mNendAdInterstitialVideo.setActionListener(new NendAdVideoActionListener() {
    @Override
    public void onLoaded(NendAdVideo nendAdVideo) {
        // loading of ad is completed
        switch (mNendAdInterstitialVideo.getType()) {
            case PLAYABLE:
                Log.d(TAG, "Playable ad is not provide playing state listener");
                break;
            case NORMAL:
                NendAdVideoPlayingState state = mNendAdInterstitialVideo.playingState();
                if (state != null) {
                    state.setPlayingStateListener(new NendAdVideoPlayingStateListener() {
                        @Override
                        public void onStarted(NendAdVideo nendAdVideo) {
                            // video started
                        }

                        @Override
                        public void onStopped(NendAdVideo nendAdVideo) {
                            // video stopped
                        }

                        @Override
                        public void onCompleted(NendAdVideo nendAdVideo) {
                            // video completed playing to the end
                        }
                    });
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onFailedToLoad(NendAdVideo nendAdVideo, int errorCode) {
        // loading of ad is failed
        Log.d(TAG, "errorCode:" + errorCode);
    }

    @Override
    public void onFailedToPlay(NendAdVideo nendAdVideo) {
        // playing of ad content is failed
    }

    @Override
    public void onShown(NendAdVideo nendAdVideo) {
        // ad shown
    }

    @Override
    public void onClosed(NendAdVideo nendAdVideo) {
        // ad closed
    }

    @Override
    public void onAdClicked(NendAdVideo nendAdVideo) {
        // ad clicked
    }

    @Override
    public void onInformationClicked(NendAdVideo nendAdVideo) {
        // information button clicked
    }
});

Acquire Error Information

The information of the argument errorCode of public void onFailedToLoad(NendAdVideo nendAdVideo, int errorCode) 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

Set up User Name

This option is deprecated on nendSDK v10.0.0 or higher

When setting a user id that your app's original identifier, set the name with a character string using setUserId method.

Kotlin
nendAdInterstitialVideo.setUserId("User Id")
Java
mNendAdInterstitialVideo.setUserId("User Id");

Set up Features of User

This option is deprecated on nendSDK v10.0.0 or higher

In the nendSDK version 4.0.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.
Kotlin
import net.nend.android.NendAdUserFeature
...

//e.g. Only single feature
val feature = NendAdUserFeature.Builder()
        .setBirthday(1985,1,1) // Birthday (e.g. Jan 1, 1985)
        .build()
nendAdInterstitialVideo.setUserFeature(feature)

...

//e.g. Multiple features
val feature = NendAdUserFeature.Builder()
        .setGender(NendAdUserFeature.Gender.MALE) // Gender
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .setAge(34) // age
        .addCustomFeature("stringParameter", "test") // Others: customized parameters that formatted key-value type.
        .addCustomFeature("booleanParameter", true)
        .addCustomFeature("integerParameter", 100)
        .addCustomFeature("doubleParameter", 123.45)
        .build()
nendAdInterstitialVideo.setUserFeature(feature)
Java
import net.nend.android.NendAdUserFeature;
...

//e.g. Only single feature
NendAdUserFeature feature = new NendAdUserFeature.Builder()
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .build();
mNendAdInterstitialVideo.setUserFeature(feature);

...

//e.g. Multiple features
NendAdUserFeature feature = new NendAdUserFeature.Builder()
        .setGender(NendAdUserFeature.Gender.MALE) // Gender
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .setAge(34) // age
        .addCustomFeature("stringParameter", "test") // Others: customized parameters that formatted key-value type.
        .addCustomFeature("booleanParameter", true)
        .addCustomFeature("integerParameter", 100)
        .addCustomFeature("doubleParameter", 123.45)
        .build();
mNendAdInterstitialVideo.setUserFeature(feature);

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.

Set mute state to play video

Set mute to play video using setMuteStartPlaying method.
And default value is true.

Kotlin
nendAdInterstitialVideo.setMuteStartPlaying(false)
Java
mNendAdInterstitialVideo.setMuteStartPlaying(false);

Display Fullscreen Ads

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.

Kotlin
nendAdInterstitialVideo.addFallbackFullboard(full board spot id, "full board api key")
Java
mNendAdInterstitialVideo.addFallbackFullboard(full board spot id, "full board api key");

Verification

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

How to check GAID

  1. Enabled application logging.

  2. Generate interstitial video ad, then GAID value will be printed in debug logs. gaid_console_log

  3. Register GAID value on nend console.

日本語

nendSDK Android について

SDKの組み込み

広告の表示

ログ出力

導入サポート


English

About nendSDK Android

SDK Implementation

Display Ads

Logs Output

Supports

Clone this wiki locally