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.

  • Call WortiseSdk.initialize once, when the app starts, and wait for it to complete before using any ad. An ad requested before the SDK has been initialized fails with SDK_NOT_INITIALIZED. This also applies to the BannerAd widget, which requests its ad as soon as it is added to the layout:

    bool _sdkReady = false;
    Future<void> _initializeSdk() async {
    await WortiseSdk.initialize('your app key');
    await ConsentManager.requestIfRequired();
    setState(() => _sdkReady = true);
    _interstitialAd.loadAd();
    }
    /* ... */
    // In the children of your layout: the banner is added only when the SDK is ready
    if (_sdkReady)
    SizedBox(
    height: 50,
    child: BannerAd(adUnitId: 'Wortise Ad Unit ID'),
    ),
  • Do not wait for the initialization before calling runApp. WortiseSdk.initialize completes after the SDK has downloaded its configuration, so awaiting it in main() delays the first frame of the app for as long as the network takes.

  • Apply the privacy settings before initializing the SDK. AdSettings.setChildDirected and AdSettings.setMaxAdContentRating must be called before WortiseSdk.initialize.

  • 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. See User consent.
  • Do not read the result of requestIfRequired as the user’s answer. The returned value only tells whether the dialog has been shown. Use ConsentManager.canRequestPersonalizedAds or ConsentManager.canCollectData to know what the user has granted.
  • On iOS, if your app requests the App Tracking Transparency authorization, do it before the first ad is requested. Requesting it is optional, and neither the plugin nor the iOS SDK shows this prompt. See App Tracking Transparency.
  • Create each InterstitialAd, RewardedAd, AppOpenAd and NativeAdLoader once, outside of build(), and keep it in a field. Loading takes time, so an ad created at the moment it has to be shown will not be ready, and an object created in build() is created again on every rebuild.

  • Use a single object for each ad unit ID. The events are delivered through a channel that is identified by the ad unit ID, and both objects share the same underlying ad: a second object with the same ID takes the events from the first one, and destroying either of them destroys the ad of both.

  • 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. Check isAvailable first.

  • Let the SDK load the next ad. A fullscreen ad can be shown only once. Set reloadOnDismissed: true in InterstitialAd and RewardedAd, or autoReload: true in AppOpenAd, to load a new ad when the current one is dismissed.

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

    import 'dart:math';
    /* ... */
    _interstitialAd = InterstitialAd('Wortise Ad Unit ID', listener: (event, args) async {
    if (event == InterstitialAdEvent.FAILED_TO_LOAD) {
    final cooldown = await _interstitialAd.cooldownRemainingMs;
    Future.delayed(
    Duration(milliseconds: max(cooldown, 30000)),
    _interstitialAd.loadAd,
    );
    }
    });
  • Check the value returned by showAd(). It completes with false when there is no ad available, and in that case no FAILED_TO_SHOW or DISMISSED event is sent. If the app waits for DISMISSED to continue (for example, to move to the next screen), it must continue by itself when the result is false:

    if (!await _interstitialAd.showAd()) {
    _continue();
    }
  • Grant the reward of a rewarded ad only in the COMPLETED event, and only when its success argument is true. SHOWN and DISMISSED are also sent when the user closes the ad without completing it.

  • Give the BannerAd widget a parent with a bounded height. With AdSize.MATCH_VIEW and the anchored adaptive size, the widget takes all the height of its parent until the ad has been loaded, which causes a layout error when the parent does not limit it, such as a Column or a ListView.
  • Do not recreate the widget to refresh or retry the ad. The banner refreshes automatically, and it also retries by itself after a failed load. Every new BannerAd state (for example, when its key changes or when it is rebuilt inside a different parent) creates a new banner and makes a new ad request.
  • Decide the parameters of the banner before adding it. adUnitId, adSize, autoRefreshTime and requestParameters are read when the banner is created; changing them in a later rebuild has no effect.
  • Set keepAlive: true for banners inside scrollable lists. Otherwise the state of the widget is discarded when it scrolls out of the screen, and a new banner is created, with a new ad request, every time it comes back.
  • Express autoRefreshTime in milliseconds. The valid range goes from 30000 to 120000.
  • Register the ad with AppOpenManager.register. The default AppOpenManager constructor does not listen to the app lifecycle, so it never shows the ad. Only one manager can be registered at a time: a new registration replaces the previous one.

  • Load the ad and enable autoReload when using the manager. The manager shows the ad only if it is already available when the app comes to the foreground; it does not load it:

    final appOpenAd = AppOpenAd('Wortise Ad Unit ID', autoReload: true)..loadAd();
    AppOpenManager.register(appOpenAd);
  • Use the manual integration when the ad must not be shown on every return to the app. The manager shows the ad every time the app comes to the foreground while there is one available. With tryToShowAd() the app decides when it is shown.

  • Register the native ad factory on Android and on iOS, with the same identifier that is passed to NativeAdLoader. loadAd() throws an exception when the factory is not found. See Native.
  • Destroy every NativeAd that is no longer displayed. Each LOADED event delivers a new NativeAd. Call destroy() on the previous one when it is replaced, and remove its AdWidget from the layout: an AdWidget cannot display an ad that has been destroyed.
  • Call destroy() on fullscreen ads, native ads and native ad loaders when they are no longer needed, typically in the dispose() method of the State that owns them. The plugin keeps each ad in memory until it is destroyed. Destroying a NativeAdLoader does not destroy the ads it has delivered.
  • 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:

    await AdSettings.setTestEnabled(kDebugMode);
  • Test the first launch after a fresh install, on both platforms. The SDK stores the app key after the first initialization, so an ad that is requested too early only fails the first time the app is opened.

  • WortiseSdk.initialize is called with the app key of the app, and no ad is requested before it completes.
  • AndroidManifest.xml and Info.plist contain the Google App ID shown in the Wortise dashboard for the app.
  • Info.plist contains the SKAdNetworkItems list and, if the app requests the tracking authorization, the NSUserTrackingUsageDescription key.
  • 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.
  • The result of showAd() is checked, and the app continues when an ad is not available.
  • The reward of rewarded ads is granted only in COMPLETED with success set to true.
  • Fullscreen ads, native ads and native ad loaders are destroyed when their screen is disposed.
  • A release build has been tested on a real Android device and on a real iOS device, starting from a fresh install.