Skip to main content

Getting Started

A Native Normal Ad is an industry-standard native ad format composed of tweakable components such as title, body, call-to-action, icon, and media.

샘플 이미지

Prerequisites

Implementing View Controller

In the view controller that will present the ad view as subview,

  • add these properties

    GFPAdLoader *adLoader

    GFPNativeAd *nativeView

  • and implement these delegate protocols

    GFPAdLoaderDelegate

    GFPNativeAdDelegate

// MyViewController.h

import GFPSDK

class MyViewController : UIViewController, GFPAdLoaderDelegate, GFPNativeAdDelegate {
private var adLoader : GFPAdLoader?

private var nativeAd : GFPNativeAd?
private var nativeAdView : GFPNativeAdView?
}

GFPAdLoader

Initialize GFPAdLoader in your view controller, say, in viewDidLoad: and request an ad.

  • Provider GFPAdLoader with Ad Unit ID (essential) as registered on GFP dashboard, and GFPAdParam (optional) for better ad performance.

  • Set GFPAdLoaderDelegate on GFPAdLoader.

danger

Do not use GFPAdLoader instance for multiple ad requests, since it's only designed for single ad request.

override func viewDidLoad() {
super.viewDidLoad()

let adParam = GFPAdParam()
adParam.yearOfBirth = 1990
adParam.gender = .male
...

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

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

// Requesting Ad
self.adLoader?.delegate = self
self.adLoader?.loadAd()
}
info
  • If you are contracted to use the Communication Ad, provider GFPContentInfo in GFPAdParam
let adParam = GFPAdParam()
adParam.contentInfo = GFPContentInfo(
sourceType:0001,
subtype: “menu”,
sourceId:30907206:7)

Implementing Interface Builder

GFPNativeAd requires to be subclassed by an interface builder view. Create an .xib file with a view and subclass GFPNativeAdView and its subviews.

  1. In your .xib file, open Identity Inspector tab on Xcode, than set Custom Class to GFPNativeAdView. 예시이미지

  2. Add subviews that corresponds to title label, body label, etc. onto the GFPNativeAdView and connect them to outlets on the Connections Inspector tab.

  3. Add another subview than set its custom class as GFPMediaView. 예시이미지

danger

Do not allocate more than one GFPNativeAdView for one GFPNativeAd.

GFPAdLoaderDelegate

On Ad Load Success

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) {
...
}

On Ad Load Failure

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didFailWithError error: GFPError!, responseInfo: GFPLoadResponseInfo!) {
...
}

Copying Text Contents

On receiving a GFPNativeAd, it is necessary to copy the text contents into the text label subviews.

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) { 

// Set `GFPNativeAdDelegate`
self.nativeAd = nativeAd
self.nativeAd?.delegate = self

// Copy text contents to subviews
self.nativeAdView?.titleLabel?.text = nativeAd.title
self.nativeAdView?.bodyLabel?.text = nativeAd.body
self.nativeAdView?.advertiserLabel?.text = nativeAd.advertiser
self.nativeAdView?.callToActionLabel?.text = nativeAd.callToAction
...

// As soon as assigning a `GFPNativeAd` to the `GFPNativeAdView`, it starts tracking impressions, and rendering iconView and mediaView images.
self.nativeAdView?.nativeAd = nativeAd

// Add as subview
self.view.addSubview(self.nativeAdView!)
}

GFPNativeAdDelegate

On View impression

func nativeAdWasSeen(_ nativeAd: GFPNativeAd) {
...
}

On Rendered Impression

func nativeAdWasRendered(_ nativeAd: GFPNativeAd) {
...
}

On Click

func nativeAdWasClicked(_ nativeAd: GFPNativeAd) {
...
}

On Render Error

func nativeAd(_ nativeAd: GFPNativeAd, didFailWithError error: GFPError) {
...
}

Auxiliary

Rendering Native Ad Using Extrnal Ad Network SDKs

  • Get the original native components from the external ad network SDKs in the GFPNativeAd's adProviderNativeAd property.

  • Get the name of ad network by the GFPNativeAd's adProviderType property.

Than typecast the adProviderNativeAd to the original SDK's native ad type.

import FBAudienceNetwork    // FAN SDK
import GoogleMobileAds // DFP SDK

func adLoader(_ unifiedAdLoader: GFPAdLoader!, didReceive nativeAd: GFPNativeAd!) {

self.nativeAd = nativeAd
self.nativeAd?.delegate = self

if nativeAd.adProviderType == .FAN {
// Handle FAN native ad
...
} else if nativeAd.adProviderType == .DFP {
// Handle DFP native ad
...
}
}