TikTok for Developers

Developer Docs

Last updated November 28, 2026

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.Load

Use 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() or Load() when it's supported. Otherwise, skip the preload call and keep your existing display flow.
  • When the player chooses to watch, call show() or Show() 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, or IsLoaded() before it calls show() or Show().

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 canIUse() key or Unity CanIUse flag shows whether preloading is supported.

4

Preload the ad.

If preloading is supported and the instance is neither loading nor ready, your code calls load() or Load().

5

Show the ad when the player chooses to watch.

Your code calls show() or Show(). On clients without preload support, the existing flow loads and shows the ad.

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

errorCode

Number

The error code.

Yes

errMsg

String

The error message.

Yes

subErrorCode

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

callback

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

callback

Function

The same function reference passed to onLoad().

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() or Show() 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: isEnded in JavaScript, or the isEnded argument 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:

  1. Remove the listeners from the old instance.
  2. Discard the old instance. In Unity, also call Destroy().
  3. 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)

[Third party] Invalid ad Instance Id. Please call createRewardedVideoAd/createInterstitialAd JSB with the same adUnitId first.

The instance wasn't created first, or the IDs don't match.

Call createRewardedVideoAd() or createInterstitialAd() first, then call load() on that instance.

11003 (101111003)

[Third party] Ad instance can only show once. Please call this JSB with another adUnitId.

The ad was already shown. Ad instances are single-use.

Create a new ad instance, then call load(). Don't preload an instance that was already shown.

11007 (104111007)

[Third party] Ad is currently loading.

load() is already in progress for the same instance.

Wait for the current load to succeed or fail before you retry. Don't call load() concurrently on the same instance.

11008 (102111008)

[TT4B] Ad load failed.

The ads SDK failed to load the ad.

Call show() to fall back to the on-demand flow. Check network connectivity and the ad unit configuration. If the problem continues, contact Developer Support.

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

Ad troubleshooting flow: trigger, create/init, call show, check the ad appears, then resume play and handle close and rewards

Problem

What to check

The button or level-end event runs, but the game never calls show().

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 createInterstitialAd() with an interstitial ad unit, and createRewardedVideoAd() with a rewarded ad unit. For other initialization failures, check the actual error code.

show() is called, but the ad doesn't appear or appears late.

Record the show() result or error callback, and use a screen recording to check when the ad appears. If the ad consistently appears after a long wait, compare the time from trigger to display, and the successful displays, with and without preloading.

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.

Next steps

TikTok for Developers