poki-js-sdk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Poki JavaScript SDK

Poki JavaScript SDK

Integration Workflow

集成工作流

  1. Add the SDK script — embed or dynamically inject the Poki script tag.
  2. Initialize — call
    PokiSDK.init()
    and resolve
    gameLoadingFinished
    when the game is ready.
  3. Verify init — check the browser console for Poki SDK handshake messages; use the Poki Inspector dev tool to confirm the session started.
  4. Add lifecycle hooks — call
    gameplayStart
    /
    gameplayStop
    around every play session.
  5. Add ad breaks — insert
    commercialBreak
    at natural pause points; add
    rewardedBreak
    where the player can opt in.
  6. Test in Poki Inspector — open
    https://inspector.poki.io
    , load your game URL, and trigger each ad break to confirm the flow.
  1. 添加 SDK 脚本 — 嵌入或动态注入 Poki script 标签。
  2. 初始化 — 调用
    PokiSDK.init()
    ,并在游戏准备就绪时完成
    gameLoadingFinished
    。
  3. 验证初始化 — 检查浏览器控制台中的 Poki SDK 握手消息;使用 Poki Inspector 开发工具确认会话已启动。
  4. 添加生命周期钩子 — 在每次游玩会话前后调用
    gameplayStart
    /
    gameplayStop
    。
  5. 添加广告时段 — 在自然的暂停节点插入
    commercialBreak
    ;在玩家可以主动选择加入的位置添加
    rewardedBreak
    。
  6. 在 Poki Inspector 中测试 — 打开
    https://inspector.poki.io
    ,加载你的游戏 URL,并触发每个广告时段以确认流程正常。

Installation

安装

Add the official Poki SDK script to your page:
html
<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js"></script>
Or inject it dynamically:
js
function loadPokiSdk() {
    return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = 'https://game-cdn.poki.com/scripts/v2/poki-sdk.js';
        script.onload = resolve;
        script.onerror = reject;
        document.head.appendChild(script);
    });
}
将官方 Poki SDK 脚本添加到页面中:
html
<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js"></script>
也可以动态注入:
js
function loadPokiSdk() {
    return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = 'https://game-cdn.poki.com/scripts/v2/poki-sdk.js';
        script.onload = resolve;
        script.onerror = reject;
        document.head.appendChild(script);
    });
}

Initialization

初始化

js
loadPokiSdk()
    .then(() => window.PokiSDK.init())
    .then(() => {
        // SDK is ready
        window.PokiSDK.gameLoadingFinished();
    })
    .catch(() => {
        // SDK init failed - continue without Poki integration
        window.PokiSDK && window.PokiSDK.gameLoadingFinished();
    });
Call
gameLoadingFinished
when the game is ready for the player. If your loader has discrete phases, bracket them with
gameLoadingStart
and
gameLoadingFinished
.
js
loadPokiSdk()
    .then(() => window.PokiSDK.init())
    .then(() => {
        // SDK is ready
        window.PokiSDK.gameLoadingFinished();
    })
    .catch(() => {
        // SDK init failed - continue without Poki integration
        window.PokiSDK && window.PokiSDK.gameLoadingFinished();
    });
游戏可供玩家开始时,调用
gameLoadingFinished
。如果加载器包含多个明确的阶段,可以使用
gameLoadingStart
和
gameLoadingFinished
包围这些阶段。

Advertisement

广告

Interstitial

插屏广告

Use the
isOpened
flag to detect whether an ad was actually delivered — the callback is not invoked when no ad is shown.
js
function showInterstitial() {
    let isOpened = false;

    window.PokiSDK.commercialBreak(() => {
        isOpened = true;
        // Pause game, mute audio
    })
        .then(() => {
            if (isOpened) {
                // Resume game, unmute audio
            } else {
                // Ad was not shown
            }
        })
        .catch(() => {
            // Ad request failed
        });
}
使用
isOpened
标志检测是否实际展示了广告——未展示广告时不会调用回调。
js
function showInterstitial() {
    let isOpened = false;

    window.PokiSDK.commercialBreak(() => {
        isOpened = true;
        // Pause game, mute audio
    })
        .then(() => {
            if (isOpened) {
                // Resume game, unmute audio
            } else {
                // Ad was not shown
            }
        })
        .catch(() => {
            // Ad request failed
        });
}

Rewarded

激励广告

rewardedBreak
resolves with a boolean — grant the reward only when both
isOpened
is true and the resolved value is truthy.
js
function showRewarded() {
    let isOpened = false;

    window.PokiSDK.rewardedBreak(() => {
        isOpened = true;
        // Pause game, mute audio
    })
        .then((success) => {
            if (isOpened) {
                if (success) {
                    // Grant reward to the player
                }
                // Resume game, unmute audio
            } else {
                // Ad was not shown
            }
        })
        .catch(() => {
            // Ad request failed
        });
}
rewardedBreak
解析后返回布尔值——仅当
isOpened
为 true 且解析结果为 truthy 时,才发放奖励。
js
function showRewarded() {
    let isOpened = false;

    window.PokiSDK.rewardedBreak(() => {
        isOpened = true;
        // Pause game, mute audio
    })
        .then((success) => {
            if (isOpened) {
                if (success) {
                    // Grant reward to the player
                }
                // Resume game, unmute audio
            } else {
                // Ad was not shown
            }
        })
        .catch(() => {
            // Ad request failed
        });
}

Lifecycle

生命周期

Call
gameplayStart
when the player gains control (level start, level resume) and
gameplayStop
when control is taken away (level paused, completed, failed, or returning to a menu). Pair every
gameplayStart
with a matching
gameplayStop
.
js
function onLevelStart() {
    window.PokiSDK.gameplayStart();
}

function onLevelEnd() {
    window.PokiSDK.gameplayStop();
}
当玩家获得控制权时(关卡开始、关卡继续),调用
gameplayStart
;当玩家失去控制权时(关卡暂停、完成、失败或返回菜单),调用
gameplayStop
。每次
gameplayStart
都应与对应的
gameplayStop
配对。
js
function onLevelStart() {
    window.PokiSDK.gameplayStart();
}

function onLevelEnd() {
    window.PokiSDK.gameplayStop();
}

Testing & Verification

测试与验证

  • Open Poki Inspector at
    https://inspector.poki.io
    and load your game URL to get a developer session.
  • The browser console will print Poki SDK handshake and event messages — confirm
    init
    resolves and
    gameLoadingFinished
    is acknowledged.
  • Trigger
    commercialBreak
    and
    rewardedBreak
    via the Inspector UI to simulate ad delivery and verify pause/resume logic fires correctly.
  • Confirm
    gameplayStart
    and
    gameplayStop
    events appear in the Inspector timeline at the correct moments.

Notes on omitted features: this skill does not cover server time, ad-block detection,
happyTime
, or
gameInteractive
; keep the implementation focused on the Poki SDK features listed above.
  • 在
    https://inspector.poki.io
    打开 Poki Inspector,并加载你的游戏 URL,以获取开发者会话。
  • 浏览器控制台将打印 Poki SDK 握手和事件消息——确认
    init
    已完成解析,且
    gameLoadingFinished
    已被确认。
  • 通过 Inspector UI 触发
    commercialBreak
    和
    rewardedBreak
    ,以模拟广告展示,并验证暂停和恢复逻辑能够正确执行。
  • 确认
    gameplayStart
    和
    gameplayStop
    事件在正确的时间点出现在 Inspector 时间线中。

关于未包含功能的说明:本 skill 不涵盖服务器时间、广告拦截检测、
happyTime
或
gameInteractive
;实现应聚焦于上述 Poki SDK 功能。