SDK Implementation - pogamesdk/POGAME-Cocos GitHub Wiki

Implementation

You can integrate POGAME in both new games and in existing games. Please follow the instructions below depending on your situation.

Add your Game ID to the POGAME section of the script file:

onLoad: function () {
    window["PO_OPTIONS"] = {
        "gameId": "[YOUR GAME ID HERE]",
        "onEvent": function(event) {
            switch (event.name) {
                case "SDK_READY":
                    // When the SDK is ready.
                    break;
                case "SDK_ERROR":
                    // When the SDK has hit a critical error.
                    break;
                case "SDK_GAME_START":
                    // advertisement done, resume game logic and unmute audio
                    break;
                case "SDK_GAME_PAUSE":
                    // pause game logic / mute audio
                    break;
                case "SDK_REWARDED_WATCH_COMPLETE":
                    // this event is triggered when your user completely watched rewarded ad
                    break;
            }
        },
    };
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s);
        js.id = id;
        js.src = 'https://sdk.pogame.com/posdk.js';
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'posdk'));
}

Usage

To use the POGAME SDK in a cocos game you need to write some new functions to call advertisement from POGAME SDK.

//Interstitial ads
POShowAd: function () {
    if (typeof posdk !== 'undefined' && posdk.showAd !== 'undefined') {
        posdk.showAd();
    }
},
//Rewarded ads
POShowRewardedAd: function () {
    if (typeof posdk !== 'undefined' && posdk.showAd !== 'undefined') {
        posdk.showAd('rewarded')
        .then(response => {
            // Ad process done. You can track "SDK_REWARDED_WATCH_COMPLETE" event if that event triggered, that means the user watched the advertisement completely, you can give reward there.
        })
        .catch(error => {
            // An error catched. Please don't give reward here.
        });
    }
},

Showing a Rewarded ad

Use Rewarded-Ads to give the user premium content, extra lives, in-game currency, and so on. You show a Rewarded Ad like this:

Showing an Interstitial Ad

Use Interstitial Ads during screen transitions, between sessions and in other situations where there is a natural pause in game play. You show an Interstitial Ad like this: