Skip to main content

Native Ad Options

Ad Request Timeout (default: 60 seconds)

If no ad response is received within the specified time (in seconds) after the ad request, the existing request is invalidated and the adLoader:didFailWithError:responseInfo: method of GFPAdLoaderDelegate is called.

self.adLoader?.requestTimeoutInterval = ...

GFPNativeAdRenderingSetting

info

This section covers only the most commonly used options. For the full list of all options provided by GFPNativeAdRenderingSetting, refer to Native Rendering Options.

DFP adChoicesView Position Setting

The DFP adChoiceView is rendered as an overlay. Therefore, one of the four corners where the adChoicesView will be automatically inserted must be left empty. The default position of the DFP adChoicesView is the top-right corner, and it can be configured via GFPNativeAdRenderingSetting's preferredAdChoicesViewPosition.

let renderingSetting = GFPNativeAdRenderingSetting()
renderingSetting.preferredAdChoicesViewPosition = .topRightCorner

let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = renderingSetting
info

The Google documentation states that manually registering an adChoiceView renders it directly onto the registered view rather than as an overlay, but this does not yet work correctly. If you want the adChoiceView rendered at a position other than the top-right, this setting is required.

Using Native Ads Without a Media View

To use a native ad without a media view (for example, a native ad composed only of an icon and a title/CTA button), set hasMediaView = NO on GFPNativeAdRenderingSetting. (The default value is YES.)

danger

If the presence of a media view in the native view does not match the GFPNativeAdRenderingSetting.hasMediaView state, an error will occur at the time of native ad rendering.

let setting = GFPNativeAdRenderingSetting()
setting.hasMediaView = false

let nativeOption = GFPAdNativeOptions()
nativeOption.renderingSetting = setting

Native Ad Lazy Loading

Enabling Lazy Loading

When lazy loading is enabled in the native rendering options, the native ad view object and text assets are first delivered via GFPAdLoaderDelegate.adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!), while the media view, icon view, and other assets are loaded asynchronously.

self.adLoader = GFPAdLoader(unitID: "UnitId", rootViewController: self, adParam: adParam)

let nativeOption = GFPAdNativeOptions()
nativeOptions.renderingSetting.useLazyMediaLoading = true
self.adLoader?.setNativeDelegate(self, nativeOptions: nativeOption)

self.adLoader?.delegate = self
self.adLoader?.loadAd()

Showing a Placeholder

A placeholder can be shown while media is loading asynchronously. The placeholder appears directly on top of the ad view and is automatically scaled to fit the view element's size.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) {
self.nativeAdView.nativeAd = nativeAd

self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

Async Media Loading Callbacks

When all media (media view, icon view, etc.) have finished loading asynchronously, nativeAdDidLoadMediaData(_:) of GFPNativeAdDelegate is called.

If any asset fails to load, nativeAdDidFail(toLoadMediaData:) is called.

// GFPNativeAdDelegate
func nativeAdDidLoadMediaData(_ nativeAd: GFPNativeAd) {
self.nativeAdView.removePlaceholders() // Optional for safety.
}

func nativeAdDidFail(toLoadMediaData nativeAd: GFPNativeAd) {
// Example showing new placeholders on failure.
self.nativeAdView.mediaView?.showPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_media_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}

self.nativeAdView.showIconPlaceholder { imageView in
imageView.image = UIImage(named: "my_fallback_icon_placeholder")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
}
}

GFPContentInfo

When applying a NativeNormal type ad as a Communication Ad, you must inject ContentInfo.

let adParam = GFPAdParam()
adParam.contentInfo = GFPContentInfo(
sourceType: "0001",
subtype: "menu",
sourceId: "30907206:7")