Overview
Banner ads are rectangular ads displayed in a portion of the screen. They can be easily implemented using theAdropBanner component.
Key Features
- Can be fixed at the top, bottom, or middle of the screen
- Support for image and video ads
- Support for automatic or manual ad loading
- Ad event handling through callbacks
- Provides ad metadata (creative ID, campaign ID, etc.)
Use test unit IDs in development:
PUBLIC_TEST_UNIT_ID_320_100 or PUBLIC_TEST_UNIT_ID_320_50AdropBanner Component
Props
string
required
Unit ID created in the Ad Control Console
ViewStyle
required
Banner style (width and height required)
string
Context ID for contextual targeting (1.17.0+). Only the value at mount time applies. To change it, change
key to remount the banner.boolean
default:"true"
Whether to automatically load ads when the component is mounted
boolean
default:"false"
Whether to use custom click handling. If set to
true, the browser won’t automatically open on ad click.{ width: number; height: number } | null
Explicit ad size to request from the server. When
style.width is a number, adSize is automatically derived from the style dimensions ({ width: style.width, height: style.height }). When style.width is a string (e.g., '100%'), adSize defaults to null and the SDK uses responsive sizing. You generally do not need to set this prop manually.(unitId: string, metadata?: AdropBannerMetadata) => void
Callback invoked when ad is successfully received
(unitId: string, metadata?: AdropBannerMetadata) => void
Callback invoked when user clicks the ad
(unitId: string, metadata?: AdropBannerMetadata) => void
Callback invoked when ad is displayed on screen
(unitId: string, errorCode?: string) => void
Callback invoked when ad reception fails
(unitId: string) => void
Callback invoked when a video ad starts playing
(unitId: string) => void
Callback invoked when a video ad finishes playing
Basic Usage
Auto Load (Recommended)
Automatically load the ad when the component is mounted.Manual Load Using Ref
You can load ads at the desired time usingref.
Callback Functions
onAdReceived
Called when ad reception is successful.onAdClicked
Called when user clicks the ad.onAdImpression
Called when ad is displayed on screen.onAdFailedToReceive
Called when ad reception fails.onAdVideoStart
Called when a video ad starts playing.onAdVideoEnd
Called when a video ad finishes playing.AdropBannerMetadata
Type for ad metadata.Ad Sizes
Banner ads should have style dimensions that match the size set in the unit.Common Banner Sizes
Using Fixed Size
Fitting to Screen Width
Using Responsive Size
If
width is set as a string (e.g., '100%'), it works responsively, but if set as a number, that value is passed to the ad server to request ads of appropriate size.Test Unit IDs
Use the following test unit IDs during development and testing.Usage Example
Error Handling
Implement appropriate error handling when ad loading fails.Managing Error State
Best Practices
1. Screen Visibility
Load ads when the banner is visible on screen.2. Loading Indicator
Improve user experience during ad loading.3. Managing Multiple Banners
Manage the state of each banner when using multiple banners.4. Custom Click Handling
UseuseCustomClick to handle ad clicks directly.
Complete Example
TypeScript Example
JavaScript Example
Backfill Ads
To use backfill ads, you must have the backfill dependency added to your native platforms (Android/iOS).
onAdFailedToReceive callback.
Preloading Backfill Ads (preload)
Starting with SDK 1.17.0, you can useAdropBanner.preload() to preload a backfill banner ad. When an <AdropBanner> loaded with the same unit ID and the same size gets no direct ad and falls back to a backfill ad, it displays the preloaded ad right away instead of requesting a backfill ad again.
The banner still requests a direct ad first, regardless of preload. If a direct ad is displayed, the preloaded ad is kept as is. If you don’t call preload, the behavior is the same as before.
Requirements
- You need
adrop-ads-react-native1.17.0 or later and, on the native platforms, the backfill dependency 1.17.0 or later. See Getting Started. - Preload fetches a backfill ad only when the server has told the app that there are no direct ads to show right now. Otherwise, it ends with
AdropErrorCode.preloadSkippedwithout requesting a backfill ad. This is a normal result in apps that have direct ad campaigns. - Right after the app is installed, right after you change the App Key, and right after you switch to a different user with
setUID, preload ends withAdropErrorCode.preloadSkippeduntil the server response arrives. - With test unit IDs, preload always ends with
AdropErrorCode.preloadSkipped.
Usage
Call preload right before you open the screen that contains the banner. A preloaded ad is discarded after 30 minutes if it isn’t used, so call preload only for banners you’re about to display. You don’t need to wait for the result before loading the banner. If the ad is still being fetched, the banner waits for that result and uses it.AdropBanner.preload() resolves when preloading succeeds. Any other result (including AdropErrorCode.preloadSkipped) rejects with { code, message }. If you don’t handle it, even SKIPPED, which is a normal result, triggers an unhandled Promise rejection warning, so wrap the call in try/catch or attach .catch.
width and height values in the style of <AdropBanner> that match preload’s adSize.
When a Preloaded Ad Is Used
- Same unit ID and same size: The numeric
widthandheightin thestyleof<AdropBanner>must match preload’sadSize. For a banner that uses a non-numeric size such aswidth: '100%', the preloaded ad may not be used because the size doesn’t match. If the size differs, the preloaded ad is kept as is, and the banner requests a backfill ad as usual. - Used only once: A preloaded ad is gone once a single banner load uses it. To preload again, call preload again.
- Lifetime and count: An ad that isn’t used within 30 minutes is discarded. Only 1 ad is kept per unit and size, and banners keep up to 5 different unit/size combinations. When there are more than 5, ads are discarded starting with the one received first.
- Calling again: Calling preload again with the same unit and size doesn’t make a new request. If an ad has already been preloaded, the call resolves without a new request; if one is still being fetched, the call gets that load’s result (success or failure). You can’t use preload to refresh an ad. However, if the user consent status has changed in the meantime, the existing ad is discarded and a new one is fetched.
- Consent status changes: If the user consent status changes after an ad is preloaded, that ad isn’t used to load a banner.
- What resolve means: When
preload()resolves, it means preloading has finished. A banner that was waiting for that result may have already used the ad.
Failure Codes
Next Steps
Native Ads
Implement customizable native ads for your UI
Interstitial Ads
Implement full-screen interstitial ads
Popup Ads
Implement ads displayed in popup format
Reference
Reference types, methods, and error codes