TikTok for Developers

Developer Docs

Last updated October 1, 2026

In-App Ads

Create and control rewarded video and interstitial ad instances, with methods for showing ads, registering lifecycle callbacks (close, error), and handling ad error codes.

TTMinis.game.createRewardedVideoAd(opts)

Creates a rewarded video ad instance.

Parameters

Field

Type

Description

Required

adUnitId

string

The ad unit ID

Yes

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

TTMinis.game.createInterstitialAd(opts)

Note: Requires base library version 0.3.0 or later. Earlier versions require compatibility handling.

Creates an interstitial ad component.

Parameters

Field

Type

Description

Required

adUnitId

string

The ad unit ID

Yes

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

rewardedVideoAd

rewardedVideoAd.show()

Displays the rewarded video ad.

Returns

Returns a Promise representing the result of the rewarded video ad display operation.

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

rewardedVideoAd.show().then(() => {
  console.log('Rewarded video ad displayed');
}).catch(() => {
  console.log('Rewarded video ad display failed');
});

rewardedVideoAd.onClose(callback)

Listens for the close event of the rewarded video ad. Triggered when the ad is closed.

Parameters

Field

Type

Description

Required

callback

function

The listener function for the close event

Yes

Callback parameters

The callback receives an object with the following fields:

Field

Type

Description

isEnded

Boolean

Whether the video was closed after the user watched it completely

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

rewardedVideoAd.onClose((result) => {
  console.log('Rewarded video ad closed', result.isEnded);
});

rewardedVideoAd.offClose(callback)

Removes the listener function for the close event of the rewarded video ad.

Parameters

Field

Type

Description

Required

callback

function

The listener function passed to onClose. If not provided, removes all listener functions.

No

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('close event');
}

rewardedVideoAd.onClose(listener);
// Remove when no longer needed
rewardedVideoAd.offClose(listener);

rewardedVideoAd.onError(callback)

Listens for the error event of the rewarded video ad display. Triggered when the rewarded video display fails.

Parameters

Field

Type

Description

Required

callback

function

The listener function for the error event

Yes

Callback parameters

The callback receives an object with the following fields:

Field

Type

Description

errMsg

string

The error message

errorCode

int32

The error code

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('error emit');
}

rewardedVideoAd.onError(listener);

rewardedVideoAd.offError(callback)

Removes the listener function for the error event of the rewarded video ad.

Parameters

Field

Type

Description

Required

callback

function

The listener function passed to onError. If not provided, removes all listener functions.

No

Example

const rewardedVideoAd = TTMinis.game.createRewardedVideoAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('error emit');
}

rewardedVideoAd.onError(listener);
// Remove when no longer needed
rewardedVideoAd.offError(listener);

interstitialAd

interstitialAd.show()

Displays the interstitial ad.

Returns

Returns a Promise representing the result of the interstitial ad display operation.

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

interstitialAd.show().then(() => {
  console.log('Interstitial ad displayed');
}).catch(() => {
  console.log('Interstitial ad display failed');
});

interstitialAd.onClose(callback)

Listens for the close event of the interstitial ad. Triggered when the ad is closed.

Parameters

Field

Type

Description

Required

callback

function

The listener function for the close event

Yes

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

interstitialAd.onClose(() => {
  console.log('Interstitial ad closed');
});

interstitialAd.offClose(callback)

Removes the listener function for the close event of the interstitial ad.

Parameters

Field

Type

Description

Required

callback

function

The listener function passed to onClose. If not provided, removes all listener functions.

No

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('close event');
}

interstitialAd.onClose(listener);
// Remove when no longer needed
interstitialAd.offClose(listener);

interstitialAd.onError(callback)

Listens for the error event of the interstitial ad display. Triggered when the interstitial display fails.

Parameters

Field

Type

Description

Required

callback

function

The listener function for the error event

Yes

Callback parameters

The callback receives an object with the following fields:

Field

Type

Description

errMsg

string

The error message

errorCode

int32

The error code

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('error emit');
}

interstitialAd.onError(listener);

interstitialAd.offError(callback)

Removes the listener function for the error event of the interstitial ad.

Parameters

Field

Type

Description

Required

callback

function

The listener function passed to onError. If not provided, removes all listener functions.

No

Example

const interstitialAd = TTMinis.game.createInterstitialAd({
  adUnitId: 'YOUR_AD_UNIT_ID'
});

function listener() {
  console.log('error emit');
}

interstitialAd.onError(listener);
// Remove when no longer needed
interstitialAd.offError(listener);

Error codes

Init API

errorCode

subErrorCode

Description

11001


Ad unit ID is empty, invalid parameter

20000


Client request to backend failed

50000


System error

500


Server internal system error

10001


Ad unit validation parameter error

20001


Ad unit does not exist

20002


Ad unit and request mini game ID do not match

20003


Ad unit status is abnormal

20007


Ad unit type error

30001


Same ad unit requested too frequently

Show API

errorCode

subErrorCode

Description

10001


Ad instance ID parameter is empty, invalid parameter

11002


Ad instance ID does not match, cannot find the corresponding ad instance

11003


Ad instance has already been displayed, cannot be reused

11004


Insufficient interval since last play, not allowed to show interstitial ad

11005


Exceeded interstitial ad play count limit, not allowed to show interstitial ad

30001


User exited without watching completely (no reward earned)

50000


System error

50000

50101

Client network environment error

50000

50102-50107

Server error

TikTok for Developers