3. Quick Start

If your games do not require backend servers, this chapter is all you need to know to integrade Wakool SDK, everything else can be skipped.

3.1. Importing SDK

Simply insert the following line into your html page in the head section.

<script src="https://sdk.wakool.net/api/loader"></script>

3.2. Waiting for SDK initialization

After the SDK is imported, some of the functions provided require the SDK being initialized before they can be used. To wait for the SDK being initialized, use wakool.ready().

wakool.ready() is executed asynchronously and return a Promise object.

Example:

document.getElementById('wakool-jssdk').addEventListener
('load', function() {
    /**
     * Wakool SDK has been imported, but not yet 
     * initialized. At this stage, usually some configuration
     * is made, such as listening various events from Wakool SDK.
     *
     * To wait for the SDK being initialized, use wakool.ready()
     */
    wakool.ready().then(function() {
        /**
         * At this stage the SDK has been initialized and fully functional.
         */
        console.log('♥ ♥ ♥ Wakool SDK READY ♥ ♥ ♥');
    });
});

3.3. Video Ads

Play fullscreen video ads when appropriate.

Playback video ads only when SDK has been initialized.

3.3.1. Display Video Ads API

wakool.displayVideoAd(complete_callback, placement_id);

Parameters:

name type description
complete_callback function When the video Ad ends or the player choose to skip the Ad, this function will be called to notify the game.
placement_id string A string represents the button or reason that triggers the video ads, for analytics purpose.

Example:

wakool.displayVideoAd (
    // complete_callback
    function(result) {
        let details = '';
        if (result) {
            details = '(Duration:' + result.duration + ' seconds, ' + 
                       'played:' + result.played + ' seconds, ' + 
                       'clicked:' + result.clicks + ' times, ' + 
                       'effectively watched:' + result.isFinished() + ')';
        }
        console.log('Video ad ends!', details);
    },
    // placement_id
    'Reward double resources',
);

3.3.2. Listening pause/resume events

Once the video ads starts playing, the game should be paused as the video ads are played in fullscreen, and the game shall resume once the video ads stopped. Game developers should listen to those events, and pausing/resuming the game accordingly.

wakool.addEventListener(wakool.EVENT_GAME_PAUSE, function(event){
    // video ads begins, game pauses.
    console.log('game-play should pause here!!!');
});
wakool.addEventListener(wakool.EVENT_GAME_RESUME, function(event){
    // video ads ends, game play continues.
    let details = '';
    if (event && event.data) {
        details = '(Duration:' + event.data.duration + ' seconds, ' + 
                   'played:' + event.data.played + ' seconds, ' + 
                   'clicked:' + event.data.clicks + ' times, ' + 
                   'effectively watched:' + event.data.isFinished() + ')';
    }
    console.log('game-play should continue here!!!', details);
});

See Events for a complete list of events.

results matching ""

    No results matching ""