Implementation Methods
You can implement banner ads in two ways.| Method | Description | Recommended |
|---|---|---|
| Data Attributes | Simple implementation using HTML attributes only | Quick implementation |
| renderAd | Direct control over ad loading timing | When fine-grained control is needed |
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
Unit ID created in Ad Control Console
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
Unit ID created in Ad Control Console
User identifier (used to override SDK-level setting for individual placements)
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).
| Type | Size Setting | Alignment |
|---|---|---|
| Direct Ads | Responsive support, height required | Horizontal/Vertical center |
| Backfill Ads | Auto-matched to container width (responsive) or stretched to container height (fixed) | Horizontal center |
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
| Event | Constant | Description |
|---|---|---|
| Ad Received | AD_RECEIVED | Ad request successful |
| No Ad | AD_NO_FILL | No direct ads available |
| Request Failed | AD_FAILED | Ad request failed |
| Impression | AD_IMPRESSION | Ad impression recorded |
| Click | AD_CLICKED | User clicked the ad |
| No Backfill | AD_BACKFILL_NO_FILL | No backfill ad available |
| Video Start | AD_VIDEO_START | Video ad playback started |
| Video End | AD_VIDEO_END | Video ad playback ended |
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.
Development Environment Testing: If at least one ad unit connected to the app is Monetizing, backfill ad requests can be made from localhost. On unapproved domains, an
AD_BACKFILL_NO_FILL event will be triggered.