Implementation Methods
You can implement banner ads in two ways.Use the test unit ID in development:
PUBLIC_TEST_UNIT_ID_320_1001. Data Attributes Method
The simplest method - just add thedata-adrop-unit attribute and the SDK will automatically load the ad.
Data Attributes
Context ID for Contextual Targeting
Theme setting (
light or dark) - See Dark Mode SettingsEnable custom click handling - When
true, SDK will not automatically navigate to the destination URL on click, only emit adClicked event with destination URL. Allows developers to implement custom click behavior.Backfill ad rendering mode (
responsive or fixed). See the Backfill Rendering Mode guide for details. (SDK 1.2.3+)Advertising identifier — required for the View on Device feature to preview a draft creative on a registered test device. Do not hard-code in production.
Refreshing Ads
Change the React key to remount the component and request a new ad.2. renderAd Method
Use this when you want direct control over ad loading timing.renderAd Options
Context ID for Contextual Targeting
Theme setting (
light or dark) - See Dark Mode SettingsEnable custom click handling - When
true, SDK will not automatically navigate to the destination URL on click, only emit adClicked event with destination URL. Allows developers to implement custom click behavior.Backfill ad rendering mode. See the Backfill Rendering Mode guide for details. (SDK 1.2.3+)
Advertising identifier — required for the View on Device feature to preview a draft creative on a registered test device. Do not hard-code in production.
Refreshing Ads
CallrenderAd() again to request a new ad. Can also be used on placements created with Data Attributes.
When calling
renderAd() on a placement created with Data Attributes, you only need to pass items that don’t exist in data attributes or items you want to modify.Removing Ads
Callclear() to remove the ad from the container.
Ad Size
Recommended: responsive width +aspect-ratio matching the registered unit size. The slot scales with the device width and the height is locked by the ratio (no CLS).
For container sizing patterns and how to choose a backfill rendering mode, see the Backfill Rendering Mode guide.
Event Handling
You can detect ad status changes and handle the UI appropriately.Supported Events
Always remove event listeners using
off() when the component unmounts.AdData
Ad data passed to event handlers. See Reference > AdData for detailed field information.Custom Click Handling
WhenuseCustomClick is enabled, the SDK will not automatically navigate to the destination URL. Instead, you can handle the click event and implement custom behavior.
With custom click handling enabled, you have full control over what happens when users click the ad. The
destinationURL is provided in the adClicked event data.Complete Example
BannerAd.tsx
Usage Example
Backfill Ads
When backfill ads are enabled, they are automatically requested when no direct ads are available. You can distinguish ad types usingadData.format.