InterstitialVideo Ad - fan-ADN/nendSDK-cocos2d-x GitHub Wiki

Preparation

If you have not yet register app/ad placements nor downloaded SDK, please refer to following link.

SDK Implementation

Add SDK/Module to a project.


The Flow to Implement Interstitial Video Ad

Implement a program that displays interstitial video Ads into the source file of Cocos2d-x.
Please follow the instruction below.

  1. Create an instance
  2. Load ad
  3. Show ad
  4. Discard ad
  5. Optional settings

Create an instance

Keep an instance controlling the Interstitial Video Ad in the class.

Header file

Declare a variable to hold the instance.

#include "NendVideoAds.h"

class YourAppScene : public cocos2d::Scene
{
  ...
private:
    // Keep the instance in the class.
    nend_module::video::VideoAds::InterstitialVideoAd* _interstitialVideoAd;
  ...
}

Implementation file

Set the instance to the variable that declared in the Header file.

using namespace nend_module;

bool YourAppScene::init()
{
  ...
    _interstitialVideoAd = VideoAds::createInterstitialVideoAd("SpotId published on the dashboard", "ApiKey published on the dashboard");
  ...
}

Load ad

Load ads.

_interstitialVideoAd->loadAd();

Show ad

You can display ad after the loading of ad is completed. Please check the state via isReady() loading was completed or not.

if (_interstitialVideoAd->isReady()) {
    _interstitialVideoAd->showAd();
}

Note: WhenThe ad contents is not reloaded automatically when it has been closed. You must need to execute the loading process if you want to updating ad contents.

Discard ad

Discard unnecessary resources for video ad. Please call destroy() at the time when it becomes unnecessariness after use the video ad.
Also, if you want to use video ads again after calling destroy(), instantiate the InterstitialVideoAd ad again.

YourAppScene::~YourAppScene()
{
    _interstitialVideoAd->destroy();
    CC_SAFE_DELETE(_interstitialVideoAd);
}

Optional settings

Display Fullscreen Ads

If you fail to display interstitial video by 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.

_interstitialVideoAd->addFallbackFullBoard("full board spot id", "full board api key");

Fullscreen Ad's background color outside Safe Area(iOS)

You can change the Fullscreen Ad's background color outside iPhoneX Safe Area more affinitive to your app looking & feeling. For details, please refer to here.

_interstitialVideoAd->setFallbackFullBoardBackgroundColor4F(cocos2d::Color4F::WHITE);

Set mute state to play video

Set mute to play video using setMuteStartPlaying method.
Default is true.

_interstitialVideoAd->setMuteStartPlaying(false);

Set up state of using location data

Call setLocationEnabled if you change the state of using location data.
Default is true.

_interstitialVideoAd->setLocationEnabled(false);

Set user ID

You can set the user ID in the application.

_interstitialVideoAd->setUserid("user id");

Set up Features of User

In the cocos2d-x module 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.
// e.g. Only single feature
NendUserFeature *interstitialUserFeature = new NendUserFeature();
interstitialUserFeature->setBirthday(2000, 1, 1); // Birthday (e.g. Jan 1, 2000)
_interstitialVideoAd->setUserFeature(interstitialUserFeature);
delete interstitialUserFeature;

...

// e.g. Multiple features
NendUserFeature *interstitialUserFeature = new NendUserFeature();
interstitialUserFeature->setGender(NendUserFeature::Gender::FEMALE); // Gender
interstitialUserFeature->setBirthday(2000, 1, 1); // Birthday (e.g. Jan 1, 2000)
interstitialUserFeature->setAge(18); // Age
interstitialUserFeature->addCustomValue(100, "intParameter"); // Others: customized parameters that formatted value-key type.
interstitialUserFeature->addCustomValue(123.45, "doubleParameter");
interstitialUserFeature->addCustomValue("test", "stringParameter");
interstitialUserFeature->addCustomValue(true, "boolParameter");
_interstitialVideoAd->setUserFeature(interstitialUserFeature);
delete interstitialUserFeature;

Set log output

You can specify whether debug logs are output to the debug console.

The setting of log output is set by the third parameter at instance creation.

_interstitialVideoAd = VideoAds::createInterstitialVideoAd("SpotId published on the dashboard", "ApiKey published on the dashboard", true);
Setting value Description
true Output the debug log
false Do not output logs
Omitting setting value Output according to the setting of Logs Output

Receive notifications

You can receive notifications about each processing information of interstitial video Ad via registered callback.

Load success
_interstitialVideoAd->onLoaded([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - OnLoaded.");
});
Load failed
_interstitialVideoAd->onFailedToLoad([](const VideoAds::InterstitialVideoAd& ad, int errorCode) {
    CCLOG("InterstitialVideoAd - onFailedToLoad: %d", errorCode);
});

The information of 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 Ad acquisition network error (timeout etc.)
Display failure
_interstitialVideoAd->onFailedToPlay([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onFailedToPlay.");
});
Ad displayed
_interstitialVideoAd->onShown([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onShown.");
});
Video started
_interstitialVideoAd->onStarted([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onStarted.");
});
Video stopped
_interstitialVideoAd->onStopped([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onStopped.");
});
Video completed playing to the end
_interstitialVideoAd->onCompleted([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onCompleted.");
});
Ad closed
_interstitialVideoAd->onClosed([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onClosed.");
});
Ad clicked
_interstitialVideoAd->onAdClicked([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onAdClicked.");
});
Information button clicked
_interstitialVideoAd->onInformationClicked([](const VideoAds::InterstitialVideoAd& ad) {
    CCLOG("InterstitialVideoAd - onInformationClicked.");
});