The app open ads are a special format which main purpose is to allow the monetization of the app load screens.
These ads can be closed anytime and are meant to be shown when the app moves to foreground.
Integration
This ad format can be only integrated through code, by implementing any of the two possible ways of integration that are described below.
Manual
In this kind of integration, it is needed to create an instance of the AppOpenAd class and use the loadAd() and showAd() methods to make the ad load and show on demand. The publisher is the responsible of deciding when the ad must be shown and implement the required logic.
Below you can find a simple integration example:
publicclassMainActivityextendsActivity {privateAppOpenAd mAppOpenAd; @OverridepublicvoidonCreate(Bundle savedInstanceState) {... mAppOpenAd =newAppOpenAd(this,"Wortise Ad Unit ID");mAppOpenAd.loadAd(); } @OverridepublicvoidonDestroy() {...mAppOpenAd.destroy(); }publicvoidshowAppOpen() {if (mAppOpenAd.isAvailable()) {mAppOpenAd.showAd(this); } }}
Also, the AppOpenAd class offers the following additional methods to configure its behaviour:
// Sets if a new ad must be loaded after closing the previous onemAppOpenAd.setAutoReload(true);// Shows an ad immediately if available. Otherwise, requests the load of a// new admAppOpenAd.tryToShowAd(activity);
// Sets if a new ad must be loaded after closing the previous oneappOpenAd.autoReload =true// Shows an ad immediately if available. Otherwise, requests the load of a// new adappOpenAd.tryToShowAd(activity)
Via Manager
The SDK provides a standard implementation of App Open to facilitate the integration of this ad format.
To perform this kind of integration, it is needed that the app extends the Application class and, inside it, creates an instance of AppOpenManager, just as shown in the example below:
publicclassMyApplicationextendsApplication {privateAppOpenManager mAppOpenManager; @OverridepublicvoidonCreate() {... mAppOpenManager =newAppOpenManager(this,"Wortise Ad Unit ID");mAppOpenManager.loadAd(); }}
classMyApplication : Application() {privateval appOpenManager bylazy {AppOpenManager(this, "Wortise Ad Unit ID") }overridefunonCreate() {... appOpenManager.loadAd() }}
With this simple integration, the app will show ads every time there is a transition from background to foreground.
Also, the AppOpenManager class offers the same methods as AppOpenAd to configure its behaviour and show ads on demand.
Listener configuration
Like occurs with other formats, a listener can be set to receive the events that happen during the ad lifecycle. For this, it is needed to implement the AppOpendAd.Listener interface just as shown in the example below:
mAppOpenAd.setListener(new AppOpenAd.Listener() { @OverridepublicvoidonAppOpenClicked(@NonNullAppOpenAd ad) {// Invoked when the ad has been clicked } @OverridepublicvoidonAppOpenDismissed(@NonNullAppOpenAd ad) {// Invoked when the ad has been dismissed } @OverridepublicvoidonAppOpenFailedToLoad(@NonNullAppOpenAd ad, @NonNullAdError error) {// Invoked when the ad could not be loaded// (because of an error or no fill) } @OverridepublicvoidonAppOpenFailedToShow(@NonNullAppOpenAd ad, @NonNullAdError error) {// Invoked when the ad could not be shown } @OverridepublicvoidonAppOpenImpression(@NonNullAppOpenAd ad) {// Invoked when the ad has generated an impression } @OverridepublicvoidonAppOpenLoaded(@NonNullAppOpenAd ad) {// Invoked when the ad has been loaded } @OverridepublicvoidonAppOpenShown(@NonNullAppOpenAd ad) {// Invoked when the ad has been shown }});
appOpenAd.listener =object : AppOpenAd.Listener() {overridefunonAppOpenClicked(ad: AppOpenAd) {// Invoked when the ad has been clicked }overridefunonAppOpenDismissed(ad: AppOpenAd) {// Invoked when the ad has been dismissed }overridefunonAppOpenFailedToLoad(ad: AppOpenAd, error: AdError) {// Invoked when the ad could not be loaded// (because of an error or no fill) }overridefunonAppOpenFailedToShow(ad: AppOpenAd, error: AdError) {// Invoked when the ad could not be shown }overridefunonAppOpenImpression(ad: AppOpenAd) {// Invoked when the ad has generated an impression }overridefunonAppOpenLoaded(ad: AppOpenAd) {// Invoked when the ad has been loaded }overridefunonAppOpenShown(ad: AppOpenAd) {// Invoked when the ad has been shown }}