Native Ads: Google

Integrate native ads (Google)

NativeAdView

  • Native ad assets of GoogleMobileAds SDK are required to be encapsulated within a parent view of a specific type NativeAdView.

  • The same view must be passed to AATKit via the NativeAdData method: attachToLayout.

Also, Google displays the native ad main image using an instance of MediaView.

private NativeAdView containerView;
private TextView titleView;
private TextView descriptionView;
private MediaView mediaView;
private ImageView iconView;
private TextView advertiserView;
private TextView ctaView;

Bind Google Native Ad Assets

After getting a native ad from the NativeAdPlacement, you can follow this code example to bind the native ad assets:

private void setupGoogleAd(NativeAdData nativeAd) {
    // Title
    containerView.setHeadlineView(titleView);
    titleView.setText(nativeAd.getTitle());

    // Ad Icon
    containerView.setIconView(iconView);
    loadImage(iconView, nativeAd.getIconUrl());

    // Body
    containerView.setBodyView(descriptionView);
    descriptionView.setText(nativeAd.getDescription());

    // MediaView
    containerView.setMediaView(mediaView); //Google SDK will fill the passed MediaView automatically

    // Advertiser
    containerView.setAdvertiserView(advertiserView);
    advertiserView.setText(nativeAd.getAdvertiser());

    // CallToAction
    containerView.setCallToActionView(ctaView);
    ctaView.setText(nativeAd.getCallToAction());

    nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView);
}

Change Native Ad AdChoicesIconPosition

You can choose from the following values to position the AdChoices icon within your native ad layout: TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT

AATKit.setAdChoicesIconPosition(AATKit.AdChoicesIconPosition.TOP_LEFT);

Last updated