Skip to content

SDK Documentation ๐Ÿ“ƒ

Intention of events

Thanks to our developer-friendly SDK, you can easily oversee the most important metrics of your game simply by firing a couple of SDK events during various moments in the game. This information includes, but is not limited to:

  • Daily Playing Users: The amount of page visitors and the percentage of users who are able to play the game.
  • Engagement: Average time players spends in game. Also shows how much time is spent on loading or ads.
  • Earnings: Ad-related metrics such as total earnings, or the distribution of impression types.
  • Error Scanner: Details for all of errors of the past 24 hours, updated hourly.
  • Player Feedback: Details on player rating and comments.

Definition of events

  •  โŒ› gameLoadingFinished() : Pretty self-explanatory, we’d say. We need this to track the loading progress of your game and show your conversion to play.
  •  ๐ŸŽฎ gameplayStart() : Fires whenever the player starts interacting with the game (e.g. when the player starts moving around or clicks to interact with something.).
  •  โ˜  gameplayStop() : Fires whenever the gameplay halts (e.g. when the game is paused, the level is completed or when the player is dead).
  •  ๐ŸŽž commercialBreak() : Fires with the natural stops in the game (e.g. between levels, restarting a level, or basically any scenario where the player is about to go back into the gameplay stage).
  •  ๐ŸŽฌ rewardedBreak() : Fires with user prompt in exchange for an in-game reward (e.g. unlocking gold or bonus items, revival after death, or any scenario where you can convince the player to watch an ad).

Example order of events:

  • Startup:  โŒ› gameLoadingFinished()  >  ๐ŸŽฎ gameplayStart() 
  • Player dies and restarts:  โ˜  gameplayStop()  >  ๐ŸŽž commercialBreak()  >  ๐ŸŽฎ gameplayStart() 
  • Player dies and revives:  โ˜  gameplayStop()  >  ๐ŸŽฌ rewardedBreak()  >  ๐ŸŽฎ gameplayStart() 
  • Player goes to next level:  โ˜  gameplayStop()  >  ๐ŸŽž commercialBreak()  >  ๐ŸŽฎ gameplayStart() 
  • Player goes to next level with double rewards:  โ˜  gameplayStop()  >  ๐ŸŽฌ rewardedBreak()  >  ๐ŸŽฎ gameplayStart() 
  • Player pauses / unpauses:  โ˜  gameplayStop()  >  ๐ŸŽฎ gameplayStart() 

Note: if an ad is fired when gameplay is not interrupted (for example if the player watches an ad to unlock a character skin), it’s not necessary to fire a  โ˜  gameplayStop()  or  ๐ŸŽฎ gameplayStart()  event.

Testing of events

Our Inspector is designed to help test your game and the implementation of the SDK events easily. Simply drag and drop your game folder that contains an index.html file and you’re set.

The tool will run the game as if it’s live on the platform, so you can test the game’s behavior on any device or browser. The tool also outputs the event log, so you can check if the SDK events are firing correctly.

Versioning with CLI

The Poki for Developers command line utility allows you to upload game builds directly from your terminal or CI-pipeline. Please check our Github repository for more information on installation.

Full examples

If you’d like to see a full example of the SDK implementation for each game engine, check these links out:

HTML
function init() {
    PokiSDK.init().then(startLoading)

    // remove this line in your production build
    PokiSDK.setDebug(true);
};

function startLoading() {
    // Load the game!

    // When all files are loaded
    loadingComplete();
};

function loadingComplete() {
    // We're done loading!
    PokiSDK.gameLoadingFinished();

    // Lets start playing after the initial commercial break
    PokiSDK.commercialBreak().then(() => {
        PokiSDK.gameplayStart();
        startGame();
    });
};

function startGame() {
    console.log("Starting a new round!");

    // .. user plays for a while

    // We died!
    onDeath();
};

function onDeath() {
    // Lets run the on death code: but we can get one more shot by watching a rewarded video
    PokiSDK.gameplayStop();

    if(canRevive){
        // we have the option to revive! (usually this is on a button in the game over screen)
        PokiSDK.rewardedBreak(() => {
            // if the ad loads and will show pause the game and mute the menu music
            pauseGame();
        }).then((withReward) => {
            // when the ad is completed, skipped or did not play we run this code
            if (withReward) {
                // withReward is a boolean that you receive that indicates wether a user actually finished the video correctly
                console.log("Revive!");
                PokiSDK.gameplayStart();

                canRevive = false;
                revive();
            } else{
                // User skipped the video, not entitled to a reward
                restartLevel()
            }
        });
    } else {
        // if we can't revive we just restart
        restartLevel()
    }
}

function restartLevel() {
    // we failed the level, letโ€™s close this gameplay session and trigger a break

    PokiSDK.gameplayStop();

    // we closed the gameplay now letโ€™s trigger the break
        PokiSDK.commercialBreak(() => {
            // if we actually start showing an ad, pause the game ( this function also mutes the game music)
        pauseGame();
    }).then(() => {
            // when the ad is completed, or we didn't show an ad run this code
        PokiSDK.gameplayStart();
        unMuteSound();
        startLevel();
    });

};

function pauseGame() {
    console.log("Starting break");
    museAudio();
    disableKeyboardInput();
};

function unPauseGame() {
    console.log("Break completed");
    unMuteAudio();
    enableKeyboardInput();
};
    
Unity
using UnityEngine;

public class Game : MonoBehaviour {
    public void Awake () {
        // Initialize SDK
        PokiUnitySDK.Instance.init();
        StartLoading();
    }

    public void StartLoading() {
        // Load the game!

        // [...loading logic goes here...]

        // When all files are loaded
        OpenMainMenu();
    }

    public void OpenMainMenu(){
        gamePause(); // we mute audio and stop gameplay here
        if(!PokiUnitySDK.Instance.adsBlocked()){
            PokiUnitySDK.Instance.commercialBreakCallBack = StartGame; // after the commercial break we trigger StartGame
            PokiUnitySDK.Instance.commercialBreak();
        }else StartGame();
    }

    public void StartGame() {
        Debug.Log("Starting a new round!");
        PokiUnitySDK.Instance.gameplayStart();

        //[... do all the gameplay stuff];

        // We died but we can get one more shot by watching a rewarded video
        if(PokiUnitySDK.Instance.adsBlocked()){
            //hide the rewarded video
        }else{
            PokiUnitySDK.Instance.rewardedBreakCallBack = RevivePlayer;
            PokiUnitySDK.Instance.rewardedBreak();
        }

        // ahh we died again, letโ€™s restart
        RestartLevel();
    }

    public void RevivePlayer(bool withReward){
        if(withReward){
            Debug.Log("Revive!");
            //resume game
        }else{
            //exit level
        }
    }

    public void RestartLevel(){
        // we failed the level, letโ€™s close this gameplay session and trigger a break
        gamePause();
        PokiUnitySDK.Instance.gameplayStop();
        // we closed the gameplay now letโ€™s trigger the break

        if(!PokiUnitySDK.Instance.adsBlocked()){
            PokiUnitySDK.Instance.commercialBreakCallBack = StartGame; // after the commercial break we trigger StartGame
            PokiUnitySDK.Instance.commercialBreak();
        }else StartGame();
    }

    public void gamePause() {
        Debug.Log("Starting break");
        //muteMusic();
        //pauseGamePlay();
    }

    public void continueGame() {
        Debug.Log("Break completed");
        //unMuteMusic();
        //resumeGameplay();
    }
}

GameMaker example project download

Phaser 3 Github repository