Skip to content

Best practices

These recommendations help you get the most out of the SDK and avoid the integration mistakes that cause lost revenue, wasted requests or policy problems.

  • Initialize the SDK in Application.onCreate. An ad requested before WortiseSdk.initialize has been called fails with SDK_NOT_INITIALIZED. Initializing in the Application class guarantees that every Activity, and every banner declared in a layout, finds the SDK ready.
  • Load and show ads only from the main process of the app. WortiseSdk.initialize does nothing when it is called from a secondary process, so the ads requested there cannot be filled.
  • Do not declare Google Mobile Ads or the bundled mediation adapters in your own dependencies. The SDK already includes play-services-ads and its adapters in the versions it has been tested with, and forcing different versions can break the build or the ads at runtime.
  • Request the user consent on every app launch, before loading the first ad. The SDK never shows the consent dialog on its own, and ConsentManager.requestIfRequired only shows it when it is needed. Ads requested without consent, where it is required, cannot be personalized and generate less revenue.

  • Load the ads when the consent request finishes. The listener is always invoked, whether the dialog has been shown or not:

    WortiseSdk.wait {
    ConsentManager.requestIfRequired(this) {
    // The consent request has finished: the ads can be loaded now
    loadAds()
    }
    }
  • If you already use another consent platform, make sure it is IAB TCF compliant. The SDK reads the consent string that these platforms store, so there is no need to request the consent twice.

  • If your app is directed to children, follow the Families program guide. Those apps must integrate android-sdk-families instead of android-sdk, and mark their users before initializing the SDK.

  • Create each interstitial, rewarded or app open ad once, and load it in advance. Loading takes time, so an ad requested at the moment it has to be shown will not be ready.

  • Do not call loadAd() on an ad that is already loaded. A new load discards the ad that was ready to be shown, which wastes a filled request.

  • Load the next ad when the current one is dismissed. A fullscreen ad can be shown only once, so call loadAd() again in the on…Dismissed callback (or enable autoReload in app open ads).

  • Do not retry immediately after a failed load. After a failed load of a fullscreen or native ad, the SDK applies a cooldown (30 seconds by default) during which loadAd() is ignored and no callback is invoked. Wait before retrying, using cooldownRemainingMs as the minimum delay:

    override fun onInterstitialFailedToLoad(ad: InterstitialAd, error: AdError) {
    val delay = maxOf(ad.cooldownRemainingMs, 30_000L)
    handler.postDelayed({ ad.loadAd() }, delay)
    }
  • Do not wait indefinitely for a load callback. loadAd() does not invoke any callback when the ad is already loading or in cooldown, so do not block the app flow on it.

  • Check isAvailable before calling showAd(). When no ad is available, showAd() returns without showing anything and without invoking any callback, so the app must be able to continue on its own.
  • Continue the app flow from both on…Dismissed and on…FailedToShow. An ad that could not be shown never reaches on…Dismissed, so handling only that callback can leave the app waiting.
  • Grant the reward only in onRewardedCompleted. onRewardedDismissed is also invoked when the user closes the ad without completing it.
  • Show fullscreen ads at natural pauses of the app. Ads that interrupt the user in the middle of an action, or that appear unexpectedly, cause accidental clicks, which go against the policies of the ad networks.
  • Use one BannerAd per placement and keep it while its screen is alive. Creating a new banner on every refresh of the UI multiplies the ad requests without generating more impressions.
  • Do not call loadAd() to refresh a banner or to retry a failed load. The banner refreshes itself while it is visible, and after a failed load it retries automatically one minute later.
  • A banner declared in a layout with app:adUnitId loads automatically. Calling loadAd() on it cancels the request in progress and sends a second one.
  • Set the ad unit ID only once. Assigning a different ad unit ID to a banner that already has one throws an IllegalArgumentException, so do not reuse the same instance for different ad units.
  • In Jetpack Compose, create the banner with remember and call loadAd() in the factory block of AndroidView, never in update, which runs on every recomposition.
  • Choose one integration: AppOpenManager or your own AppOpenAd. The manager already shows an ad every time the app returns to the foreground, so showing another one manually at the same moment would display two ads in a row.
  • Do not expect an ad on the first app launch with AppOpenManager. The first ad is being loaded at that moment, and it is shown the next time the app returns to the foreground.
  • Take into account that any return to the foreground counts, including coming back from an ad click or from another app. If you need to limit how often these ads appear, use AppOpenAd and decide when to call showAd().
  • Call destroy() on every banner when its screen is destroyed. A banner holds system listeners, timers and the ad view of the network that filled it, and it only releases them in destroy().
  • Call destroy() on fullscreen ads, native ads and native ad loaders when they are no longer needed.
  • Do not keep ads created with an Activity in static fields or singletons. The ad holds a reference to the context it was created with.
  • Use test mode or the test ad units during development, and never click on real ads. Impressions and clicks made by the developers on real ads are invalid traffic and can get the account penalized.

  • Enable test mode only in debug builds. Test mode is not persisted, so it must be set on every launch before loading ads, and an app published with it enabled does not generate revenue:

    AdSettings.testEnabled = BuildConfig.DEBUG
  • The SDK is initialized in Application.onCreate with the app key of the app.
  • The com.google.android.gms.ads.APPLICATION_ID meta-data contains the Google App ID shown in the Wortise dashboard for the app.
  • Every ad uses its production ad unit ID: no test-… ad unit is left in the code.
  • Test mode is disabled in release builds.
  • The user consent is requested before the first ad is loaded.
  • Fullscreen ads are shown only after checking isAvailable, and the app continues when an ad is not available.
  • Banners, fullscreen ads and native ads are destroyed with their screens.
  • Apps directed to children use android-sdk-families and follow the Families program checklist.
  • A release build (with R8 enabled, if you use it) has been tested on a real device. No additional ProGuard rules are required.