TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/admob-plus/admob-plus/llms.txt
Use this file to discover all available pages before exploring further.
MobileAd class is the base class for all ad formats in AdMob Plus. It provides common functionality for ad lifecycle management, event handling, and ad operations.
You typically don’t instantiate
MobileAd directly. Instead, use specific ad format classes like BannerAd, InterstitialAd, RewardedAd, etc., which extend this base class.Constructor
Parameters
Configuration options for the mobile ad.
The AdMob ad unit ID for this ad. Get this from your AdMob dashboard.
Optional unique identifier for this ad instance. If not provided, defaults to the
adUnitId.URL string for content that is being requested. Used for content targeting.
Array of keyword strings for targeting ads based on content.
Non-personalized ads flag. Set to
'1' to request non-personalized ads (for GDPR compliance).Properties
id
Unique identifier for this ad instance. Either the provided
id option or the adUnitId.adUnitId
The AdMob ad unit ID for this ad.
Methods
on()
Registers an event listener for ad events. Returns a cleanup function to unregister the listener.Parameters
The name of the event to listen for. Common events include:
'load'- Ad loaded successfully'loadfail'- Ad failed to load'show'- Ad shown to user'showfail'- Ad failed to show'dismiss'- Ad dismissed by user'impression'- Ad impression recorded'click'- User clicked on ad'reward'- User earned reward (for rewarded ads)
Function called when the event occurs. Receives an event object with ad details.
Optional event listener options (e.g.,
{ once: true } for one-time listeners).Returns
A cleanup function that removes the event listener when called.
Example
getAdById()
Static method to retrieve an ad instance by its ID.Parameters
The ID of the ad instance to retrieve.
Returns
The ad instance with the specified ID, or
undefined if not found.Example
Protected Methods
The following methods are protected and available to subclasses. Specific ad format classes expose these as public methods with appropriate signatures.load()
Loads the ad from AdMob servers.show()
Shows the loaded ad to the user.Parameters
Optional ad format-specific options for showing the ad.
hide()
Hides the ad from view (primarily used for banner ads).isLoaded()
Checks if the ad is currently loaded and ready to show.Returns
true if the ad is loaded, false otherwise.Type Definitions
Event System
All ad events follow a consistent naming pattern:Usage Example
Ad Lifecycle
All ads following the MobileAd pattern go through this lifecycle:- Create - Instantiate the ad class with options
- Initialize - Internal initialization (happens automatically)
- Load - Request ad from AdMob servers
- Show - Display the ad to the user
- Dismiss/Hide - Ad is closed or hidden