Migrate ad requests

This page covers the instructions to migrate ad requests.

Google Mobile Ads SDK (beta) requires you to pass the Ad Manager ad unit ID directly to the AdRequest object, rather than passing it to the load ad method.

Current

Kotlin

val adRequest = AdRequest.Builder().build()

InterstitialAd.load(
  this, "AD_UNIT_ID", adRequest,
  object : InterstitialAdLoadCallback() {
  }
)

Java

AdRequest adRequest = new AdRequest.Builder().build();

InterstitialAd.load(
  this, "AD_UNIT_ID", adRequest,
  new InterstitialAdLoadCallback() {
  }
);
Google Mobile Ads SDK (beta)

Kotlin

val adRequest = AdRequest.Builder("AD_UNIT_ID").build()

InterstitialAd.load(adRequest, object : AdLoadCallback<InterstitialAd> {})

Java

AdRequest adRequest = new AdRequest.Builder("AD_UNIT_ID").build();

InterstitialAd.load(adRequest, new AdLoadCallback<InterstitialAd>() {});

Pass extra parameters to Ad Manager

The following examples pass extra parameters to Ad Manager to request non-personalized ads:

Current

Kotlin

val extras = Bundle()
extras.putInt("npa", 1)
val request = AdRequest.Builder()
    .addNetworkExtrasBundle(AdMobAdapter::class.java, extras)
    .build()

Java

Bundle extras = new Bundle();
extras.putInt("npa", 1);
AdRequest request = new AdRequest.Builder()
    .addNetworkExtrasBundle(AdMobAdapter.class, extras)
    .build();
Google Mobile Ads SDK (beta)

Kotlin

val extras = Bundle()
extras.putInt("npa", 1)
val request = AdRequest.Builder("AD_UNIT_ID")
    .setGoogleExtrasBundle(extras)
    .build()

Java

Bundle extras = new Bundle();
extras.putInt("npa", 1);
AdRequest request = new AdRequest.Builder("AD_UNIT_ID")
    .setGoogleExtrasBundle(extras)
    .build();

Pass extra parameters to an ad source adapter

The following examples pass extra parameters to a sample ad source adapter. For details on passing extra parameters to a specific ad source adapter, see the corresponding ad source integration guide.

Current

Kotlin

val extras = Bundle()
extras.putString("exampleKey", "exampleValue")

val request = AdRequest.Builder()
    .addNetworkExtrasBundle(SampleAdapter::class, extras)
    .build()

Java

Bundle extras = new Bundle();
extras.putString("exampleKey", "exampleValue");

AdRequest request = new AdRequest.Builder()
    .addNetworkExtrasBundle(SampleAdapter.class, extras)
    .build();
Google Mobile Ads SDK (beta)

Kotlin

val extras = Bundle()
extras.putString("exampleKey", "exampleValue")

val request = AdRequest.Builder("AD_UNIT_ID")
    .putAdSourceExtrasBundle(SampleAdapter::class.java, extras)
    .build()

Java

Bundle extras = new Bundle();
extras.putString("exampleKey", "exampleValue");

AdRequest request = new AdRequest.Builder("AD_UNIT_ID")
    .putAdSourceExtrasBundle(SampleAdapter.class, extras)
    .build();