Mediate Google AdMob
- Instructions for passing user’s ad preference to AdMob
- Set up content mapping for AdMob
- Download and Integration
- Set up AdMob Rewarded Video Demand
- Mediate AdMob Native Ad Demand
- Best Practices
- Test Ad
Instructions for passing user’s ad preference to AdMob
Publishers must work with Google for GDPR compliance by collecting consents on their own. To faciliate the process, the AdMob adapters (Android: 15.0.0.x / iOS: 7.30.0.x) will forward the user’s npa preference to Google. Publishers must make sure to complete the remaining steps below in their app:
Android
- In your implementation, before you initialize the MoPub SDK, create a
Bundle, and pass in the following value if the user does not consent to receive personalized ads:Bundle extras = new Bundle(); extras.putString("npa", "1"); - In your
SdkConfigurationobject, pass thatBundleto the applicable AdMob adapters (all if the user does not consent to receive personalized ads for any ad format):SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(adUnitId) .withMediationSettings(new GooglePlayServicesBanner.GooglePlayServicesMediationSettings(extras), new GooglePlayServicesInterstitial.GooglePlayServicesMediationSettings(extras), new GooglePlayServicesRewardedVideo.GooglePlayServicesMediationSettings(extras), new GooglePlayServicesNative.GooglePlayServicesMediationSettings(extras)) .build();
iOS
- In your implementation, before you initialize the MoPub SDK, create an instance of
MPGoogleGlobalMediationSettings, and pass in the following value if the user does not consent to receive personalized ads:MPGoogleGlobalMediationSettings *mediationSettings = [[MPGoogleGlobalMediationSettings alloc] init]; mediationSettings.npa = @"1"; -
In your
MPMoPubConfigurationobject, pass in your instance ofMPGoogleGlobalMediationSettings, and initialize withMPMoPubConfiguration:MPMoPubConfiguration *sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization: @"AD_UNIT_ID"]; sdkConfig.globalMediationSettings = [[NSArray alloc] initWithObjects:mediationSettings, nil]; [[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:^{ NSLog(@"SDK initialization complete"); }];
Unity
-
In your implementation, when you initialize the MoPub SDK, create an instance of
MediationSetting, and pass in the following value if the user does not consent to receive personalized ads:MoPub.InitializeSdk(new MoPubBase.SdkConfiguration { AdUnitId = anyAdUnitId, MediationSettings = new[] {new MoPub.MediationSetting.AdMob { {"npa", "1"} } } });
For additional context, please visit the AdMob articles (Android / iOS) on forwarding consent to the Mobile Ads SDK.
Set up content mapping for AdMob
AdMob allows publishers to pass a URL String to target using content mapping. The adapters have been updated to pass this URL resource to the AdMob ad request. Publishers only need to do the following steps in their implementation before sending out the ad request:
Android
-
Create a
Mapto hold a key-value pair. The key should becontentUrl, and the value will be the URL String you’d like to pass to AdMob.Map<String, Object> localExtras = new HashMap<>(); localExtras.put("contentUrl", "www.example.com"); -
Depending on the ad format you are integrating, pass the
Mapcreated from step 1 to the correct API, shown below:// Banner MoPubView.setLocalExtras(localExtras); // Interstitial MoPubInterstitial.setLocalExtras(localExtras); // Rewarded Video // Publishers are to pass the content URL String at the time of initializing the MoPub SDK, like so: // Pass the GooglePlayServicesMediationSettings to the SDK's initialization call from the "Instructions for passing user's ad preference to AdMob" section: SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(adUnitId) .withMediationSettings(new GooglePlayServicesRewardedVideo.GooglePlayServicesMediationSettings(npaBundle, "http://www.example.com")) .build(); // Native MoPubNative.setLocalExtras(localExtras); -
Make your ad request.
iOS
-
Create an
NSDictionaryto hold a key-value pair. The key should becontentUrl, and the value will be the URL String you’d like to pass to AdMob.NSDictionary *localExtras = @{@"contentUrl" : @"www.example.com"}; - Depending on the ad format you are integrating, pass the
NSDictionarycreated from step 1 to the correct API, shown below:// 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; - Make your ad request.
Download and Integration
To download the AdMob adapters, navigate to the Mediation Integration Tool. You will also need to download the Mobile Ads SDK, which can be found below.
For the latest download and integration instructions, ensure that you have consulted Google’s tutorials before you integrate the SDK and adapters.
| iOS | Download |
| Android | Download |
-
AdMob App ID
-
Android
Publishers must add their AdMob App ID to the app’s AndroidManifest as a child of the
<application></application>tag. This is a required step as of v17.0.0 of the Mobile Ads SDK. Failure to do so results in a crash. More information can be found on this page.<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="[ADMOB_APP_ID]"/>
-
Set up AdMob Rewarded Video Demand
- Navigate to the Networks section of your MoPub UI, select the “Add A Network”.
- Select
AdMobas the network. - Paste the AdMob ad unit ID to the “Ad Unit ID” field.
To access AdMob network reports for these formats, make sure to enter the network ids in the Google networks sections as shown below.
-
Once you enable reporting as below for AdMob:

-
Configure Admob ad unit IDs against the native MoPub ad unit IDs of your app as below:

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. Ensure to set the preferred position before the ad request. The icon will be rendered in the topright corner by default if no custom position is set.
iOS
Call setAdChoicesPosition: from MPGoogleAdMobNativeCustomEvent with your preferred GADAdChoicesPosition position:
[MPGoogleAdMobNativeCustomEvent setAdChoicesPosition:GADAdChoicesPositionBottomRightCorner];
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 using the below API:
- 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.
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"]];
}
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, it’s important to 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 might cause the AdChoices icon to be rendered on top of margins.
-
Layouts with empty views used as padding/margins:

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

-
Layouts with a margin on the outermost view.

Note: The Google Mobile Ads SDK considers the bounds of the top level view of the layout used to create the MoPub
ViewHolderto define the bounds of the native ad’s presentation, and will place theAdChoicesicon in one of the corners of those bounds.
The Google Mobile Ads SDK supports a different setting to allow publishers 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, please contact your account manager to request this feature. Once your account is whitelisted to use the customized Ad Choices placement, follow the below steps.
Android
-
Modify your ad view layout by wrapping the MoPub privacy information icon with a
FrameLayoutwith 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" />You should 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
FrameLayoutas an extra to theViewBinderthat would be provided to theGooglePlayServicesAdRendererusing the keyGooglePlayServicesAdRenderer.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
AdChoicesicon not visible when usingCardViewas the view passed to MoPub.
Test Ad
While testing your SDK integrations and network setups, it is recommended that you leverage test ad placements. To set up test mode, please reference Google’s test ad article for Android and iOS for instructions.
Last updated December 18, 2018
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.
© 2018 MoPub Inc.