Below we show a few simple examples to implement the App Open ads by following the two possible ways of integration:
Manual
import'package:wortise/app_open_ad.dart';AppOpenAd _appOpenAd;// Create an App Open_appOpenAd =AppOpenAd('Wortise Ad Unit ID', listener: (event, args) {// This listener will be invoked when an event happens});// Request an adawait _appOpenAd.loadAd();/* ... */// Show the ad if availableif (await _appOpenAd.isAvailable) {await _appOpenAd.showAd();}
The AppOpenAd class constructor allows to specify the following optional parameters to configure its behaviour:
// Sets if a new ad must be loaded after closing the previous oneautoReload:true
Alternatively, the tryToShowAd() method can be used to show the ad with the difference that, if there is none available, the load of a new ad is automatically requested.
await _appOpenAd.tryToShowAd();
Via Manager
import'package:wortise/app_open_ad.dart';import'package:wortise/app_open_manager.dart';// Create an App OpenAppOpenAd appOpenAd =AppOpenAd('Wortise Ad Unit ID')..loadAd();// Register the ad in the managerAppOpenManager.register(appOpenAd);
In this integration, the ads will be automatically shown when an app transitions from background to foreground. Also, the methods offered by AppOpenAd can still be used to show ads on demand.
Listener events
The assigned listener to an AppOpenAd can receive the following events:
// The ad has been clickedAppOpenAdEvent.CLICKED// The ad has been dismissedAppOpenAdEvent.DISMISSED// The ad could not be loadedAppOpenAdEvent.FAILED_TO_LOAD// The ad could not be shownAppOpenAdEvent.FAILED_TO_SHOW// The ad has generated an impressionAppOpenAdEvent.IMPRESSION// The ad has been loadedAppOpenAdEvent.LOADED// The ad has been shownAppOpenAdEvent.SHOWN