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: "/6499/example/native",
    rootViewController: self,
    adTypes: [ ... ad type constants ... ],
    options: [ ... ad loader options objects ... ])

Objective-C

self.adLoader = [[GADAdLoader alloc]
      initWithAdUnitID:@"/6499/example/native"
    rootViewController:rootViewController
               adTypes:@[ ... ad type constants ... ]
               options:@[ ... ad loader options objects ... ]];

GADNativeAdImageAdLoaderOptions

GADNativeAdImageAdLoaderOptions contains properties relating to images in native ads. Apps can control how a GADAdLoader handles 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: "/6499/example/native",
    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:@"/6499/example/native"
    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.

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

Swift

let videoOptions = GADVideoOptions()
// Ads start muted by default. Set to false to start video ads with sound.
videoOptions.startMuted = false
adLoader = GADAdLoader(
    adUnitID: "/6499/example/native",
    rootViewController: self,
    adTypes: [ ... ad type constants ... ],
    options: [videoOptions])

Objective-C

GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
// Ads start muted by default. Set to NO to start video ads with sound.
videoOptions.startMuted = NO;
self.adLoader = [[GADAdLoader alloc]
      initWithAdUnitID:@"/6499/example/native"
    rootViewController:self
               adTypes:@[ ... ad type constants ... ]
               options:@[videoOptions]];

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.