App Open Ads - cleveradssolutions/CAS-Flutter GitHub Wiki

App open ads are a special ad format intended for publishers wishing to monetize their app load screens. App open ads can be closed at any time, and are designed to be shown when your users bring your app to the foreground.

App open ads automatically show a small branding area so users know they're in your app.

This guide explains how to integrate app open ads into an Android app.

flowchart TD

A[isAutoloadEnabled] -->|auto| L((load))
L -->|success| R([onAdLoaded])
L -->|fail| F([onAdFailedToLoad])
F -->|delay| A
R --> RL[isLoaded]
S((show)) --> RL
RL -->|success| SR([onAdShowed])
RL -->|fail| SF([onAdFailedToShow])
SR --> I([onAdImpression])
SR --> C([onAdClicked])
I --> D([onAdDismissed])
D --> A
SF --> A
Loading

Create Ad instance

Ad instance can be initialized along with the widget state before initState.

import 'package:clever_ads_solutions/clever_ads_solutions.dart';

class _SplashScreenState extends State<HomeScreen> {

  final _appOpenAd = CASAppOpen.create(_casId);

  @override
  void initState() {
    ...
  }

The SDK provides the capability to create and precache multiple ad instances, enabling uninterrupted sequential ad display. CAS SDK will load mediation ads in order for each created instance.

Create Ad Content callback

The com.cleveradssolutions.sdk.screen.ScreenAdContentCallback handles events related to displaying your CASAppOpen. Callbacks are called on the main thread. Before showing ad, make sure to setContentCallback().

final ScreenAdContentCallback _adContentCallback = ScreenAdContentCallback(
  onAdLoaded: (ad) {
    // (Optional) Called when the ad content has been successfully loaded.
  },
  onAdFailedToLoad: (ad, error) {
    // (Optional) Called when the ad content fails to load.
  },
  onAdShowed: (ad) {
    // (Optional) Called when the ad content is successfully shown.  
  },
  onAdFailedToShow: (ad, error) {
    // (Optional) Called when the ad content fails to show.  
  },
  onAdClicked: (ad) {
    // (Optional) Called when the ad content is clicked by the user.  
  },
  onAdDismissed: (ad) {
    // (Optional) Called when the ad content is dismissed.  
  },
);

Note

  • Read more about AdContentInfo structure in Impression Level Data.
  • Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged. Limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.
  • When an error occurs during ad impression, executed the onAdFailedToShow only. In this case the onAdDismissed will not be executed, since the impression is not considered successful.

Load Ad

The next step is to fill out the load() method and handle the ad load callbacks.

@override
void initState() {
  _appOpenAd.contentCallback = _adContentCallback;
  _appOpenAd.load();
}

Autoload mode

If enabled, the ad will automatically load new content when the current ad is dismissed or completed. Additionally, it will automatically retry loading the ad if an error occurs during the loading process.

@override
void initState() {
  _appOpenAd.contentCallback = _adContentCallback;
  _appOpenAd.setAutoloadEnabled(true);
}

By default autoload disabled.

Show Ad

The most common app open implementation is to attempt to show an app open ad near app launch, start app content if the ad isn't ready, and preload another ad for the next app open opportunity.

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      if (_appOpenAd.isLoaded) {
        _appOpenAd.show();
      } else if (!appOpenAd.isAutoloadEnabled) {
        _appOpenAd.load();
      }
    }
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}

Once you’ve successfully call show(), you will have shown your user an App Open Ad.
In the case you want to serve another App Open Ad, you must repeat load() to request an additional ad.

Note

If a user returns to your app after having left it by clicking on an app open ad, it makes sure they're not presented with another app open ad.

Autoshow mode

Use the isAutoshowEnabled property to automatically show a loaded ad when the user returns to the app.

@override
void initState() {
  ...
  _appOpenAd.setAutoshowEnabled(true);
}

By default autoshow disabled.

Release ad resource

It is important to destroy() loaded but not displayed ads.

@override
void dispose() {
  _appOpenAd.destroy();
  super.dispose();
}

Cold starts and loading screens

The documentation thus far assumes that you only show app open ads when users foreground your app when it is suspended in memory. "Cold starts" occur when your app is launched but was not previously suspended in memory.

An example of a cold start is when a user opens your app for the first time. With cold starts, you won't have a previously loaded app open ad that's ready to be shown right away. The delay between when you request an ad and receive an ad back can create a situation where users are able to briefly use your app before being surprised by an out of context ad. This should be avoided because it is a bad user experience.

The preferred way to use app open ads on cold starts is to use a loading screen to load your game or app assets, and to only show the ad from the loading screen. If your app has completed loading and has sent the user to the main content of your app, do not show the ad.

Note

In order to continue loading app assets while the app open ad is being displayed, always load assets in a background thread.

Best practices

App open ads help you monetize your app's loading screen, when the app first launches and during app switches, but it's important to keep best practices in mind so that your users enjoy using your app. It's best to:

  • Show your first app open ad after your users have used your app a few times.
  • Show app open ads during times when your users would otherwise be waiting for your app to load.
  • If you have a loading screen under the app open ad, and your loading screen completes loading before the ad is dismissed, you may want to dismiss your loading screen in the onAdDismissed() and onAdFailedToShow() methods.

🔗 Next Banner Ads

⚠️ **GitHub.com Fallback** ⚠️