AppOpenAd
Creates App Open Ad and register event listeners to various events.
Unlike other FullScreenAd
s, only one AppOpenAd
instance can exist in an application. Doing so, AppOpenAd
supports static methods as well as instance methods. Calling these static methods acts same as calling instance methods for shared ad instance.
tip
If you are going to use App Open Ad inside functional component, consider using useAppOpenAd
.
Useage Example
TODO
Methods
createAd()
static createAd(unitId: string, options?: AppOpenAdOptions): AppOpenAd
Creates an shared ad instance. If you create ad more than once, ad created before is destroyed. Ad is loaded automatically after created and after dismissed.
Parameters
unitId
: App Open Ad unitId.
options
(Optional) : AppOpenAdOptions
object
Properties :
showOnColdStart
: Whether to show ad on app coldstart. Defaults tofalse
.showOnAppForeground
: Whether to show ad on app becomes foreground. Defaults totrue
.loadOnDismissed
: Whether App Open Ad to load new ad on dismissed. Defaults totrue
.requestOptions
: RequestOptions used to load the ad.
Returns
AppOpenAd
instance.
getAd()
static getAd(): AppOpenAd
Returns created AppOpenAd shared instance.
Returns
AppOpenAd
shared instance.
load()
static load(requestOptions?: RequestOptions): Promise<void>
Loads new App Open Ad.
Generally you don't need to call this function because ad is loaded automatically on ad created and ad dismissed.
Parameters
requestOptions
(Optional) : RequestOptions used to load the ad.
Returns
Promise
that waits for ad load. When error is occured while loading ad, the Promise will reject with AdError
object.
show()
static show(): Promise<void>
Shows loaded App Open Ad.
Ad must be loaded before calling this function.
You don't need to call this function if you set showOnAppForeground
option to true.
Returns
Promise
that waits for ad present. When error is occurred while presenting ad, the Promise will reject with AdError
object.
addEventListener()
static addEventListener(event: string, handler: (event?: any) => any): void
Adds an event handler for an ad event.
Parameters
event
: Event name. Supported events:
Event Name | Description |
---|---|
adLoaded | Fires when the ad has finished loading. |
adFailedToLoad | Fires when the ad has failed to load. The argument to the event handler is AdError object. |
adPresented | Fires when the ad is presented to user. |
adFailedToPresent | Fires when an error occurred while presenting ad. The argument to the event handler is AdError object. |
adDismissed | Fires when the ad is dismissed. |
handler
: An event handler.
removeAllListeners()
static removeAllListeners(): void
Removes all registered event handlers for this ad.
setRequestOptions()
static setRequestOptions(requestOptions?: RequestOptions): void
Sets RequestOptions for this Ad instance.
Parameters
requestOptions
: RequestOptions used to load the ad.