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 |
|
| 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 |
|
| 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 |
|
| The listener function for the close event | Yes |
Callback parameters
The callback receives an object with the following fields:
Field | Type | Description |
|
| 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 |
|
| The listener function passed to | 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 |
|
| The listener function for the error event | Yes |
Callback parameters
The callback receives an object with the following fields:
Field | Type | Description |
|
| The error message |
|
| 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 |
|
| The listener function passed to | 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 |
|
| 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 |
|
| The listener function passed to | 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 |
|
| The listener function for the error event | Yes |
Callback parameters
The callback receives an object with the following fields:
Field | Type | Description |
|
| The error message |
|
| 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 |
|
| The listener function passed to | 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 |
| Ad unit ID is empty, invalid parameter | |
| Client request to backend failed | |
| System error | |
| Server internal system error | |
| Ad unit validation parameter error | |
| Ad unit does not exist | |
| Ad unit and request mini game ID do not match | |
| Ad unit status is abnormal | |
| Ad unit type error | |
| Same ad unit requested too frequently |
Show API
errorCode | subErrorCode | Description |
| Ad instance ID parameter is empty, invalid parameter | |
| Ad instance ID does not match, cannot find the corresponding ad instance | |
| Ad instance has already been displayed, cannot be reused | |
| Insufficient interval since last play, not allowed to show interstitial ad | |
| Exceeded interstitial ad play count limit, not allowed to show interstitial ad | |
| User exited without watching completely (no reward earned) | |
| System error | |
|
| Client network environment error |
|
| Server error |