Native Ad Options

The last parameter included in the creation of the GADAdLoader is an optional array of objects. This section describes those options.

Swift

adLoader = GADAdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511",
    rootViewController: self,
    adTypes: [ ... ad type constants ... ],
    options: [ ... ad loader options objects ... ])

Objective-C

self.adLoader = [[GADAdLoader alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
    rootViewController:rootViewController
               adTypes:@[ ... ad type constants ... ]
               options:@[ ... ad loader options objects ... ]];

GADNativeAdImageAdLoaderOptions

GADNativeAdImageAdLoaderOptions contains properties relating to images in Native Advanced ads. Apps can control how a GADAdLoader handles Native Ads Advanced image assets by creating a GADNativeAdImageAdLoaderOptions object, setting its properties (disableImageLoading, preferredImageOrientation, and shouldRequestMultipleImages), and passing it in during initialization.

GADNativeAdImageAdLoaderOptions has the following properties:

disableImageLoading
Image assets for native ads are returned via instances of GADNativeAdImage, which contains image and imageURL properties. If disableImageLoading is set to false, which is the default (NO in Objective-C), the SDK will fetch image assets automatically and populate both the image and the imageURL properties for you. If it's set to true (or YES in Objective-C), the SDK will only populate imageURL, allowing you to download the actual images at your discretion. Use the mainImage property of GADMediaContent to set the image for the media view when manually downloading images.
preferredImageOrientation

Some creatives have multiple images available to match different device orientations. Apps can request images for a particular orientation by setting this property to one of the orientation constants:

  • GADNativeAdImageAdLoaderOptionsOrientationAny
  • GADNativeAdImageAdLoaderOptionsOrientationLandscape
  • GADNativeAdImageAdLoaderOptionsOrientationPortrait

    If you use preferredImageOrientation to specify a preference for landscape or portrait image orientation, the SDK will place images matching that orientation first in image asset arrays and place non-matching images after them. Since some ads will only have one orientation available, publishers should make sure that their apps can handle both landscape and portrait images.

    If this method is not called, the default value of GADNativeAdImageAdLoaderOptionsOrientationAny will be used.

shouldRequestMultipleImages

Some image assets will contain a series of images rather than just one. By setting this value to true, your app indicates that it's prepared to display all the images for any assets that have more than one. By setting it to false (the default) your app instructs the SDK to provide just the first image for any assets that contain a series.

If no GADAdLoaderOptions objects are passed in when initializing a GADAdLoader, the default value for each option will be used.

GADNativeAdViewAdOptions

GADNativeAdViewAdOptions objects are used to indicate preferences for how native ad views should represent ads. They have a single property: preferredAdChoicesPosition, which you can use to specify the location where the AdChoices icon should be placed. The icon can appear at any corner of the ad, and defaults to GADAdChoicesPositionTopRightCorner. The possible values for this property are:

  • GADAdChoicesPositionTopRightCorner
  • GADAdChoicesPositionTopLeftCorner
  • GADAdChoicesPositionBottomRightCorner
  • GADAdChoicesPositionBottomLeftCorner

Here's an example showing how to place the AdChoices icon in the top left corner of an ad:

Swift

let adViewOptions = GADNativeAdViewAdOptions()
adViewOptions.preferredAdChoicesPosition = .topLeftCorner
adLoader = GADAdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511",
    rootViewController: self,
    adTypes: [ ... ad type constants ... ],
    options: [ ... ad loader options objects ... ])

Objective-C

GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init];
adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner;
self.adLoader = [[GADAdLoader alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
    rootViewController:self
               adTypes:@[ ... ad type constants ...  ]
               options:@[ ... ad loader options objects ... ]];

GADVideoOptions

GADVideoOptions objects are used to indicate how native video assets should be displayed. They offer a single property: startMuted.

This boolean indicates whether video assets should begin playback in a muted state. The default value is true.

GADMultipleAdsAdLoaderOptions

GADMultipleAdsAdLoaderOptions objects allow publishers to instruct an ad loader to load multiple ads in a single request. Ads loaded in this way are guaranteed to be unique. GADMultipleAdsAdLoaderOptions has a single property, numberOfAds, which represents the number of ads the ad loader should attempt to return for the request. By default this value is one, and it's capped at a maximum of five (even if an app requests more ads, at most five will be returned). The actual number of ads returned is not guaranteed, but will be between zero and numberOfAds.

GADNativeAdMediaAdLoaderOptions

To use this feature, include the GADNativeAdMediaAdLoaderOptions class in the native ad options array in the GADAdLoader initialization.

GADNativeAdMediaAdLoaderOptions objects allow you to select media aspect ratio preferences. The option is applied to both image and video. This class has one property: mediaAspectRatio, which you can use to specify the supported media aspect ratios. The possible values for this property are:

Objective-CSwift
GADMediaAspectRatioAny .any
GADMediaAspectRatioLandscape .landscape
GADMediaAspectRatioPortrait .portrait
GADMediaAspectRatioSquare .square

Setting mediaAspectRatio to one of these options will cause only ads with media of the specified aspect ratio to be returned. If this property is not set explicitly, the value will default to GADMediaAspectRatioUnknown and no restrictions on aspect ratios will be applied.

Send feedback about...

Need help? Visit our support page.