SDK docs
JavaScript API
One SDK for the website, partner embeds and the PlayKovo app. Keep your ad, pause and audio code behind these methods and the same build behaves correctly everywhere.
Core methods
- init()
- Initializes the bridge once during game boot and resolves with SDK status.
- showInterstitial()
- Requests a midgame ad at a natural break, then calls onClose or onError.
- showRewarded()
- Requests an optional reward flow. Grant only when onReward fires.
- cloudSave.get() / .set()
- Reads or writes save data tied to the signed-in player's PlayKovo account.
- on("pause") / on("resume")
- The platform paused or resumed your game (app menu, ad, hidden tab, app in background).
- on("mute") / on("unmute")
- The player's sound button, or an ad that needs silence.
- gameplayStart() / gameplayStop()
- Brackets the moments the player is actually playing.
- loadingStart() / loadingFinished()
- Your own loading screen is up / the game is playable.
- getStatus()
- Returns status, environment (web, native, local), paused, muted, sdkVersion, ready, testMode, and localPreview.
Pause and resume
PlayKovo pauses your game while an ad is on screen, while the player has the PlayKovo app menu open, while the browser tab is hidden and while the app is in the background. Stop your game loop, timers and physics on pause and continue on resume. Several reasons can overlap; you only hear pause on the first and resume when the last one clears. The payload's reason is "ad", "menu", "hidden", "background" or "platform".
window.PlayKovoSDK.on("pause", ({ reason }) => {
game.paused = true; // stop updating the world
music.pause();
});
window.PlayKovoSDK.on("resume", () => {
game.paused = false;
lastFrameTime = performance.now(); // avoid one huge delta after the pause
music.play();
});Subscribing is a promise
Sound
The PlayKovo player and app have a sound button. Route all of your audio through one master volume and follow mute / unmute (or the combined audio event). Ads also mute your game for their duration. isMuted() returns the current state, which is useful when you create audio late.
window.PlayKovoSDK.on("audio", ({ muted }) => {
masterGain.gain.value = muted ? 0 : 1;
});
if (window.PlayKovoSDK.isMuted()) masterGain.gain.value = 0;Keep your own in-game sound toggle if you have one; apply both: sound plays only when neither the player nor PlayKovo muted it.
Ad lifecycle events
adStarted fires when an ad takes over the screen and adFinished when it is gone, with adType and the final status. You do not need them for pausing (pause/resume already covers ads), but they are the right place for ad-specific UI such as hiding a "Watch ad" spinner.
window.PlayKovoSDK.on("adStarted", ({ adType }) => hideRewardSpinner());
window.PlayKovoSDK.on("adFinished", ({ adType, status }) => analytics.track("ad", { adType, status }));Gameplay and loading
Call gameplayStart() when the player starts or resumes actually playing (a run, a level, a match) and gameplayStop() when they reach a menu, shop, pause or result screen. PlayKovo uses this to keep its own interface out of the way during play and to avoid interrupting active gameplay. Calling either twice in a row is harmless.
function startLevel() { window.PlayKovoSDK.gameplayStart(); /* ... */ }
function onLevelComplete() {
window.PlayKovoSDK.gameplayStop();
window.PlayKovoSDK.showInterstitial({ placement: "level_complete", onClose: showResults, onError: showResults });
}If your game draws its own loading screen, call loadingStart() as soon as it is visible and loadingFinished() once the game is interactive. The app then hides its own cover immediately instead of showing two loaders.
window.PlayKovoSDK.loadingStart();
await loadAssets();
window.PlayKovoSDK.loadingFinished();window.PlayKovoSDK.init()
Returns a promise resolving to an immutable status object: status, ready, testMode, localPreview, and sdkVersion. Await it once during game boot, before you touch ads or save data.
const status = await window.PlayKovoSDK.init();
if (status.ready) startMainMenu();A minimal but complete boot sequence looks like this — init the bridge, load any existing save, then start the menu regardless of whether the bridge came up in live or local preview mode:
async function boot() {
const status = await window.PlayKovoSDK.init();
console.log("PlayKovo SDK ready:", status.sdkVersion, "local preview:", status.localPreview);
const save = await window.PlayKovoSDK.cloudSave.get();
applySaveData(save.ok ? save.data : loadLocalFallback());
startMainMenu();
}
boot();Don't block on init
Storage and utility methods
Use PlayKovoSDK.storage (or the compatibility alias localStorage) for string key/value saves. getLanguage returns the browser language; updateScore, updateLevel, and happyMoment are safe lifecycle hooks for future reporting.
window.PlayKovoSDK.storage.setItem("save-slot", JSON.stringify(saveData));
const saved = window.PlayKovoSDK.storage.getItem("save-slot");
const language = window.PlayKovoSDK.getLanguage();
window.PlayKovoSDK.updateLevel(8);
window.PlayKovoSDK.happyMoment("boss_defeated");window.PlayKovoSDK.showInterstitial(options)
Requests an interstitial at a natural break. Options require placement and can include onClose and onError. The promise resolves to shown or unavailable. Always resume gameplay from onClose (or onError), never assume the call resolved immediately.
const result = await window.PlayKovoSDK.showInterstitial({
placement: "level_complete",
onClose: continueGame,
onError: continueGame,
});Naming placements after the moment they fire in (not "ad1", "ad2") makes them easier to reason about later, and lets us tune frequency per placement instead of globally:
// Between levels
await window.PlayKovoSDK.showInterstitial({ placement: "level_complete", onClose: loadNextLevel, onError: loadNextLevel });
// After a game-over screen, before the retry button becomes active
await window.PlayKovoSDK.showInterstitial({ placement: "game_over", onClose: enableRetryButton, onError: enableRetryButton });
// When the player opens the pause menu
await window.PlayKovoSDK.showInterstitial({ placement: "pause_menu_open", onClose: renderPauseMenu, onError: renderPauseMenu });Cooldowns are enforced server-side
window.PlayKovoSDK.showRewarded(options)
Requests an optional rewarded flow. onReward fires once only after the approved rewarded flow completes. onClose fires after a successful rewarded completion; onError covers unavailable and failed requests.
await window.PlayKovoSDK.showRewarded({
placement: "continue_run",
onReward: () => grantContinue(),
onClose: () => closePauseMenu(),
onError: () => showContinueUnavailable(),
});A common pattern: offer the reward, but only enable the "Watch ad" button once the SDK reports it's actually available — otherwise you're showing a dead button:
function renderContinueScreen() {
const capabilities = window.PlayKovoSDK.getCapabilities();
continueButton.disabled = !capabilities.rewarded;
}
continueButton.addEventListener("click", async () => {
continueButton.disabled = true;
await window.PlayKovoSDK.showRewarded({
placement: "continue_run",
onReward: () => { playerHasContinue = true; },
onClose: () => resumeRun(),
onError: () => { continueButton.disabled = false; },
});
});Reward safety
window.PlayKovoSDK.cloudSave.get() / .set(data)
Reads or writes JSON-serializable save data tied to the player's PlayKovo account, so progress follows them across devices when they're signed in. Both methods resolve to a result object instead of throwing — always check ok before trusting the data.
// Load on boot
const save = await window.PlayKovoSDK.cloudSave.get();
if (save.ok && save.data) {
applySaveData(save.data);
} else {
applySaveData(loadLocalFallback());
}
// Write after a meaningful checkpoint (not every frame)
async function onLevelComplete(levelId, score) {
const result = await window.PlayKovoSDK.cloudSave.set({ levelId, score, updatedAt: Date.now() });
if (!result.ok) {
// Player likely isn't signed in, or is offline — fall back to storage so nothing is lost
window.PlayKovoSDK.storage.setItem("save-slot", JSON.stringify({ levelId, score }));
}
}Guest players still need a save path
Storage and utility methods
Use PlayKovoSDK.storage (or the compatibility alias localStorage) for string key/value saves scoped to the current device — this is the right default for anything that doesn't need to follow the player across devices, and the fallback for cloudSave when a player isn't signed in. getLanguage returns the browser language; updateScore, updateLevel, and happyMoment are safe lifecycle hooks for future reporting.
window.PlayKovoSDK.storage.setItem("save-slot", JSON.stringify(saveData));
const saved = window.PlayKovoSDK.storage.getItem("save-slot");
const language = window.PlayKovoSDK.getLanguage();
window.PlayKovoSDK.updateLevel(8);
window.PlayKovoSDK.happyMoment("boss_defeated");Localizing menu text from getLanguage, with a safe fallback for languages you haven't translated yet:
const supported = ["en", "tr", "es", "de"];
const detected = window.PlayKovoSDK.getLanguage();
const language = supported.includes(detected) ? detected : "en";
renderMenu(translations[language]);Status and events
Use getStatus(), getCapabilities(), and on(event, callback) for bridge state. isAdAvailable() reports whether the bridge is ready to make a request; the server still decides actual availability for every PlayKovo placement. A local preview is not an ad decision.
window.PlayKovoSDK.on("ready", (status) => {
console.log(status.sdkVersion);
});
const capabilities = window.PlayKovoSDK.getCapabilities();A small debug overlay some developers keep behind a query-string flag while integrating, so bridge state is visible without opening devtools:
if (new URLSearchParams(location.search).has("pkv_debug")) {
window.PlayKovoSDK.on("status", (status) => {
debugOverlay.textContent = `PlayKovo SDK: ${status.status} (v${status.sdkVersion}, local: ${status.localPreview})`;
});
}