poki-js-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePoki JavaScript SDK
Poki JavaScript SDK
Integration Workflow
集成工作流
- Add the SDK script — embed or dynamically inject the Poki script tag.
- Initialize — call and resolve
PokiSDK.init()when the game is ready.gameLoadingFinished - Verify init — check the browser console for Poki SDK handshake messages; use the Poki Inspector dev tool to confirm the session started.
- Add lifecycle hooks — call /
gameplayStartaround every play session.gameplayStop - Add ad breaks — insert at natural pause points; add
commercialBreakwhere the player can opt in.rewardedBreak - Test in Poki Inspector — open , load your game URL, and trigger each ad break to confirm the flow.
https://inspector.poki.io
- 添加 SDK 脚本 — 嵌入或动态注入 Poki script 标签。
- 初始化 — 调用 ,并在游戏准备就绪时完成
PokiSDK.init()。gameLoadingFinished - 验证初始化 — 检查浏览器控制台中的 Poki SDK 握手消息;使用 Poki Inspector 开发工具确认会话已启动。
- 添加生命周期钩子 — 在每次游玩会话前后调用 /
gameplayStart。gameplayStop - 添加广告时段 — 在自然的暂停节点插入 ;在玩家可以主动选择加入的位置添加
commercialBreak。rewardedBreak - 在 Poki Inspector 中测试 — 打开 ,加载你的游戏 URL,并触发每个广告时段以确认流程正常。
https://inspector.poki.io
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 when the game is ready for the player. If your loader has discrete phases, bracket them with and .
gameLoadingFinishedgameLoadingStartgameLoadingFinishedjs
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();
});游戏可供玩家开始时,调用 。如果加载器包含多个明确的阶段,可以使用 和 包围这些阶段。
gameLoadingFinishedgameLoadingStartgameLoadingFinishedAdvertisement
广告
Interstitial
插屏广告
Use the flag to detect whether an ad was actually delivered — the callback is not invoked when no ad is shown.
isOpenedjs
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
});
}使用 标志检测是否实际展示了广告——未展示广告时不会调用回调。
isOpenedjs
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
激励广告
rewardedBreakisOpenedjs
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
});
}rewardedBreakisOpenedjs
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 when the player gains control (level start, level resume) and when control is taken away (level paused, completed, failed, or returning to a menu). Pair every with a matching .
gameplayStartgameplayStopgameplayStartgameplayStopjs
function onLevelStart() {
window.PokiSDK.gameplayStart();
}
function onLevelEnd() {
window.PokiSDK.gameplayStop();
}当玩家获得控制权时(关卡开始、关卡继续),调用 ;当玩家失去控制权时(关卡暂停、完成、失败或返回菜单),调用 。每次 都应与对应的 配对。
gameplayStartgameplayStopgameplayStartgameplayStopjs
function onLevelStart() {
window.PokiSDK.gameplayStart();
}
function onLevelEnd() {
window.PokiSDK.gameplayStop();
}Testing & Verification
测试与验证
- Open Poki Inspector at and load your game URL to get a developer session.
https://inspector.poki.io - The browser console will print Poki SDK handshake and event messages — confirm resolves and
initis acknowledged.gameLoadingFinished - Trigger and
commercialBreakvia the Inspector UI to simulate ad delivery and verify pause/resume logic fires correctly.rewardedBreak - Confirm and
gameplayStartevents appear in the Inspector timeline at the correct moments.gameplayStop
Notes on omitted features: this skill does not cover server time, ad-block detection, , or ; keep the implementation focused on the Poki SDK features listed above.
happyTimegameInteractive- 在 打开 Poki Inspector,并加载你的游戏 URL,以获取开发者会话。
https://inspector.poki.io - 浏览器控制台将打印 Poki SDK 握手和事件消息——确认 已完成解析,且
init已被确认。gameLoadingFinished - 通过 Inspector UI 触发 和
commercialBreak,以模拟广告展示,并验证暂停和恢复逻辑能够正确执行。rewardedBreak - 确认 和
gameplayStart事件在正确的时间点出现在 Inspector 时间线中。gameplayStop
关于未包含功能的说明:本 skill 不涵盖服务器时间、广告拦截检测、 或 ;实现应聚焦于上述 Poki SDK 功能。
happyTimegameInteractive