Skip to content

Funox SDK

AI Summary

A short gist of this page, generated for you.

Powered by AI. Summaries can miss nuance — when in doubt, read the page.

The Funox SDK is a single script that connects your game to Funox: gameplay signals, ads, the player, cloud saves, analytics and sharing.

Current version: 1.5.3

#Install

Add this to your game's index.html, before your game scripts:

html
<script src="https://funox.com/sdk/v1/funox-sdk.js"></script>

It defines one global object, FunOxSDK.

Load it from this exact URL

Include the script once, and do not ship your own copy of the file. The portal's upload check reports a missing, copied or duplicated SDK script, and the hosted file keeps receiving fixes.

Unity is the one exception: for Unity builds the script is added for you — see the Unity guide.

#Initialize

Call init() as early as possible, before loading assets or starting gameplay.

javascript
FunOxSDK.init()
  .then(function (result) {
    console.log('Game ID:', result.gameId);
    console.log('Mode:', result.mode); // 'iframe' on Funox, 'standalone' when opened directly
    startGame();
  })
  .catch(function (error) {
    console.error('SDK init failed:', error.code, error.message);
    startGame(); // always start the game
  });

init() resolves immediately and does not wait for the platform. Calling it again is safe — the SDK is not initialized twice.

#What init() returns

json
{
  "gameId": "abc123",
  "sessionToken": "temporary-session-id",
  "user": null,
  "features": {
    "saveEnabled": true,
    "adsEnabled": true,
    "leaderboardsEnabled": false
  },
  "mode": "iframe"
}
Field Description
gameId Your game's Funox id
sessionToken A temporary value. Do not store it or use it to identify a player
user Always null here. Use getUser()
features What is switched on: saveEnabled, adsEnabled, leaderboardsEnabled
mode 'iframe' on Funox, 'standalone' when the game is opened directly, 'native' when it is opened directly inside the Funox mobile app

#The four required calls

Every game must make these. The Developer Portal checks each one before a build can be submitted.

Call When
FunOxSDK.init() Once, at startup
FunOxSDK.gameplayStart() When active play begins
FunOxSDK.gameplayStop() When play ends or is interrupted
FunOxSDK.commercialBreak() At a natural break
javascript
FunOxSDK.init().then(startGame, startGame);

function onPlayPressed() {
  FunOxSDK.gameplayStart();
}

function onLevelComplete() {
  FunOxSDK.gameplayStop();
  pauseGame(); // stop the loop, mute audio

  FunOxSDK.commercialBreak()
    .catch(function () {})
    .then(function () {
      resumeGame();
      loadNextLevel();
    });
}

#Where the SDK runs

The same build runs in three places with no code changes:

Where the game runs What you get
Inside a Funox page Everything: the player, cloud saves, ads, platform events
Inside the Funox mobile app The same API. Ads are shown by the app itself
Opened directly by its own URL, or on localhost Standalone mode: the SDK still works, saves go to the browser, and there is no player account

#What the SDK covers

Area Calls Page
Gameplay signals gameplayStart, gameplayStop, happyTime, reportActivity Gameplay
Ads commercialBreak, rewardedBreak, isRewardedAdAvailable Ads
Player getUser, isLoggedIn, getLanguage Player
Saves saveProgress, loadProgress Save data
Leaderboards submitScore, getLeaderboard Leaderboards
Analytics trackEvent, trackMilestone Analytics
Sharing shareGame, shareResult, getShareUrl Sharing
Platform events on, off, offAll Platform events

#Configuration

configure() is optional and goes before init().

javascript
FunOxSDK.configure({ debug: true }); // log every SDK call to the console
FunOxSDK.init();
Option Type Default Description
debug boolean false Log SDK activity to the console. Remove before you submit
timeout number 30000 Request timeout in milliseconds. Ad calls always allow 120 seconds

#Properties and helpers

Name Type Description
FunOxSDK.version string SDK version, for example '1.5.3'
FunOxSDK.isInitialized boolean true once init() has run
FunOxSDK.mode string or null 'iframe', 'standalone', or null before init()
FunOxSDK.getGameId() string or null The game id the SDK is using
FunOxSDK.isInFunOx() boolean true when the game runs inside a host page, false when opened directly
FunOxSDK.destroy() — Removes listeners and rejects pending requests

#Advanced init() options

Games hosted on Funox should call init() with no arguments. These exist for special hosting setups only:

Option Type Description
gameId string Overrides the game id the SDK detects from the game's URL. A wrong value breaks analytics and ad revenue attribution for your game
adsInIframe boolean Set false to stop the SDK loading ads inside the game frame. On Funox the surrounding page serves them instead; in standalone mode no ads are shown
gtagId string Google Analytics measurement id used in standalone mode

#Next steps