Creating a Banner Ad
API Reference
Constructor Options
Your AdMob ad unit ID for banner ads.
Optional unique identifier for this ad instance. Defaults to
adUnitId if not provided.Position of the banner on screen.
Banner size configuration. Can be a predefined size type or custom dimensions.Predefined Sizes:Adaptive Anchored:Adaptive Inline:
AdSizeType.BANNER(320x50)AdSizeType.LARGE_BANNER(320x100)AdSizeType.MEDIUM_RECTANGLE(300x250)AdSizeType.FULL_BANNER(468x60)AdSizeType.LEADERBOARD(728x90)AdSizeType.SMART_BANNER(screen width adaptive, default)
Offset in pixels from the position edge. Setting this makes the banner overlay on the webview.Set to
0 to overlay directly on content without spacing:URL string for content that is being displayed in your app.
Array of keyword strings for ad targeting.
Set to
'1' to enable non-personalized ads (for GDPR compliance).Methods
show()
Displays the banner ad. Automatically loads the ad if not already loaded.
Promise<void>
hide()
Hides the banner ad from view without destroying it.
Promise<void>
load()
Preloads the banner ad. Usually not needed as show() automatically loads.
Promise<void>
on(eventName, callback)
Registers an event listener for the ad.
Function - Unsubscribe function
Static Methods
BannerAd.config(options)
Configures global banner settings (iOS only).
Background color for banner area. Accepts any CSS color value.
Top margin in pixels.
Bottom margin in pixels.
Events
All events can be listened to using theon() method or via global event listeners.
load
Fired when the ad is successfully loaded and ready for display.
loadfail
Fired when the ad request fails.
impression
Fired when the ad is displayed to the user.
click
Fired when the user clicks on the ad.
admob.banner.size
Global event that provides banner size information, including when the device is rotated.
Usage Examples
Basic Banner
Banner with Event Handling
Banner with Custom Size
Adaptive Banner
Show/Hide Toggle
Banner ads automatically refresh at Google’s optimized rate. You can customize the refresh rate in your AdMob account settings.
Best Practices
- Positioning: Place banners at natural breaks in content, not overlapping important UI elements
- Refresh Rate: Use Google’s automatic refresh for optimal performance
- Responsive Design: Use adaptive sizes for better rendering across different devices
- Performance: Reuse banner instances instead of creating new ones frequently