Skip to main content

ads

A collection of APIs for integrating ads into your mini-app. It consists of the TossAds namespace for inserting banner ads into the DOM, the GoogleAdMob namespace for controlling Google AdMob full-screen ads, and two top-level functions for full-screen ads.

Methods

MethodReturn typePurpose
TossAds.attachvoidDeprecated. Attaches a banner ad slot directly to a DOM element.
TossAds.attachBannerAttachBannerResultAttaches a banner ad slot to a DOM element and returns a destroy handle.
TossAds.destroyvoidDestroys a banner ad by slot ID.
TossAds.destroyAllvoidDestroys all banner ad slots on the current page.
TossAds.initializevoidInitializes the TossAds SDK. Must be called before attaching any ads.
GoogleAdMob.isAppsInTossAdMobLoadedPromise<boolean>Checks whether an ad has been successfully loaded.
GoogleAdMob.loadAppsInTossAdMob() => void (cleanup)Pre-loads a Google AdMob full-screen ad.
loadFullScreenAd() => void (cleanup)Pre-loads a full-screen ad (non-AdMob).
GoogleAdMob.showAppsInTossAdMob() => void (cleanup)Shows the pre-loaded Google AdMob full-screen ad.
showFullScreenAd() => void (cleanup)Shows the pre-loaded full-screen ad (non-AdMob).

Permission

No permission required — none of the functions in the ads namespace are bound to a PermissionName.

Ad type summary

TypeAPIDescription
Banner adTossAds.initialize + TossAds.attachBannerInserts an inline banner into a DOM element. Call destroy/destroyAll when the view unmounts.
Google AdMob full-screenGoogleAdMob.loadAppsInTossAdMobGoogleAdMob.showAppsInTossAdMobTwo-step: load then show. Call show only after receiving the loaded event.
Full-screen ad (native)loadFullScreenAdshowFullScreenAdSame pattern as GoogleAdMob but a separate namespace.

UX guidance

  • Don't use TossAds.attach. It is deprecated — replace it with TossAds.attachBanner.
  • Call initialize only once. Initialize at app mount time and don't call it again.
  • Always destroy on unmount. Failing to call destroy or destroyAll in a React useEffect cleanup leaves zombie ad slots and leaks memory.
  • Check isSupported() before calling ad APIs. Every ad API exposes an .isSupported() method. Calling an unsupported API may throw.

Try it live

Try all methods on the Ads page in sdk-example.

Open in sdk-example

External references