SDK reference
Every call in goof.js version 1.0.0. Load it from https://developer.goof.gg/sdk/v1/goof.js.
This page covers the SDK your game calls. To upload and submit builds from a terminal or CI, see API keys and the upload command.
Calls that take an options object also accept success, fail and complete callbacks, and return a promise as well.
Core
| Call | Result | Notes |
|---|---|---|
GOOF.game.init({ gameId?, mock? }) | Promise of { host, sdk, gameId, can: { rewarded, interstitial, pay, share, vibrate } } | host is android, ios, web, mock or none. Safe to call more than once. Other calls wait for it. |
GOOF.version | "1.0.0" | |
GOOF.compat() | Sets window.tt and window.TTMinis = { game: GOOF.game } when they are not defined, so code written for that style of API runs unchanged. |
Ads
| Call | Result | Notes |
|---|---|---|
GOOF.game.createRewardedVideoAd({ adUnitId }) | Ad object | See below. onClose gets { isEnded }. |
GOOF.game.createInterstitialAd({ adUnitId }) | Ad object | onClose gets {}. |
GOOF.ads.showRewarded({ adUnitId }) | Promise of { rewarded, error? } | Never rejects. |
GOOF.ads.showInterstitial({ adUnitId }) | Promise of { shown, error? } | Never rejects. |
Ad object
| Method | Notes |
|---|---|
load() | Promise. Rejects with { errMsg, errorCode }. |
show() | Resolves when the ad is on screen. Rejects with { errMsg, errorCode }. |
onLoad(cb) / offLoad(cb) | Ad loaded. |
onClose(cb) / offClose(cb) | Ad closed. Rewarded: { isEnded }, the reward decision. |
onError(cb) / offError(cb) | Gets { errMsg, errorCode }. |
destroy() | Frees the object. |
An off call with no argument removes all callbacks of that kind. An ad object can be shown again after it closed.
Purchases
| Call | Result |
|---|---|
GOOF.game.getProducts() | Promise of [{ sku, name, price_cents, type, priceLabel }] |
GOOF.game.requestPayment({ sku, success, fail, complete }) | Promise of { orderId, sku, state } |
GOOF.game.consumePurchase({ orderId }) | Promise of { ok } |
Lifecycle
| Call | Notes |
|---|---|
GOOF.game.onShow(cb) / GOOF.game.offShow(cb) | The game is active again, also after every ad or payment sheet. |
GOOF.game.onHide(cb) / GOOF.game.offHide(cb) | The game is inactive, also before every ad or payment sheet. |
GOOF.game.setLoadingProgress(p) | p from 0 to 1. |
GOOF.game.gameReady() | The first screen can be played. |
Player and storage
| Call | Result |
|---|---|
GOOF.game.login({ success, fail, complete }) | Promise of { code, anonymousId } |
GOOF.game.getStorage(key) | Promise of the value |
GOOF.game.setStorage(key, value) | Promise |
GOOF.game.removeStorage(key) | Promise |
GOOF.game.setUserCloudStorage({ KVDataList: [{ key, value }] }) | Promise |
GOOF.game.getUserCloudStorage({ keyList }) | Promise |
Storage is kept in the host's save for your game, under the key __goof.
Device and social
| Call | Notes |
|---|---|
GOOF.game.getSystemInfoSync() | { platform, language, screenWidth, screenHeight, pixelRatio, safeArea: { top, bottom, left, right }, SDKVersion, host } |
GOOF.game.vibrateShort() | |
GOOF.game.vibrateLong() | |
GOOF.game.shareAppMessage({ title }) | |
GOOF.game.reportScore(n) | |
GOOF.game.logEvent(name, params) |
Error codes
| Code | Meaning |
|---|---|
11001 | Missing or invalid adUnitId. |
11004 | Interstitial asked too soon. |
20001 | Ad unit unknown. |
20002 | Ad unit of another game. |
20003 | Ad unit paused. |
30001 | Closed before the end, no reward. |
30002 | No ad available. |
40001 | Not supported on this host. |
40002 | An ad is already showing. |
50000 | System error. |
60001 | Unknown product. |
60002 | Payment cancelled. |
60003 | Payment failed. |
Errors arrive as { errMsg, errorCode }.