7. Advertisement
Show video ads in game when appropriate.
7.1. Ad types
Rewarded Ads:
The ad format allows users to earn rewards by watching ads, enhancing the ad experience. Users can voluntarily watch ads in exchange for in-app rewards.Display Ads:
These can be any ads you see presented in the form of videos, images, text, audio, or even a combination of them.
7.2. Video Ads
When the display video API is called, the browser will start playing
full-screen video ads. When the video ads ends or the player choose to
skip the ads, completeCallback
will be called.
※ For modern browsers, especially on mobile devices, the autoplay policy requires that video or audio playback must be triggered by user interactions. This means the video ads API must be called within a user click or touch event handler; otherwise, the browser will block the playback, causing the API call to fail.
7.2.1. Calling API
wakool.displayVideoAd(options);
7.2.2. Parameters:
name | type | description |
---|---|---|
options | object |
An object containing various settings as its properties. See the table below for available settings. |
name | type | description |
---|---|---|
completeCallback | function |
When the video ad ends or the player choose to skip it, this function is called to notify the game. |
placementId | string |
A string represents the button or reason that triggers the video ads, for analytics purpose. |
fullscreen | boolean |
Whether the video ads are allowed to play in fullscreen mode, default is false. |
isRewarded | boolean |
Whether the ad is rewarded ads, default is false. |
7.2.3. Example:
const options = {
completeCallback: function(result) {
let details = '(Duration:' + result.duration + ' seconds, ' +
'played:' + result.played + ' seconds, ' +
'clicked:' + result.clicks + ' times, ' +
'effectively watched:' + result.isFinished() + ')';
console.log('Video ad ends!', details);
},
placementId: 'Reward double resources',
fullscreen: false,
isRewarded: true,
};
wakool.displayVideoAd(options);
7.3. Listening pause/resume events
When the video ads start playing, the game should be paused since the ads are displayed in fullscreen. The game should resume once the video ads stop. Game developers should listen for these events and pause or resume the game accordingly.
wakool.addEventListener(wakool.EVENT_GAME_PAUSE, function(event){
// video ads begins, pause the game.
console.log('Game should be paused here!!!');
});
wakool.addEventListener(wakool.EVENT_GAME_RESUME, function(event){
// video ads ends, game play continues.
let details = '(Duration:' + result.duration + ' seconds, ' +
'played:' + result.played + ' seconds, ' +
'clicked:' + result.clicks + ' times, ' +
'effectively watched:' + result.isFinished() + ')';
console.log('game-play should continue here!!!', details);
});
See Events for a complete list of events.
7.4. Cooldown period
To prevent video ads being played too frequently, there's a cool-down period after each successfully playback of video ads.
During cool-down period calling to wakool.displayVideoAd()
are ignored and the completeCallback
are immediately called.
The cool-down period varies according to how long the video ads were played, the longer a user watched the video ads the longer the cool-down period would be.
Developers may use the following API to find out whether it's still within the cool-down period, or
how long the cool-down period remains.
7.4.1. API to query the cool-down period
wakool.videoAdsCooldown();
7.4.2. Return value:
type | description |
---|---|
number |
Remaining cool-down in seconds, or 0 if not in the cool-down period. |
7.4.3. Example:
if (wakool.videoAdsCooldown() > 0) {
console.log('Video ads cool-down remaining: ' + wakool.videoAdsCooldown() + ' seconds!');
}