Google

If you plan to use the MoPub SDK to load and display ads from AdMob and Google Ad Manager via mediation, use this article for integration instructions and information unique to the ad network. To learn more about how MoPub mediation works, refer to our MoPub Network Mediation article.

Supported Ad Formats

Google currently supports the following ad formats. For support information, visit the Google AdMob homepage.

MoPub Formats Google Ad Formats
Banner Banner
Medium Rectangle Banner
Interstitial Interstitial
Rewarded Video Rewarded Video
Native Native

Download and Integrate

The same adapters and SDKs support both AdMob and Google Ad Manager. To download the adapters, navigate to the Mediation Integration Tool. You must also download the Mobile Ads SDK:

  • Download the Mobile Ads SDK for iOS

  • Download the Mobile Ads SDK for Android

    For Android, adapters are released as an Android Archive (AAR) file starting with version 17.1.2.4. The AAR includes any required Manifest data for AdMob and Google Ad Manager. You no longer need to update the AndroidManifest manually for any generic data, such as permissions and Activities. Any other app-level placement configuration required by Google must be manually entered into the AndroidManifest.

For the latest download and integration instructions, consult Google’s tutorials before you integrate the SDK and adapters.

Update Your AndroidManifest.xml and Info.plist

This is a required step starting with v17.0.0 of the Mobile Ads SDK. Failure to do this results in a crash.

  • If you mediate AdMob, refer to these Android and iOS instructions.

  • If you mediate Google Ad Manager, refer to these Android and iOS instructions.

Pass Data to Google

Google allows publishers to pass a URL String to target using content mapping, as well as test device IDs to activate test mode. To take advantage of data passing capabilities, you must use v17.1.2.2 or higher of the Android adapter, and v7.37.0.0 or higher of the iOS adapter. Then, follow the steps below in the implementation when you integrate the MoPub SDK.

Note that the adapters currently do not support Google Ad Manager Custom Targeting.

Android

  1. Create a Map to hold two key-value pairs, where the keys are case-sensitive.

    • For content mapping, the key is contentUrl, and the value is the URL String you want to pass to Google.
    • For test device IDs, the key is testDevices, and the value is the test device ID String of your device.
     Map<String, Object> localExtras = new HashMap<>();
     localExtras.put("contentUrl", "www.example.com");
     localExtras.put("testDevices", "0123456789");
    
  2. Depending on the ad format you are integrating, pass the Map created from step 1 to the correct API, as shown:

     // Banner
     MoPubView.setLocalExtras(localExtras);
    
     // Interstitial
     MoPubInterstitial.setLocalExtras(localExtras);
    
     // Rewarded Video
     // Pass the GooglePlayServicesMediationSettings to the SDK's initialization call
     SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(adUnitId)
     .withMediationSettings(new GooglePlayServicesRewardedVideo.GooglePlayServicesMediationSettings("http://www.example.com", "0123456789"))
     .build();
    
     // Native
     MoPubNative.setLocalExtras(localExtras);
    
  3. Make your ad request.

iOS

  1. Create an NSDictionary to hold two key-value pairs, where the keys are case-sensitive.

    • For content mapping, the key is contentUrl, and the value is the URL String you want to pass to Google.
    • For test device IDs, the key is testDevices, and the value is the test device ID String of your device.
     NSDictionary *localExtras = @{@"contentUrl" : @"www.example.com", @"testDevices" : @"0123456789"};
    
  2. Depending on the ad format you are integrating, pass the NSDictionary created from step 1 to the correct API, as shown:

     // Banner
     MPAdView.localExtras = localExtras;
    
     // Interstitial
     MPInterstitialAdController.localExtras = localExtras;
    
     // Rewarded Video
     [MPRewardedVideo loadRewardedVideoAdWithAdUnitID:self.info.ID keywords:self.info.keywords userDataKeywords:nil location:nil customerId:@"testCustomerId" mediationSettings:@[] localExtras:localExtras];
    
     // Native
     MPNativeAdRequestTargeting *targeting = [[MPNativeAdRequestTargeting alloc] init];
     targeting.localExtras = localExtras;
    
  3. Make your ad request.

Network Reporting

To access AdMob network reports:

  1. First, enable reporting for AdMob as shown:

    AdMob Network Page

  2. Then configure AdMob ad unit IDs against the native MoPub ad unit IDs of your app as shown:

    AdMob Network with AdMob IDs

Mediate AdMob Native Ad Demand

AdChoices Options

Google provides the option to select any of the four corners of the ad to render the AdChoices icon. To set a preferred AdChoices icon position for your app, follow the steps below. Be sure to set the preferred position before the ad request. The icon is rendered in the top right corner by default if no custom position is set.

  • For iOS:

    Call setAdChoicesPosition: from MPGoogleAdMobNativeCustomEvent with your preferred GADAdChoicesPosition position:

     [MPGoogleAdMobNativeCustomEvent setAdChoicesPosition:GADAdChoicesPositionBottomRightCorner];
    
  • For Android:

    Pass the preferred position to a HashMap, then pass the HashMap in the setLocalExtras() call:

     HashMap<String, Object> extras = new HashMap<>();
       
     extras.put(GooglePlayServicesNative.KEY_EXTRA_AD_CHOICES_PLACEMENT, NativeAdOptions.ADCHOICES_TOP_LEFT);
       
     moPubNative.setLocalExtras(extras);
    

(Optional) Additional Assets

Google also supports the following additional assets that you can access:

  • Star Rating (app-install ads only): Textview showing the star rating on 5.
  • Price (app-install ads only): Textview showing price of the app.
  • Store (app-install ads only): Textview app store name.
  • Advertiser (content ads only): Textview showing the name of the advertiser.

Use these APIs to access the additional assets:

  • For iOS:

     static NSString *const kGADMAdvertiserKey = @"advertiser";
     static NSString *const kGADMPriceKey = @"price";
     static NSString *const kGADMStoreKey = @"store";
       
     - (void)layoutCustomAssetsWithProperties:(NSDictionary *)customProperties {
       
         _priceLabel.text = [NSString stringWithFormat:@"%@", customProperties[@"price"]];
         _storeLabel.text = [NSString stringWithFormat:@"%@", customProperties[@"store"]];
     }
    
  • For Android:

     ViewBinder mViewBinder = new ViewBinder.Builder(R.layout.native_ad_item)
             // bind to the other required assets here
             .addExtra(GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_STAR_RATING,
                     R.id.native_star_rating)
             .addExtra(GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_PRICE,
                     R.id.native_price)
             .addExtra(GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_STORE,
                     R.id.native_store)
             .addExtra(GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_ADVERTISER,
                     R.id.native_advertiser)
             .build();
    

    Best Practices

MoPub Manual Integration

When using MoPub’s manual integration via AdapterHelper, avoid using a recycled view that once displayed an ad from AdMob to display one from another network, and vice versa. The following code snippet shows how to render and show ads when manually integrating:

if (nativeAd.getMoPubAdRenderer() instanceof GooglePlayServicesAdRenderer) {

   // When creating an AdMob ad using AdapterHelper's
   // getAdView(convertView, parent, nativeAd, viewBinder), do not pass a view used to
   // display an ad from another network as convertView instead let the AdapterHelper
   // create a new one. Views used to show another AdMob ad can be reused.

} else {
   // Create/show ads from other networks.
}

Margins

AdMob renders the AdChoices icon in one of the four corners of the native ad view by default. Some layout designs can cause this icon to appear to be outside the ad’s content area. The following are some examples of the view hierarchies that may cause the AdChoices icon to be rendered on top of margins.

  • Layouts with empty views used as padding/margins:

    layout1

  • Layout with margin on the child view (containing assets) relative to the outermost view.

    layout2

  • Layouts with a margin on the outermost view.

    layout3

Note: The Google Mobile Ads SDK considers the bounds of the top level view of the layout used to create the MoPub ViewHolder to define the bounds of the native ad’s presentation, and will place the AdChoices icon in one of the corners of those bounds.

The Google Mobile Ads SDK supports a different setting you can use to specify the location of the AdChoices placement, and it addresses the layouts with margins noted above. However, your account must be enabled by AdMob for this feature. If you are affected by this margin issue, and placing AdChoices in one of the four corners of the native ad view is not sufficient, contact your Google account manager to request this feature. Once your account is allowlisted to use the customized AdChoices placement, follow the steps below.

Android

  • Modify your ad view layout by wrapping the MoPub privacy information icon with a FrameLayout with the ID native_ad_choices_icon_container. For example, if your privacy icon layout looks like this:

     <ImageView android:id="@+id/native_ad_daa_icon_image"
                 android:layout_width="40dp"
                 android:layout_height="40dp"
                 android:padding="10dp" />
    

    Modify it to look like like this:

     <FrameLayout android:id="@+id/native_ad_choices_icon_container"
                 android:layout_width="40dp"
                 android:layout_height="40dp"
                 android:padding="10dp" >
        <ImageView android:id="@+id/native_ad_daa_icon_image"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent" />
     </FrameLayout>
    
  • Add the ID of the FrameLayout as an extra to the ViewBinder that would be provided to the GooglePlayServicesAdRenderer using the key GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_AD_CHOICES_ICON_CONTAINER.

     mViewBinder = new ViewBinder.Builder(R.layout.native_ad_item)
       // bind to the other required assets here
       .addExtra(GooglePlayServicesAdRenderer.VIEW_BINDER_KEY_AD_CHOICES_ICON_CONTAINER,
               R.id.native_ad_choices_icon_container)
       .build();
    

iOS

No additional code is required. The Google adapter will place its AdChoices icon in the same spot where you placed the MoPub privacy icon.

Known Issues

  • Android: the AdChoices icon not visible when using CardView as the view passed to MoPub.
  • Android: MoPub will not collect the advertising ID in pre-5.5 SDKs if com.google.android.gms:play-services-ads is missing. Please check the dependencies as mentioned here.

OAuth Authentication for Auto CPM

Refer to these Google instructions, about how to set up authentication through OAuth2 to use in the MoPub UI.

This setup is required to take advantage of Auto CPM.

Migrate to the AdMob Reporting API

If you set up Google Network Reporting before May 29, 2020, you are connected to their legacy AdSense API, which is being sunset by Google in the second half of 2021. To access the new AdMob Reporting API connection please follow these steps: revoking access and then linking their account again, which will automatically upgrade them to the new reporting API connection.

  1. In the Networks tab, select AdMob.
  2. Under Reporting Access, select Revoke Access.
  3. Under Reporting Access, select Link Account and re-enter your credentials. Save.

Test and Ad

As you test your SDK integrations and network setups, we recommend that you leverage test ad placements to ensure a consistent fill rate.

  • To set up test mode, follow the instructions in Google’s test ad article for Android and iOS for instructions.

  • For Google Ad Manager, refer to the Android and iOS articles.

With test mode enabled, you can request ads using the ad unit ID you created earlier for this purpose and receive a Google test ad. Be sure to disable test mode after testing!

Last updated September 17, 2020

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2020 MoPub (a division of Twitter, Inc.)