<br />

<br />

This guide shows you how to integrate a mediation adapter with your
Flutter app.

## Prerequisites

Before you can integrate mediation for an ad format, you need to integrate that
ad format into your app:

- [Banner Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/banner.md.txt)
- [Interstitial Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/interstitial.md.txt)
- [Native Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/native.md.txt)
- [Rewarded Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/rewarded.md.txt)
- [Rewarded Interstitial
  Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/rewarded-interstitial)

New to mediation? Read

[Introduction to mediation](https://support.google.com/admanager/answer/6272813).

## Initialize Google Mobile Ads Flutter Plugin

The quick start guide shows you how to [initialize the Google Mobile Ads Flutter Plugin](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/quick-start.md.txt#initialize_the_mobile_ads_sdk).
During that initialization call, mediation adapters also
get initialized. It is important to wait for initialization to complete before
you load ads in order to verify full participation from every ad network on the
first ad request.

> [!IMPORTANT]
> **Important:** Bidding adapters require you to explicitly initialize Google Mobile Ads Flutter Plugin.

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

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

## Update your gradle settings (Android only)

Add the following lines to your `settings.gradle` file, so you can use the
plugin's Android APIs:

```dart
def flutterSdkPath = {
    def properties = new Properties()
    file("local.properties").withInputStream { properties.load(it) }
    def flutterSdkPath = properties.getProperty("flutter.sdk")
    assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
    return flutterSdkPath
}()

includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
```

## 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](https://github.com/googleads/googleads-mobile-android-mediation/tree/master/ThirdPartyAdapters)
and
[iOS](https://github.com/googleads/googleads-mobile-ios-mediation/tree/main/adapters).

See the
[Android](https://developers.google.com/ad-manager/mobile-ads-sdk/android/choose-networks.md.txt#network_details)
and
[iOS](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/choose-networks.md.txt#network_details)
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 following sample code demonstrates how to log the ad network class name for
a banner ad:

```dart
final bannerAd = AdManagerBannerAd(
      size: [AdSize.banner],
      adUnitId: '<your-ad-unit>',
      listener: AdManagerBannerAdListener(
        onAdLoaded: (ad) {
          debugPrint('$ad loaded: ${ad.responseInfo?.mediationAdapterClassName}');
        },
      ),
      request: AdManagerAdRequest(),
    );
```

<br />

## Use banner ads with mediation

Make sure to disable refresh in all third-party ad source UIs for banner ad
units used in mediation. This prevents a
double refresh since Ad Manager also triggers a refresh
based on your banner ad unit's refresh rate.

## Use native ads with 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.

## US states privacy laws and GDPR

If you need to comply with the [U.S. states privacy
laws](https://support.google.com/admanager/answer/9561023) or [General Data Protection
Regulation (GDPR)](https://support.google.com/admanager/answer/7666366), follow the
steps in [US state regulations
settings](https://support.google.com/admanager/answer/10115735) or [GDPR
settings](https://support.google.com/admanager/answer/10113006#adding_ad_partners_to_published_gdpr_messages) to add your
mediation partners in Ad Manager Privacy \& messaging's
US states or GDPR ad partners list. Failure to do so can lead to partners
failing to serve ads on your app.

Learn more about enabling [restricted data processing
(RDP)](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/privacy/us-states) and obtaining GDPR consent with the
[Google User Messaging Platform (UMP) SDK](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/privacy.md.txt).