Mediation

This guide shows you how to integrate a mediation adapter with your Flutter app and set up additional request parameters.

Prerequisites

Initialize the Mobile Ads SDK

The quick start guide shows you how to initialize the Mobile Ads SDK. During that initialization call, mediation and bidding adapters also get initialized. It is important to wait for initialization to complete before you load ads in order to ensure full participation from every ad network on the first ad request.

The sample code below shows how you can check each adapter's initialization status prior to making an ad request.

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  MobileAds.instance.initialize()
    .then((initializationStatus) {
      initializationStatus.adapterStatuses.forEach((key, value) {
        debugPrint('Adapter status for $key: ${value.description}');
      });
  });
  
  runApp(MyApp());
}

Add dependencies for partner networks

The mediation adapters and their dependencies need to be added to your Android and iOS projects. They can be added by updating your app level build.gradle file on Android and Podfile on iOS. Google has open source adapters in GitHub for both Android and iOS.

See the Android and iOS documentation for each partner network for detailed guidance of how to add their adapter in your app.

Check which ad network adapter class loaded the ad

The sample code below demonstrates how to log the ad network class name for a banner ad:

final bannerAd = BannerAd(
      size: AdSize.banner,
      adUnitId: '<your-ad-unit>',
      listener: BannerAdListener(
        onAdLoaded: (ad) {
          debugPrint('$ad loaded: ${ad.responseInfo?.mediationAdapterClassName}');
        },
      ),
      request: AdRequest(),
    );

Rewarded ads mediation

We recommend that you override all default reward values by setting reward values in the AdMob UI. To do this, select the Apply to all networks in Mediation groups box so that the reward is consistent across all networks. Some ad networks don't provide a reward value or type at all. By overriding the reward value, the reward is consistent no matter which ad network served the ad.

For more information on setting reward values in the AdMob UI, refer to create a rewarded ad unit.

Native ads mediation

The following are some best practices to consider when implementing native mediation.

Native ad presentation policy

Each ad network has its own policies. When using mediation, it's important to remember that your app still needs to abide by the policies of the mediated network that provided the ad.