Skip to content

sud.createRewardedVideoAd ​

Creates a rewarded video ad object. Each call returns a new instance.

typescript
createRewardedVideoAd(params: {
    adUnitId: string;
    /** Whether to enable multiton mode, defaults to true (reserved parameter, not yet in effect) */
    multiton?: boolean;
    /** Whether to disable the fallback share page, defaults to false (reserved parameter, not yet in effect) */
    disableFallbackSharePage?: boolean;
}): RewardedVideoAd;

Parameters ​

Object object ​

PropertyTypeRequiredDescription
adUnitIdstringYesAd unit ID configured in the SUD OpenPaaS console
multitonbooleanNoWhether to enable multiton mode, defaults to true (reserved parameter, not yet in effect)
disableFallbackSharePagebooleanNoWhether to disable the fallback share page, defaults to false (reserved parameter, not yet in effect)

Return Value ​

RewardedVideoAd ad object.

Methods ​

MethodReturn valueDescription
load()Promise<void>Starts loading the ad
show()Promise<void>Requests that the ad be shown
destroy()voidDestroys the ad; the object cannot be reused

The Promises returned by load() and show() report only the method-call result. Use onLoad for successful loading, onError for loading or display failures, and onClose for closing.

load() is subject to request frequency limits. When a limit is reached, onError reports the error code (errCode) and message (errMsg).

Events ​

MethodDescription
onLoad(listener)Listens for a successful ad load
offLoad(listener)Removes the specified load listener
onError(listener)Listens for ad loading or display failures
offError(listener)Removes the specified error listener
onClose(listener)Listens for the ad to close
offClose(listener)Removes the specified close listener

onLoad Callback Parameters ​

The onLoad listener receives the following object:

PropertyTypeDescription
useFallbackSharePagebooleanWhether the rewarded ad share page is used for this display (reserved parameter, not yet in effect)

onError Callback Parameters ​

The onError listener receives the following object:

PropertyTypeDescription
errCodenumberSee ad error codes
errMsgstringError message

onClose Callback Parameters ​

The onClose listener receives the following object:

PropertyTypeDescription
isEndedbooleanWhether this ad met the reward condition

true can enter the game's reward flow, while false must not grant a reward. Closing alone is not a reward signal. Handle the reward result at most once per display.

Example ​

Create and load the ad on reward-scene entry. Call onRewardButtonClick() only after the user clicks the watch-ad button; grant the reward only when onClose returns isEnded === true.

javascript
const rewardedVideoAd = sud.createRewardedVideoAd({
    adUnitId: 'adunit-xxxxxxxx',
    // Reserved parameters, not yet in effect
    multiton: true,
    disableFallbackSharePage: false,
});

let ready = false;
let disposed = false;
let showRequested = false;

function onLoad(res) {
    if (disposed) return;
    // res.useFallbackSharePage is a reserved parameter, not yet in effect
    ready = true;
}

function onError(err) {
    if (disposed) return;
    console.error('Rewarded video ad failed', err);
    onRewardSceneExit();
}

function onClose(result) {
    if (disposed) return;
    onRewardSceneExit();
    if (result?.isEnded === true) {
        console.log('Reward condition met');
        // Apply the game's reward once here.
    }
}

function onRewardButtonClick() {
    if (disposed || !ready || showRequested) return;
    showRequested = true;
    ready = false;
    rewardedVideoAd.show().catch(onError);
}

function onRewardSceneExit() {
    if (disposed) return;
    disposed = true;
    ready = false;
    rewardedVideoAd.offLoad(onLoad);
    rewardedVideoAd.offError(onError);
    rewardedVideoAd.offClose(onClose);
    rewardedVideoAd.destroy();
}

rewardedVideoAd.onLoad(onLoad);
rewardedVideoAd.onError(onError);
rewardedVideoAd.onClose(onClose);
rewardedVideoAd.load().catch(onError);

Bind onRewardSceneExit() to scene exit. For the complete flow, see game developer examples.