Skip to main content

Combined Ad

The GFP SDK provides a way to simultaneously receive banner, native, and native simple advertisements via the GFPAdLoader. Since multiple types are supported on a single page, ad unit settings are required. Discussion with a GFP representative may be required.

GFPSDK Import

Import the GFPSDK module.

import GFPSDK

Add and initialize dependency

Please refer to getting-started guide.

Create a view controller

Apply following steps on the view controller that will contain ad views.

  1. Declare the GFPAdLoader *adLoader property in the view controller.
  2. Implement the GFPAdLoaderDelegate protocol in the view controller.
info

GFPAdLoaderDelegate transmits events related to native ad loading.

  1. Declare the GFPBannerView *bannerView property on the view controller.
  2. Implement the GFPBannerViewDelegate protocol on the view controller.
info

GFPBannerViewDelegate delivers events such as exposure, click, and rendering errors of the loaded banner object.

  1. Declare the GFPNativeAd *nativeAd property on the view controller.
  2. Implement the GFPNativeAdDelegate protocol on the view controller.
info

GFPNativeAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native objects.

  1. Declare the GFPNativeAd *nativeAd property in the view controller.
  2. Implement the GFPNativeAdDelegate protocol in the view controller.
info

GFPNativeSimpleAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native simple object.

// MyViewController.h
import GFPSDK

class MyViewController : UIViewController,
GFPAdLoaderDelegate,
GFPBannerViewDelegate,
GFPNativeAdDelegate,
GFPNativeSimpleAdDelegate {

private var adLoader : GFPAdLoader?
private var bannerView : GFPBannerView?

private var nativeSimpleAd : GFPNativeAd?
private var nativeSimpleAdView : GFPNativeAdView?

private var nativeSimpleAd : GFPNativeSimpleAd?
private var nativeSimpleAdView : GFPNativeSimpleAdView?
}

Create GFPAdLoader and request advertisement

Create a GFPAdLoader instance from the viewDidLoad method of MyViewController.m and request an advertisement.

  • When creating a GFPAdLoader instance, set the user information in GFPAdParam including the issued advertising unit ID. GFPAdParam is used for targeting to increase ad effectiveness.

  • Set Option and Delegate in GFPAdLoader for the advertisements to be used.

override func viewDidLoad() {
super.viewDidLoad()

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

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

let bannerOption = GFPAdBannerOptions()
bannerOption.layoutType = .fluidWidth
self.adLoader?.setBannerDelegate(self, bannerOptions: bannerOption)

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

let nativeSimpleOption = GFPAdNativeSimpleOptions()
nativeSimpleOption.renderingSetting = ...
self.adLoader?.setNativeSimpleDelegate(self, nativeSimpleOptions: nativeSimpleOption)

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

In the case of MoPub, if rootViewController is nil, the internal setting is set to UIApplication.sharedApplication.delegate.window.rootViewController.

Receive GFPAdLoader ad-loading events

  • The combined ads receive Delegate events associated with each ad type. The list of events received is listed below.
    • When the Banner ad response is successful, the adLoader:didReceiveBannerAd: method of GFPAdLoaderDelegate is called. Since GFPBannerView is a regular view object (UIView), it could be included in the view hierarchy.
    • When the Native general ad response is successful, the adLoader:didReceiveNativeAd: method of GFPAdLoaderDelegate is called.
    • When the Native simple ad response is successful, the adLoader:didReceiveNativeSimpleAd: method of GFPAdLoaderDelegate is called.
    • When the ad response fails, the adLoader:didFailWithError:responseInfo: method of GFPAdLoaderDelegate is called.

Event reception and rendering guide after GFPAdLoader

Retrieving Ad Metadata

For banner, native, and native simple ads, advertising information can be checked when events occur, but only when provided by the server. This information is delivered when load success occurs, when ad impression occurs, and when click events occur.

On Load Success

func adLoader(_ unifiedAdLoader: GFPAdLoader, didReceiveNativeAd nativeAd: GFPNativeAd) {
if let adMetaData = nativeAd.adMetaData {
let adMetaDataMessage = String(format: "Native Ad Context (loaded) %@", adMetaData.adContext)
print(adMetaDataMessage)
}
}

On Ad Impression

func bannerAdWasSeen(_ bannerView: GFPBannerView) {
...
if let adMetaData = bannerView.adMetaData {
let adMetaDataMessage = String(format: "Banner Ad Context (seen) %@", adMetaData.adContext)
print(adMetaDataMessage)
}
}

On Click Event

func nativeSimpleAdWasClicked(_ nativeSimpleAd: GFPNativeSimpleAd) {
if let adContext = nativeSimpleAd.adMetaData?.adContext {
let adMetaDataMessage = String(format: "Native Simple Ad Context (clicked) %@", adContext)
print(adMetaDataMessage)
}
}

Checking Slot Index of Native Ads

For carousel-type native ads, you can check the index number of the slot when a slot click event occurs.

func nativeAdWasClicked(_ nativeAd: GFPNativeAd) {
if let slotIndex = nativeAd.adMetaData?.slotIndex, slotIndex.intValue >= 0 {
let slotIndexMessage = String(format: "Native Ad Slot Index (clicked) %ld", slotIndex.intValue)
print(slotIndexMessage)
}
}