Skip to content
Random game

SDK reference

Last updated 2026-11-21

FreeGamesSdk connects your game to the FreeGames.gg page around it. The page shows the ads, keeps saves, and offers the next game. Your game tells it when it loads, when play starts and stops, and when there is a good moment for an ad. It is about 3.3 KB gzip and does no work until your game calls it.

Install

Pick one. All three give you the same object, with the same calls.

Script tag (any engine, no build step). It also sets up PokiSDK, CrazyGames.SDK and Google’s adBreak for ported games:

<script src="https://games.foony.com/sdk/v1.js"></script>

ES module from FreeGames.gg:

import FreeGamesSdk from 'https://games.foony.com/sdk/v1.mjs';

npm package with its types, for a bundler (Vite, webpack, esbuild):

npm install https://games.foony.com/sdk/freegames-sdk.tgz
import FreeGamesSdk from 'freegames-sdk';

For TypeScript with the script tag, download the types: https://games.foony.com/sdk/v1.d.ts. They declare window.FreeGamesSdk.

The script and the module load from FreeGames.gg, so your game gets SDK fixes without a new build. Prefer them. A bundled copy works too, but keeps the version it was built with. v1 never breaks: a change that would break games gets a new address (v2). sdk.version says which one runs, for example "1.2.0".

The examples below call it sdk:

const sdk = window.FreeGamesSdk;

window.FreeGamesSDK (the name before 1.1.0) still works.

How the calls behave

  • Every call is safe at any time. Calls made before init() has answered wait for it.
  • No call ever throws or rejects. Calls that return a promise always resolve. When a call can’t do what you asked (a bad key, a score the board refused), it resolves with false or null and the browser console says why, starting with [FreeGamesSdk].
  • Local mode. When your game isn’t on a FreeGames.gg page (you opened index.html on your computer), init() resolves at once with isConnected: false. Breaks finish at once with no ad, rewardedBreak() resolves {rewarded: false}, and saves stay in your browser’s localStorage, so you can build and test without an account. Boards need a page. For test ads, boards and the event log, open your game in the Inspector.
  • In a frame whose page never answers (another site), init() waits 3 seconds, then runs in local mode.

Order of calls

When Call
Your game starts init(), then loadingStart()
While loading loadingProgress(0.5) (0 to 1)
Ready for input loadingFinished()
Play starts (a level, a match) gameplayStart()
Play stops (a menu, game over, pause) gameplayStop()
A match or run ended gameEnd('win')
A natural break (between levels, after a match) commercialBreak()
The player asks for a reward rewardedBreak()

The SDK warns in the browser console when you call gameplayStart() twice in a row, or gameplayStop() with no start before it. The events page shows the order for common moments, like a revive or the next level.

init()

Starts the SDK. Call it once, as soon as your game starts. On FreeGames.gg the page answers within a few milliseconds. In local mode it resolves at once.

const settings = await sdk.init();
if (settings.isMuted) {
  muteMyGame();
}

It resolves with:

Field Meaning
isConnected true inside FreeGames.gg, false when your game runs on its own
playerToken A token that names the signed-in player to your server, or null for a guest. It is never a login and lasts 5 minutes. See Know the player
locale The page’s language, like "en"
isMobile true on a phone or tablet (a touch screen is the main input)
isMuted true when the page’s sound is off. Start muted then
pageUrl Your game’s page on FreeGames.gg, with no query, like "https://games.foony.com/game/block-drop"
version The page’s protocol version, now 1 (the SDK’s own version is sdk.version)
gameToken, accountLink Only for Foony’s own games. Always null for yours

loadingStart()

Tells the page loading started. Call it right after init().

sdk.loadingStart();

loadingProgress(progress)

Tells the page how far loading is, from 0 to 1. The page shows it as a bar over the game. Numbers outside 0 to 1 are clamped.

loader.onProgress = (loaded, total) => sdk.loadingProgress(loaded / total);

loadingFinished()

Tells the page the game is ready for input. The page hides its loading bar, and your load time stops here.

sdk.loadingFinished();

gameplayStart()

Tells the page play started: a level, a match, a run. Your gameplay time counts from here, and no ad shows until gameplayStop(). Active play between these two calls is also what earns players XP.

function startLevel() {
  sdk.gameplayStart();
  level.start();
}

gameplayStop()

Tells the page play stopped: a menu, a pause, a game over, a level end.

function openPauseMenu() {
  sdk.gameplayStop();
  pauseMenu.show();
}

gameEnd(result)

Tells the page a match or run ended. result is 'win', 'loss', 'draw', or nothing. About a second later, the page shows a card beside your game with the XP the player earned and games to play next, so your own result screen shows first. The card hides when you call gameplayStart() again.

sdk.gameplayStop();
sdk.gameEnd('win');

Call it when a whole match or run ends, not after every level of a level-based game. Each call shows the card of next games. A gameEnd() also ends the player’s first game for the ad rules, so the next break may show an ad.

commercialBreak(onStart)

Asks for an interstitial ad at a natural break. The site’s ad rules decide if one shows, so call it at every break. It resolves {shown: true} when the ad is over, or {shown: false} at once when no ad shows. onStart runs only if an ad really starts.

sdk.gameplayStop();
await sdk.commercialBreak(() => muteMyGame());
unmuteMyGame();
sdk.gameplayStart();

When no ad starts within 8 seconds, it resolves with no ad, so your game never waits longer than that.

rewardedBreak(onStart)

Asks for an opt-in rewarded ad, when the player chose to watch one. It resolves {rewarded: true} only when the player watched the whole ad. No ad, an ad blocker, or a closed ad resolve {rewarded: false}. Give no reward then.

const {rewarded} = await sdk.rewardedBreak(() => muteMyGame());
unmuteMyGame();
if (rewarded) {
  giveExtraLife();
}

Supporters and players under 13 see no ads. For them it resolves {rewarded: true} at once.

happyTime()

Tells the page about a big moment: a win, a new record. The page shows a short “Nice one!” note over the game.

sdk.happyTime();

save.get(key)

Reads a save. Resolves with the saved text, or null when there is none. For a signed-in player the save comes from their Foony account, for a guest from their browser. Call it once while your game loads.

const text = await sdk.save.get('progress');
const progress = text ? JSON.parse(text) : {level: 1};

save.set(key, value)

Keeps text under a key. Resolves true when it was kept, false when it wasn’t (over a limit, or the save couldn’t be written). Keys are 1 to 64 characters. One game keeps up to 1,000,000 characters and 1,000 keys per player. A signed-in player’s saves go to their Foony account, at most one write a second. A guest’s stay in their browser and move to the account when they sign in. See Cloud save.

await sdk.save.set('progress', JSON.stringify({level: 4, coins: 120}));

leaderboard.submitScore(boardId, score)

Sends a score to a board you declared in the dashboard. Resolves true when the board took it, and false for a guest, a score outside the board’s lowest and highest scores, a score inside its wait time, or a board id you didn’t declare. The console says which. See Leaderboards.

await sdk.leaderboard.submitScore('best', 1200);

leaderboard.getScores(boardId, options)

Reads a board’s ranking: {entries, player}. entries are the best players (rank, name, score), player is the signed-in player’s own rank and score, or null. options.period is 'daily', 'weekly' or 'allTime' (the default), and options.limit is 1 to 100 (10 by default).

const {entries, player} = await sdk.leaderboard.getScores('best', {period: 'daily', limit: 5});

progress.event(name, value)

Shows the player your game’s own progress. An xp event with a value above 0 shows a “+40 XP” note over the game. Other names are taken and not shown yet. Names are 1 to 64 characters.

sdk.progress.event('xp', 40);

It is your game’s own number: it adds no FreeGames.gg XP. See XP.

XP

Players earn FreeGames.gg XP from your game for active play: the time between gameplayStart() and gameplayStop() while the player is really playing. The page checks it, and the game server counts it:

  • A second counts only while the page is visible, your game’s frame has focus, and the player pressed a key, clicked, tapped or scrolled in your game in the last 15 seconds. An idle game earns nothing. Gamepad input isn’t seen yet.
  • Each active minute gives 8 account XP (the player’s Foony level, shared with foony.com) and 24 XP to your game’s own level on FreeGames.gg. That is a little under the median rate of Foony’s own games.
  • The first 120 active minutes a day count, across all games from developers. Players see this cap on the end card and their account page.
  • Play time pays no coins.

You don’t call anything extra: keep gameplayStart() and gameplayStop() right. The Inspector shows when they fire.

achievement.unlock(id, name)

Reports an unlocked achievement. The page shows an “Achievement unlocked” note. id is 1 to 64 characters, name up to 80.

sdk.achievement.unlock('first-win', 'First win');

invite.getLink(roomId)

Resolves with a link to your game’s page that joins roomId, or null with no page. Room ids are 1 to 64 letters, numbers, - or _. A player who opens the link gets your game with ?room=<roomId> in its address.

const link = await sdk.invite.getLink('room-42');
showShareBox(link);

const roomId = new URLSearchParams(location.search).get('room');
if (roomId) {
  joinRoom(roomId);
}

pause.onPause(listener) and pause.onResume(listener)

The page asks your game to pause while an ad plays, and to go on after it. Each one returns a function that stops listening.

sdk.pause.onPause(() => pauseMyGame());
sdk.pause.onResume(() => resumeMyGame());

audio.onMuteChange(listener)

Calls listener with true when the page’s sound goes off, and false when it comes back on. Returns a function that stops listening.

const stop = sdk.audio.onMuteChange((isMuted) => setMyVolume(isMuted ? 0 : 1));

error.log(message)

Adds a line to your game’s error list. Uncaught errors and unhandled promise rejections are sent on their own, so use this for problems your game catches itself.

try {
  await loadLevel(3);
} catch (error) {
  sdk.error.log(`level 3 failed to load: ${error}`);
}

The SDK sends the first 20 errors and lines per page load, each cut to 300 characters. It only sees errors that happen after its script runs, which is why the script tag goes before your own scripts.

Player text

filterText(text) resolves with the text a player typed as other players may see it: Foony’s chat filter swaps bad words and takes out outside links. Show what it resolves with, never the text as typed. It resolves with null when the text couldn’t be checked (offline, more than 500 characters, in local mode): then show nothing. Never rejects. Test it in the inspector, which uses the real filter.

A game MUST send every typed text that other players see through it: chat, player names, level or team names (rule 12). Text only the typing player sees doesn’t need it.

const shown = await sdk.filterText(chatInput.value);
if (shown !== null) {
  sendToOtherPlayers(shown);
}

Calls for Foony’s own games

foony.gameToken(), foony.linkAccount() and foony.setAdFree() are for Foony’s own games, which use this same SDK. A game token is worth a login and the ad-free notice turns the page’s ads off, so the page answers them only for Foony’s games: for yours foony.gameToken() resolves null and the other two do nothing. destroy() stops the SDK listening to the page. Your game doesn’t need it.

Other SDKs in the same script

The script also sets up PokiSDK, CrazyGames.SDK and Google’s adBreak and adConfig, mapped to the calls above. A game built for one of them runs after you swap the script tag. See Coming from Poki, Coming from CrazyGames and Google’s Ad Placement API.