Preload Ads
Preload a rewarded or interstitial ad before the player chooses to watch it, so the ad appears with less waiting. Preloading moves the ad request earlier in the player's flow. It never displays the ad by itself. Call show() only when the player chooses to watch.
This guide is part of Optimize Mini Game Performance. For ad setup, see In-App Ads.
Prerequisites
- Rewarded or interstitial ads integrated in your game. For details, see In-App Ads.
- For JavaScript: a TikTok mini game that uses the Mini Games SDK. Preloading requires TikTok 46.1.0 or later on iOS and Android.
- For Unity: the latest TikTok SDK for Unity. For the download link, see Build Mini Games With Unity.
Choose when to preload
Preload only when the player is likely to watch an ad soon and you can predict when the ad will be triggered.
Player flow | When to preload | Expected ad trigger |
Opens a "Watch an ad to earn a reward" page | After the page finishes rendering and the ad entry is available | The player taps to claim the reward. |
Starts a game session or enters a level | After critical resources load and gameplay begins | An ad might show on the results screen. |
Approaches an out-of-energy, revive, or reward point | Shortly before that point, before the ad is triggered | The player chooses to watch an ad to revive, restore energy, or claim a reward. |
Opens a page with an ad entry | After the page finishes rendering and the entry can be tapped | The player taps the ad entry. |
Caution: Don't preload before the first playable gameplay, which is when your game reports time to interactive (sceneId: 9999). Early ad video requests compete with startup packages and first-scene assets. Don't preload repeatedly without a predictable placement, and don't request ads continuously in the background. Never display ads automatically without an explicit action from the player.
For time to interactive, see Optimize Startup.
Check compatibility
TikTok 46.1.0 and later supports load(), onLoad(), and offLoad() on iOS and Android. How you use create, show, onClose, and onError doesn't change.
Check preload support separately for each ad type:
// Rewarded ad
TTMinis.game.canIUse('createRewardedVideoAd.return.load')
// Interstitial ad
TTMinis.game.canIUse('createInterstitialAd.return.load')In Unity, check the following flags:
// Rewarded ad
CanIUse.TTRewardedVideoAd.Load
// Interstitial ad
CanIUse.TTInterstitialAd.LoadUse canIUse() and CanIUse only to decide whether to call the preload APIs. Don't use them to decide whether to call show() or Show().
- Before an expected ad trigger, check preload support. Call
load()orLoad()when it's supported. Otherwise, skip the preload call and keep your existing display flow. - When the player chooses to watch, call
show()orShow()right away. Don't wait for the preload to finish, and don't check the load state first. - Preload finished: The TikTok app shows the preloaded ad.
- Preload in progress: The TikTok app queues the display request and shows the ad when loading finishes.
- Preload failed: The TikTok app falls back to the existing flow that loads and shows the ad on demand.
- Your code must not require
onLoad,OnLoad, orIsLoaded()before it callsshow()orShow().
After you integrate preloading, test your game on a TikTok version that doesn't support preloading, to check that ads still work in production.
Integrate preloading
The integration follows the same steps in JavaScript and Unity:
Step | Action | Result |
1 | Create an ad instance. | The existing rewarded or interstitial ad API returns an instance. |
2 | Register event listeners. | Load, error, and close listeners are registered before the preload call, and your code keeps references to the callback functions. |
3 | Check preload support. | The |
4 | Preload the ad. | If preloading is supported and the instance is neither loading nor ready, your code calls |
5 | Show the ad when the player chooses to watch. | Your code calls |
6 | Prepare the next instance after the ad closes. | Your code removes the old instance's listeners and discards it, or destroys it in Unity, before creating the next one. |
Integrate in JavaScript
The following APIs work for both rewarded and interstitial ads.
load()
Requests and loads the ad instance in advance. If loading succeeds, the Promise resolves and the callbacks registered with onLoad() run. If loading fails, the Promise rejects.
Parameters: None.
Return value: Promise<void>. Resolves with no value on success, and rejects on failure.
The rejection object contains the following fields:
Field | Type | Description | Required |
| Number | The error code. | Yes |
| String | The error message. | Yes |
| Number | An additional error code returned in some cases. Don't use it as the only condition for core game logic. | No |
const ad = TTMinis.game.createInterstitialAd({
adUnitId: 'AD_UNIT_ID',
});
const canPreload = TTMinis.game.canIUse('createInterstitialAd.return.load');
async function preloadInterstitialAd() {
if (!canPreload) return;
try {
await ad.load();
} catch (error) {
console.error(error.errorCode, error.errMsg);
}
}
void preloadInterstitialAd();Replace AD_UNIT_ID with your ad unit ID.
onLoad(callback)
Registers a callback that runs each time the ad instance loads successfully.
Field | Type | Description | Required |
| Function | Called after the ad loads. The callback receives no arguments. | Yes |
Return value: None.
const ad = TTMinis.game.createInterstitialAd({
adUnitId: 'AD_UNIT_ID',
});
function handleLoad() {
console.log('interstitial ad loaded');
}
ad.onLoad(handleLoad);offLoad(callback)
Removes a callback registered with onLoad().
Field | Type | Description | Required |
| Function | The same function reference passed to | Yes |
Return value: None.
const ad = TTMinis.game.createInterstitialAd({
adUnitId: 'AD_UNIT_ID',
});
function handleLoad() {
console.log('interstitial ad loaded');
}
ad.onLoad(handleLoad);
// Pass the same function reference when the page unloads or the instance is discarded.
ad.offLoad(handleLoad);JavaScript example
The following example uses a rewarded ad. For an interstitial ad, replace the creation method, the canIUse() key, and the close callback. The rest of the logic stays the same.
const canPreload = TTMinis.game.canIUse(
'createRewardedVideoAd.return.load',
);
let ad = null;
let handleLoad;
let handleError;
let handleClose;
function createAd() {
if (ad) return;
ad = TTMinis.game.createRewardedVideoAd({
adUnitId: 'AD_UNIT_ID',
});
handleLoad = () => {
// Record preload success only; do not use it as a prerequisite for show().
reportPreloadSuccess();
};
handleError = error => {
report(error);
};
handleClose = result => {
if (result && result.isEnded) {
grantReward();
}
disposeAd();
// Do not create or preload the next instance immediately here.
};
ad.onLoad(handleLoad);
ad.onError(handleError);
ad.onClose(handleClose);
}
// Call when an ad is expected to be displayed soon.
function preloadAd() {
createAd();
if (!canPreload) return;
ad.load().catch(error => {
reportPreloadFailure(error);
});
}
// Trigger only through an explicit user action.
async function showByUserAction() {
try {
// Do not wait for load() or inspect the preload state.
await ad.show();
} catch (error) {
reportShowFailure(error);
}
}
function disposeAd() {
if (!ad) return;
ad.offLoad(handleLoad);
ad.offError(handleError);
ad.offClose(handleClose);
ad = null;
}Integrate in Unity
Unity reports load results through events. OnLoad fires when Load() succeeds, and OnError fires when it fails. You can call IsLoaded() to check the instance's load state.
Load() requires TikTok 46.1.0 or later on iOS and Android. Check the matching CanIUse flag before you call it.
Load()
Requests and loads the ad instance in advance. The result arrives through OnLoad or OnError.
Parameters: None.
Return value: None.
private TTInterstitialAd ad;
private void CreateAndLoad()
{
ad = TT.CreateInterstitialAd(new CreateInterstitialAdParam
{
InterstitialAdId = "AD_UNIT_ID"
});
if (CanIUse.TTInterstitialAd.Load)
{
ad.Load();
}
}OnLoad
Fires when the ad loads successfully. The callback receives no arguments.
private void RegisterLoadEvent()
{
if (CanIUse.TTInterstitialAd.Load)
{
ad.OnLoad += HandleLoaded;
}
}
private void HandleLoaded()
{
Debug.Log("ad loaded");
}IsLoaded()
Returns whether the ad instance is preloaded and ready. Use the result only to find out whether the preload was used. Don't use it to decide whether to call Show(). You can call Show() even when IsLoaded() returns false.
Parameters: None.
Return value: Boolean. true means the ad is loaded. false means it hasn't loaded yet or is no longer available.
public void ShowByUserAction()
{
if (ad != null && ad.IsLoaded())
{
Debug.Log("ad loaded");
}
}Destroy()
Destroys the ad instance and releases its resources. Remove all event handlers before you destroy the instance, and don't use the instance afterward.
Parameters: None.
Return value: None.
private void DisposeAd()
{
if (ad == null) return;
ad.OnLoad -= HandleLoaded;
ad.OnError -= HandleError;
ad.Destroy();
ad = null;
}Unity example
The following example uses a rewarded ad. For an interstitial ad, replace the instance type, creation parameters, CanIUse flag, and close callback signature. The rest of the logic stays the same.
private TTRewardedVideoAd ad;
// Call when entering an ad scenario whose display timing can be predicted.
// Create a new instance for each new display cycle.
private void PrepareAd()
{
DisposeAd();
ad = TT.CreateRewardedVideoAd(
new CreateRewardedVideoAdParam
{
AdUnitId = "AD_UNIT_ID"
}
);
ad.OnLoad += HandleLoaded;
ad.OnError += HandleError;
ad.OnClose += HandleClosed;
if (CanIUse.TTRewardedVideoAd.Load)
{
ad.Load();
}
}
// Trigger only through an explicit user action.
public void ShowByUserAction()
{
if (ad == null)
{
ReportAdNotPrepared();
return;
}
// Do not wait for OnLoad or use IsLoaded() to block display.
ad.Show();
}
private void HandleError(int code, string message)
{
ReportAdError(code, message);
}
private void HandleClosed(bool isEnded)
{
if (isEnded)
{
GrantReward();
}
DisposeAd();
}
private void DisposeAd()
{
if (ad == null) return;
ad.OnLoad -= HandleLoaded;
ad.OnError -= HandleError;
ad.OnClose -= HandleClosed;
ad.Destroy();
ad = null;
}Display the ad and handle the result
- Call
show()orShow()when the player chooses to watch. Don't wait for the preload to succeed. - For rewarded ads, grant the reward only when the close callback confirms that the player completed the ad:
isEndedin JavaScript, or theisEndedargument in Unity. Never grant a reward because a preload succeeded. - Keep the game usable if the ad fails. For example, continue the level-end flow if an interstitial ad doesn't appear.
Manage the instance and verify
An ad instance can show only once. After an ad closes:
- Remove the listeners from the old instance.
- Discard the old instance. In Unity, also call
Destroy(). - Create the next instance, and preload it at the next suitable time.
To check your integration, test each in-game trigger separately on a phone. For example, reach the end of a level to test an interstitial ad, then tap Watch for reward to test a rewarded ad. For each attempt, record the game version, trigger, ad unit ID, the step reached, and any error code your game receives. Match each recording with the same attempt in your logs. If the Developer Portal reports a problem with an ad unit, test each trigger that uses it.
If load() already succeeded on an instance that hasn't been shown, calling load() again reuses the cached ad instead of fetching a new one. Only a concurrent load (error 11007) or an instance that was already shown (error 11003) returns an error.
Error codes
Error code | Message | Cause | What to do |
11002 (101111002) |
| The instance wasn't created first, or the IDs don't match. | Call |
11003 (101111003) |
| The ad was already shown. Ad instances are single-use. | Create a new ad instance, then call |
11007 (104111007) |
|
| Wait for the current load to succeed or fail before you retry. Don't call |
11008 (102111008) |
| The ads SDK failed to load the ad. | Call |
The full error code appears in parentheses. Error codes 11002, 11003, and 11007 are caused by the game's code. Error code 11008 comes from the ads SDK. For other ad errors, see the Error Code Reference.
Troubleshooting

Problem | What to check |
The button or level-end event runs, but the game never calls | Trace the game's handler from the trigger to the creation and display calls. Check for an early return, such as a preload-ready flag that blocks the display call. |
Ad initialization fails with error 101320007. | Check the ad unit type on the Developer Portal against the API in your code. Use |
| Record the |
The ad closes, but the game stays paused or the reward is missing. | Check the close callback and the next step in your code. Check that the level-end flow continues if an interstitial ad fails. Grant the reward once, after the player completes the ad. |