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.
- Swift
- Objective-C
import GFPSDK
@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.
- Declare the GFPAdLoader *adLoader property in the view controller.
- Implement the GFPAdLoaderDelegate protocol in the view controller.
GFPAdLoaderDelegate transmits events related to native ad loading.
- Declare the GFPBannerView *bannerView property on the view controller.
- Implement the GFPBannerViewDelegate protocol on the view controller.
GFPBannerViewDelegate delivers events such as exposure, click, and rendering errors of the loaded banner object.
- Declare the GFPNativeAd *nativeAd property on the view controller.
- Implement the GFPNativeAdDelegate protocol on the view controller.
GFPNativeAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native objects.
- Declare the GFPNativeAd *nativeAd property in the view controller.
- Implement the GFPNativeAdDelegate protocol in the view controller.
GFPNativeSimpleAdDelegate delivers events such as exposure, click, and rendering errors of the loaded native simple object.
- Swift
- Objective-C
// 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?
}
// MyViewController.h
@import GFPSDK;
@interface MyViewController : UIViewController <GFPAdLoaderDelegate,
GFPBannerViewDelegate,
GFPNativeAdDelegate,
GFPNativeSimpleAdDelegate>
@property (nonatomic) GFPAdLoader *adLoader;
@property (nonatomic) GFPBannerView *bannerView;
@property (nonatomic) GFPNativeAd *nativeAd;
@property (nonatomic) GFPNativeAdView *nativeAdView;
@property (nonatomic) GFPNativeSimpleAd *nativeSimpleAd;
@property (nonatomic) GFPNativeSimpleAdView *nativeSimpleAdView;
@end
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.
- Swift
- Objective-C
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()
}
- (void)viewDidLoad {
[super viewDidLoad];
GFPAdParam *adParam = [[GFPAdParam alloc] init];
adParam.yearOfBirth = 1990;
adParam.gender = GFPAdParamGenderTypeMale;
...
self.adLoader = [[GFPAdLoader alloc] initWithUnitID:@"UnitId"
rootViewController:self
adParam:adParam];
GFPAdBannerOptions *bannerOptions = [[GFPAdBannerOptions alloc] init];
bannerOptions.layoutType = GFPBannerViewLayoutTypeFluidWidth;
[self.adLoader setBannerDelegate:self bannerOptions:bannerOptions];
GFPAdNativeOptions *nativeOptions = [[GFPAdNativeOptions alloc] init];
nativeOptions.renderingSetting = ...;
[self.adLoader setNativeDelegate:self nativeOptions:nativeOptions];
GFPAdNativeSimpleOptions *nativeSimpleOptions = [[GFPAdNativeSimpleOptions alloc] init];
nativeSimpleOptions.simpleAdRenderingSetting = ...;
[self.adLoader setNativeSimpleDelegate:self nativeSimpleOptions:nativeSimpleOptions];
self.adLoader.delegate = self;
[self.adLoader loadAd];
}
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
- For subsequent rendering and operations, please refer to the guide of each advertisement.
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
- Swift
- Objective-C
func adLoader(_ unifiedAdLoader: GFPAdLoader, didReceiveNativeAd nativeAd: GFPNativeAd) {
if let adMetaData = nativeAd.adMetaData {
let adMetaDataMessage = String(format: "Native Ad Context (loaded) %@", adMetaData.adContext)
print(adMetaDataMessage)
}
}
- (void)adLoader:(GFPAdLoader *)unifiedAdLoader didReceiveNativeAd:(GFPNativeAd *)nativeAd {
...
if (nativeAd.adMetaData != nil) {
NSString *adMetaDataMessage = [NSString stringWithFormat:@"Native Ad Context (loaded) %@", nativeAd.adMetaData.adContext];
NSLOG(@"%@", adMetaDataMessage);
}
}
On Ad Impression
- Swift
- Objective-C
func bannerAdWasSeen(_ bannerView: GFPBannerView) {
...
if let adMetaData = bannerView.adMetaData {
let adMetaDataMessage = String(format: "Banner Ad Context (seen) %@", adMetaData.adContext)
print(adMetaDataMessage)
}
}
- (void)bannerAdWasSeen:(GFPBannerView *)bannerView {
...
if (bannerView.adMetaData != nil) {
NSString *adMetaDataMessage = [NSString stringWithFormat:@"Banner Ad Context (seen) %@", bannerView.adMetaData.adContext];
NSLOG(@"%@", adMetaDataMessage);
}
}
On Click Event
- Swift
- Objective-C
func nativeSimpleAdWasClicked(_ nativeSimpleAd: GFPNativeSimpleAd) {
if let adContext = nativeSimpleAd.adMetaData?.adContext {
let adMetaDataMessage = String(format: "Native Simple Ad Context (clicked) %@", adContext)
print(adMetaDataMessage)
}
}
- (void)nativeSimpleAdWasClicked:(GFPNativeSimpleAd *)nativeSimpleAd {
if (nativeSimpleAd.adMetaData.adContext != nil) {
NSString *adMetaDataMessage = [NSString stringWithFormat:@"Native Simple Ad Context (clicked) %@", nativeSimpleAd.adMetaData.adContext];
NSLOG(@"%@", 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.
- Swift
- Objective-C
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)
}
}
- (void)nativeAdWasClicked:(GFPNativeAd *)nativeAd {
if (nativeAd.adMetaData.slotIndex != nil && nativeAd.adMetaData.slotIndex >= 0) {
NSString *slotIndexMessage = [NSString stringWithFormat:@"Native Ad Slot Index (clicked) %ld", [nativeAd.adMetaData.slotIndex longValue]];
NSLOG(@"%@", slotIndexMessage);
}
}