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

CallResultNotes
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

CallResultNotes
GOOF.game.createRewardedVideoAd({ adUnitId })Ad objectSee below. onClose gets { isEnded }.
GOOF.game.createInterstitialAd({ adUnitId })Ad objectonClose gets {}.
GOOF.ads.showRewarded({ adUnitId })Promise of { rewarded, error? }Never rejects.
GOOF.ads.showInterstitial({ adUnitId })Promise of { shown, error? }Never rejects.

Ad object

MethodNotes
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

CallResult
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

CallNotes
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

CallResult
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

CallNotes
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

CodeMeaning
11001Missing or invalid adUnitId.
11004Interstitial asked too soon.
20001Ad unit unknown.
20002Ad unit of another game.
20003Ad unit paused.
30001Closed before the end, no reward.
30002No ad available.
40001Not supported on this host.
40002An ad is already showing.
50000System error.
60001Unknown product.
60002Payment cancelled.
60003Payment failed.

Errors arrive as { errMsg, errorCode }.