Set up direct access for Ad Exchange

Select platform: Android (beta)New-selected Android iOS

The Google Mobile Ads SDK supports monetizing your apps with an Ad Exchange property . This guide shows you how to configure your apps for all ad formats supported by Ad Exchange.

Prerequisites

Configure your app for accessing Ad Exchange

Add your Ad Manager app ID ( identified in the Ad Manager UI ) to your app's AndroidManifest.xml file through a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID" . For android:value , insert your own Ad Manager app ID, surrounded by quotation marks.

 <manifest>  
<application>  
<!--  
Sample  
Ad  
Manager  
app  
ID:  
ca-app-pub-3940256099942544~3347511713  
-->  
<meta-data  
android:name="com.google.android.gms.ads.APPLICATION_ID"  
android:value="ca-app-pub-xxxxxxxxxxxxxx>xx~yy<yyyyyyyy&quo>t<;/  
/a>p 
plication
/manifest

Note also that failure to add the <meta-data> tag as shown above results in a crash with the message:

 Missing application ID. 

Next, you can initialize the Google Mobile Ads SDK and select an ad format to display. The rest of this guide implements the banner format to illustrate how you can load an ad from Ad Exchange. The same steps can apply to any ad formats supported by the Google Mobile Ads SDK.

Load an ad from Ad Exchange

You can use an Ad Exchange web property code with a trailing forward slash, in place of an ad unit ID. For example, ca-mb-app-pub-5629679302779023/ .

The following example adds the Ad Exchange web property code to a banner ad request:

Kotlin

  val 
  
 adRequest 
  
 = 
  
 BannerAdRequest 
 . 
 Builder 
 ( 
 "ca-mb-app-pub-5629679302779023/" 
 , 
  
 AdSize 
 . 
 BANNER 
 ). 
 build 
 () 
 BannerAd 
 . 
 load 
 ( 
  
 adRequest 
 , 
  
 object 
  
 : 
  
 AdLo<adCallba>ckBannerAd 
  
 { 
  
 override 
  
 fun 
  
 onAdLoaded 
 ( 
 ad 
 : 
  
 BannerAd 
 ) 
  
 { 
  
 bannerAd 
  
 = 
  
 ad 
  
 activity 
 ?. 
 runOnUiThread 
  
 { 
  
 binding 
 . 
 bannerViewContainer 
 . 
 addView 
 ( 
 ad 
 . 
 getView 
 ( 
 requireActivity 
 ())) 
  
 } 
  
 
 } 
  
 } 
 ) 

Java

  BannerAdRequest 
  
 adRequest 
  
 = 
  
 new 
  
 BannerAdRequest 
 . 
 Builder 
 ( 
 "ca-mb-app-pub-5629679302779023/" 
 , 
  
 AdSize 
 . 
 BANNER 
 ). 
 build 
 (); 
 BannerAd 
 . 
 load 
 ( 
  
 adRequest 
 , 
  
 new 
  
 AdLo<adCallba>ckBannerAd 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onAdLoaded 
 ( 
 @NonNull 
  
 BannerAd 
  
 ad 
 ) 
  
 { 
  
 bannerAd 
  
 = 
  
 ad 
 ; 
  
 runOnUiThread 
 ( 
 > 
 () 
  
 - 
  
 binding 
 . 
 bannerViewContainer 
 . 
 addView 
 ( 
 ad 
 . 
 getView 
 ( 
 MainActivity 
 . 
 this 
 ))); 
  
 
 } 
  
 }); 

Note that failure to add a trailing forward slash to the Ad Exchange web property code results in an ad request error with the message:

 Invalid Request. Cannot determine request type. Is your ad unit id correct? 

You can also convert an Ad Exchange web property code into an ad unit. Afterwards, use the Ad Manager UI to generate an Ad Exchange Tag and copy it into your app. The generated tag should have the Ad Exchange web property code, followed by descendant ad unit IDs without a trailing forward slash, for example: ca-mb-app-pub-5629679302779023/banner .

That's it! Your app is now ready to load and display banner ads from Ad Exchange.

In addition, you can use an Ad Exchange web property to load and display other ad formats from Ad Exchange by following respective guides:

(Approved European publishers only) Add price floors

You can submit a request for the "Price floors" feature .

Once approved, you can include a public floor or private floor in the ad request using the pubf and pvtf parameters respectively. In the following code example, replace "123" with the floor prices in micros and your network's default currency . Example of how micros are applied: if your default currency is USD, entering "6000000" is the equivalent of $6.00.

Kotlin

  val 
  
 extras 
  
 = 
  
 Bundle 
 (); 
 // Public floor parameter. 
 extras 
 . 
 putString 
 ( 
 "pubf" 
 , 
  
 "123" 
 ); 
 // Private floor parameter. 
 extras 
 . 
 putString 
 ( 
 "pvtf" 
 , 
  
 "123" 
 ); 
 val 
  
 request 
  
 = 
  
 AdRequest 
 . 
 Builder 
 ( 
 "ca-mb-app-pub-5629679302779023/" 
 ) 
 
  
 . 
 setGoogleExtrasBundle 
 ( 
 extras 
 ) 
  
 . 
 build 
 (); 

Java

  Bundle 
  
 extras 
  
 = 
  
 new 
  
 Bundle 
 (); 
 // Public floor parameter. 
 extras 
 . 
 putString 
 ( 
 "pubf" 
 , 
  
 "123" 
 ); 
 // Private floor parameter. 
 extras 
 . 
 putString 
 ( 
 "pvtf" 
 , 
  
 "123" 
 ); 
 AdRequest 
  
 request 
  
 = 
  
 new 
  
 AdRequest 
 . 
 Builder 
 ( 
 "ca-mb-app-pub-5629679302779023/" 
 ) 
 
  
 . 
 setGoogleExtrasBundle 
 ( 
 extras 
 ) 
  
 . 
 build 
 (); 
Design a Mobile Site
View Site in Mobile | Classic
Share by: