Skip to content

Best practices

This page gathers the rules that make an integration work reliably. Each one explains what the SDK does, so you know why it matters.

  • Initialize the SDK once, at app launch, before loading any ad. An ad requested before the first initialization fails with SDK_NOT_INITIALIZED. Calling initialize again later has no effect.
  • Call the SDK from the main thread. Initialization and the ad classes work with UIKit and do not switch threads by themselves.
  • Set the privacy options before initializing. WAAdSettings.childDirected and WAAdSettings.maxAdContentRating are applied when the SDK starts, so they should not be changed while the app is running. See Privacy.
  • Request the user consent on every launch, before the first ad request. The SDK never shows the consent dialog by itself. request(ifRequired:) only shows it when it is needed, and its completion handler is always called, so it is the right place to continue. See User consent.
  • If your app requests the App Tracking Transparency authorization, do it after the consent and before loading ads. Requesting it is optional, and the SDK does not show this prompt. See App Tracking Transparency.
  • Offer a way to change the consent. Call WAConsentManager.shared.request(_:) from a settings screen, as it always shows the dialog.

The recommended order at launch is: initialize, request consent, request ATT (if your app does), load ads.

  • Do not call loadAd() again when an ad is already available. A new load discards the ad that was ready and requests another one.
  • Do not retry immediately inside didFailToLoad. After a failed load, interstitial, rewarded, app open and native ads enter a cooldown (30 seconds by default) and any loadAd() call made during it is ignored, without invoking the delegate. Schedule the retry instead:
func didFailToLoad(interstitialAd: WAInterstitialAd, error: WAAdError) {
let delay = max(interstitialAd.cooldownRemaining, 30)
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
self?.interstitialAd.loadAd()
}
}
  • Load the next ad when the current one is dismissed. An interstitial, rewarded or app open ad can only be shown once, so call loadAd() in didDismiss to have the next one ready.
  • Check isAvailable before calling showAd(from:). If no ad is available the method returns without showing anything and without invoking the delegate, so the app must not wait for didDismiss or didFailToShow to continue.
  • Pass a view controller that is on screen and is not presenting another one. Otherwise the ad can not be presented.
  • Grant the reward in didComplete(rewardedAd:reward:). didDismiss is also invoked when the user closes the ad without earning the reward.
  • Set rootViewController before calling loadAd(). Without it, part of the demand can not be loaded and the banner fills less, or not at all.
  • Do not call loadAd() inside didFailToLoad. The banner retries by itself one minute after a failed load, and each manual call sends a new request.
  • Create each banner once. Create it when the screen is created (for example, in viewDidLoad) and not every time it appears, since every new instance sends a new request.
  • Let the SDK manage the auto-refresh. It is paused automatically while the banner is not visible or the app is in background. autoRefreshTime is expressed in seconds, accepts values between 30 and 120, and can be set to WABannerAd.autoRefreshDisabled to turn it off.
  • Call loadAd() once after getting the manager. WAAppOpenManager shows an ad when the app becomes active only if one is already loaded. After that first load, it reloads by itself every time an ad is closed.
  • Start the manager after the consent and ATT prompts. The app also becomes active when a system dialog is closed, so an ad loaded earlier could be shown right after it.
  • Keep a reference to every ad object. It is needed to show the ad later and to destroy it.
  • Call destroy() when an ad is no longer needed. Do it when the screen that owns the ad is closed. A banner, and any interstitial, rewarded or app open ad that has been loaded but not shown, stays in memory until it is destroyed.
  • Keep the delegate alive. WABannerAd, WAInterstitialAd, WARewardedAd and WAAppOpenAd hold their delegate weakly: an object created only to act as delegate is released immediately and no event is received.
  • Release the native ad loader explicitly. WANativeAdLoader holds its delegate strongly. When the delegate is the same object that owns the loader, destroy the loader and set the reference to nil when the screen is closed, as shown in Native. Destroy every WANativeAd that is no longer displayed too.
  • Use test ads while developing. Use the test ad units or enable the test mode, so development does not generate impressions and clicks on real ads.
  • Never ship the test mode. WAAdSettings.testEnabled makes every request a test request, which generates no revenue. Enable it only in debug builds:
#if DEBUG
WAAdSettings.testEnabled = true
#endif
  1. Info.plist contains your own GADApplicationIdentifier (with the ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy format), the SKAdNetworkItems list and, if the app requests the ATT authorization, NSUserTrackingUsageDescription.
  2. The SDK is initialized at launch with the app key of the app, taken from the dashboard.
  3. The consent is requested before the first ad request, followed by the ATT authorization if the app requests it.
  4. Every ad uses a production ad unit ID of its own format: no test- ad unit is left in the code.
  5. WAAdSettings.testEnabled is not enabled in release builds.
  6. If the app is directed to children, childDirected and maxAdContentRating are set before the initialization.
  7. Every banner has its rootViewController assigned.
  8. Every showAd(from:) call is guarded by isAvailable, and rewards are granted in didComplete.
  9. Every ad is destroyed when the screen that owns it is closed.
  10. A fresh install of the release build loads and shows every ad format. See Troubleshooting if it does not.