Mediate Google AdMob

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

  1. 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");
    
  2. In your SdkConfiguration object, pass that Bundle to 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

  1. 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";
    
  2. In your MPMoPubConfiguration object, pass in your instance of MPGoogleGlobalMediationSettings, and initialize with MPMoPubConfiguration:

     MPMoPubConfiguration *sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization: @"AD_UNIT_ID"];
    
     sdkConfig.globalMediationSettings = [[NSArray alloc] initWithObjects:mediationSettings, nil];
      [[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:^{
         NSLog(@"SDK initialization complete");
     }];
    

For additional context, please visit the AdMob articles (Android / iOS) on forwarding consent to the Mobile Ads SDK.

Mediate Google AdMob Rewarded Video Demand

Follow these steps to setup Google rewarded video demand

  • Ensure the correct Rewarded Video adapters are added to your project. You can find iOS adapters here and Android adapters here.
  • Navigate to the Networks section of your UI, select the “Add A Network”.
  • Select AdMob as the network.
  • Recommended value for Custom Event Class Data’ fields: {"adunit":"<enter your AdMob ad unit id here>"}

To access AdMob network reports for these formats, make sure to enter the network ids in the Google networks sections as shown below.

  1. Once you enable reporting as below for AdMob

    AdMob Network Page

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

    AdMob Network with AdMob IDs

Mediate Google AdMob Native Demand

Prerequisites

  • Recommended Google Mobile Ads SDK versions are as below
    • Google Mobile Ads SDK (iOS) - Google Mobile Ads SDK 7.19.0
    • Google play services SDK (Android) - Google Play Services 10.2.0
  • Minimum MoPub SDK version - MoPub SDK v4.9.0
  • Publishers interested in mediation with Google on native ads need to be whitelisted for Google’s Native Advanced (not Express) closed beta
  • In order to sign up for this beta, publishers must contact their Google Technical Account Manager. Once approved, they need to create a Native Advanced ad unit ID on the AdMob UI. Google’s Native Express ads are not eligible for mediation.

Set up AdMob Native Ads Mediation in the MoPub UI

Follow these steps to setup Google native demand

  • Navigate to the Networks section of your UI, select the “Add A Network”.
  • Select AdMob as the network.
  • Enter your AdMob ad unit id in the field provided. Changes will be automatically saved.

Access AdMob Network Reports in the MoPub UI

In order to access AdMob network reports, make sure enter the network ids in the Google networks sections as shown below.

  1. Once you enable reporting as below for AdMob’

Setup AdMob

  1. Configure Admob adunit ids against the native MoPub adunit of your app as below

Add AdMob adunit IDs

Integrate the Custom Event into your project

After you have set up your ad units in MoPub, simply import the Custom Event adapter into your project and add the Google Mobile Ads SDK (platform related instructions provided below).

You can download the AdMob Custom Events from our support page here.

Setting up your project

iOS

Drag and drop each of the .h and .m files into your Xcode project.

You can find the Google Mobile Ads SDK setup instructions here.

Google uses its own renderer to render ads, so you need to add MPGoogleAdMobNativeRenderer object to MoPubNative rendererConfigurations.

// MoPub renderer

MPNativeAdRendererConfiguration *mopubConfiguration =

  [MPStaticNativeAdRenderer rendererConfigurationWithRendererSettings:settings];

// Google renderer

MPNativeAdRendererConfiguration *googleConfiguration =

  [MPGoogleAdMobNativeRenderer rendererConfigurationWithRendererSettings:settings];

MPNativeAdRequest *adRequest =

  [MPNativeAdRequest requestWithAdUnitIdentifier:self.moPubID

                      rendererConfigurations:@[ mopubConfiguration, googleConfiguration ]];

AdChoices Options:

To set the preferred AdChoices icon position, call the MPGoogleAdMobNativeCustomEvent’s class method setAdChoicesPosition: with your preferred GADAdChoicesPosition.

Note: This needs to be set before requesting a native ad.

  [MPGoogleAdMobNativeCustomEvent setAdChoicesPosition:GADAdChoicesPositionBottomRightCorner];

Additional Assets (Optional):

Google also supports the following additional assets:

  • Star Rating
    • Textview showing the star rating on 5.
    • App install ads only.
  • Price
    • Textview showing price of the app.
    • App install ads only.
  • Store
    • Textview app store name.
    • App install ads only.
  • Advertiser
    • Textview showing the name of the advertiser.
    • Content ads only.

You can access those assets in the below method:

static NSString *const kGADMAdvertiserKey = @"advertiser";

static NSString *const kGADMPriceKey = @"price";

static NSString *const kGADMStoreKey = @"store";

- (void)layoutCustomAssetsWithProperties:(NSDictionary *)customProperties

                            imageLoader:(MPNativeAdRenderingImageLoader *)imageLoader {

 _priceLabel.text = [NSString stringWithFormat:@"%@", customProperties[@"price"]];

 _storeLabel.text = [NSString stringWithFormat:@"%@", customProperties[@"store"]];

}

Android

Copy the GooglePlayServicesNative.java and GooglePlayServicesAdRenderer.java files to com.mopub.nativeads package in the SDK project.

You can set up the Google Mobile Ads SDK by following the instructions here.

Google Play Services renderer:

Google uses its own renderer to render the ads, so you need to instantiate the GooglePlayServicesAdRenderer and register it to your MoPubNative. Note: You need to register GooglePlayServicesAdRenderer ahead of MoPubStaticNativeAdRenderer.

MoPubAdRenderer adRenderer = new GooglePlayServicesAdRenderer(mViewBinder);

MoPubNative moPubNative = new MoPubNative(MainActivity.this, adUnitId, mMoPubListener);

moPubNative.registerAdRenderer(adRenderer);

Additional assets (optional):

Google also supports the following additional assets:

  • Star Rating
    • Textview showing the star rating on 5.
    • App install ads only.
  • Price
    • Textview showing price of the app.
    • App install ads only.
  • Store
    • Textview app store name.
    • App install ads only.
  • Advertiser
    • Textview showing the name of the advertiser.
    • Content ads only.

To render these assets you need to provide the following additional views when instantiating your view binder.

mViewBinder = new ViewBinder.Builder(R.layout.native_ad_item)

        .mainImageId(R.id.native_main_image)

        .iconImageId(R.id.native_icon_image)

        .titleId(R.id.native_title)

        .textId(R.id.native_text)

        .callToActionId(R.id.native_cta)

        .privacyInformationIconImageId(R.id.native_privacy_information_icon_image)

        .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();

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 (in onNativeLoad callback) 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.

}

AdChoices Icon:

AdMob provides the option to select any of the four corners of the ad to render the AdChoices icon. The preference can be set using the extras passed to MoPubNative.

HashMap<String, Object> extras = new HashMap<>();

extras.put(GooglePlayServicesNative.KEY_EXTRA_AD_CHOICES_PLACEMENT,

              NativeAdOptions.ADCHOICES_TOP_LEFT);

moPubNative.setLocalExtras(extras);

Note: The AdChoices icon will be rendered by the AdMob SDK by default in the top right corner, if no preferred position is provided.

View Hierarchy Best Practices

AdMob renders the AdChoices icon in one of the four corners of the native ad view, as specified by the publisher (the top-right corner is the 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.

  1. Layouts with empty views used as padding/margins:

layout1

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

layout2

  1. 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 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

  1. Modify your ad view layout by wrapping the MoPub privacy 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"
              ... />

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>
  1. 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)

    .mainImageId(R.id.native_main_image)

    .iconImageId(R.id.native_icon_image)

    .titleId(R.id.native_title)

    .textId(R.id.native_text)

    .callToActionId(R.id.native_cta)

    .privacyInformationIconImageId(R.id.native_ad_daa_icon_image)

    .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)

     .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 - MoPub’s dashboard will report 0 impressions and clicks for AdMob.
  • Android - the AdChoices icon not visible when using CardView as 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 July 11, 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.