1. 기본 요건
Banner Ad용으로 발급받은 Ad Unit ID를 사용합니다.
광고를 요청하기 전에 SDK 초기화를 먼저 진행합니다.
SDK 초기화는 앱 실행 시 한 번만 호출하여 주시고, 광고 요청은 초기화가 완료된 후에 이뤄져야 합니다.
2. 구현
initWithAdUnitId:adSize:rootViewController:
메서드를 사용하여 ADXAdView
를 인스턴스화하고 ADXAdViewDelegate
callback을 등록합니다.
ADXAdSize
Size (width * height)
bannerView
의 frame을 설정하고 ViewController
에 bannerView
를 추가합니다.
#import <ADXLibrary/ADXAdView.h>
@interface BannerViewController () <ADXAdViewDelegate>
@property (strong) ADXAdView *bannerView;
@end
@implementation BannerViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.bannerView = [[ADXAdView alloc]
initWithAdUnitId:@"<ADX_BANNER_AD_UNIT_ID>"
adSize:ADXAdSizeBanner
rootViewController:self];
self.bannerView.delegate = self;
self.bannerView.frame = CGRectMake(
(self.view.bounds.size.width - ADXAdSizeBanner.width) / 2,
0,
ADXAdSizeBanner.width,
ADXAdSizeBanner.height);
[self.view addSubview:self.bannerView];
[self.bannerView loadAd];
}
#pragma mark - ADXAdViewDelegate
- (void)adViewDidLoad:(ADXAdView *)adView {
NSLog(@"adViewDidLoad");
}
- (void)adView:(ADXAdView *)adView didFailToLoadWithError:(NSError *)error {
NSLog(@"adView:didFailToLoadWithError: %@", error);
}
- (void)adViewDidClick:(ADXAdView *)adView {
NSLog(@"adViewDidClick");
}
import UIKit
import ADXLibrary
class BannerViewController: UIViewController {
var bannerView : ADXAdView!
override func viewDidLoad() {
super.viewDidLoad()
bannerView = ADXAdView(
adUnitId: "<ADX_BANNER_AD_UNIT_ID>",
adSize: ADXAdSizeBanner,
rootViewController: self)
bannerView.delegate = self
bannerView.frame = CGRect(
x: (UIScreen.main.bounds.size.width - ADXAdSizeBanner.width) / 2,
y: 0,
width: ADXAdSizeBanner.width,
height: ADXAdSizeBanner.height)
view.addSubview(bannerView)
bannerView.loadAd()
}
}
extension BannerViewController: ADXAdViewDelegate {
func adViewDidLoad(_ adView: ADXAdView) {
print("adViewDidLoad");
}
func adView(_ adView: ADXAdView, didFailToLoadWithError error: Error) {
print("adView:didFailToLoadWithError")
}
func adViewDidClick(_ adView: ADXAdView) {
print("adViewDidClick")
}
}
3. Callback
ADXAdViewDelegate
를 설정하여 특정 이벤트를 수신할 수 있습니다.
- (void)adViewDidLoad:(ADXAdView *)adView;
- (void)adView:(ADXAdView *)adView didFailToLoadWithError:(NSError *)error;
- (void)adViewDidClick:(ADXAdView *)adView;
func adViewDidLoad(_ adView: ADXAdView)
func adView(_ adView: ADXAdView, didFailToLoadWithError error: Error)
func adViewDidClick(_ adView: ADXAdView)
4. Ad Revenue (paidEventHandler)
광고 노출에 대한 예상 광고 수익을 확인할 수 있습니다.
이 기능은 iOS ADX SDK 2.6.2 이상 버전을 사용하시는 것이 권장됩니다.
아래 예제와 같이' paidEventHandler
' 를 사용하여 예상되는 eCPM 값을 확인할 수 있습니다.
미디에이션 설정 과정에서 수동적으로 설정한 값과 정확한 값이 섞여 있어서 예상 값으로 사용하시는 것을 권장드립니다.
eCPM의 통화(Currency) 단위는 USD입니다.
#import <UIKit/UIKit.h>
#import <ADXLibrary/ADXAdView.h>
#import <FirebaseAnalytics/FirebaseAnalytics.h>
#import <AppsFlyerAdRevenue/AppsFlyerAdRevenue.h>
@interface BannerViewController () <ADXAdViewDelegate>
@property (strong) ADXAdView * bannerView;
@end
@implementation BannerViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.bannerView = [[ADXAdView alloc]
initWithAdUnitId:@"<ADX_BANNER_AD_UNIT_ID>"
adSize:ADXAdSizeBanner
rootViewController:self];
self.bannerView.delegate = self;
__weak typeof(self) weakSelf = self;
self.bannerView.paidEventHandler = ^(double eCPM) {
__strong typeof(self) strongSelf = weakSelf;
if(!strongSelf) { return; }
NSNumber * revenue = [NSNumber numberWithDouble:eCPM/1000];
[strongSelf handleAdRevenue:revenue];
};
}
- (void)handleAdRevenue:(NSNumber *)revenue {
// 1) Firebase Analytics
[FIRAnalytics logEventWithName:kFIREventAdImpression
parameters: @{
kFIRParameterAdPlatform: @"AD(X)",
kFIRParameterAdFormat: @"BannerAd",
kFIRParameterAdUnitName: @"ADX Banner Ad",
kFIRParameterCurrency: @"USD",
kFIRParameterValue: revenune
}];
// 2) AppsFlyer
NSDictionary * adRevenueParams = @{
@"AdUnitName" : @"ADX Banner Ad",
@"AdType" : @"BannerAd",
};
AppsFlyerAdRevenue * appsFlyerAdRevenue = [AppsFlyerAdRevenue shared];
[appsFlyerAdRevenue
logAdRevenueWithMonetizationNetwork:@"AD(X)"
mediationNetwork:AppsFlyerAdRevenueMediationNetworkTypeCustom
eventRevenue:revenune
revenueCurrency:@"USD"
additionalParameters:adRevenueParams];
}
#pragma mark - ADXAdViewDelegate
- (void)adViewDidLoad:(ADXAdView *)adView {}
- (void)adView:(ADXAdView *)adView didFailToLoadWithError:(NSError *)error {}
- (void)adViewDidClick:(ADXAdView *)adView {}
@end
import UIKit
import ADXLibrary
import FirebaseAnalytics
import AppsFlyerAdRevenue
class BannerAdViewController: UIViewController {
var bannerView : ADXAdView!
override func viewDidLoad() {
super.viewDidLoad()
bannerView = ADXAdView(adUnitId: "<ADX_BANNER_AD_UNIT_ID>")
bannerView.delegate = self
bannerView.paidEventHandler = { [weak self] eCPM in
let revenue:NSNumber = (eCPM / 1000) as NSNumber
self?.handleAdRevenue(revenue: revenue)
}
}
func handleAdRevenue(revenue:NSNumber) {
// 1) Firebase Analytics
Analytics.logEvent(
AnalyticsEventAdImpression,
parameters: [
AnalyticsParameterAdPlatform: "AD(X)",
AnalyticsParameterAdUnitName: "ADX Banner Ad",
AnalyticsParameterAdFormat: "BannerAd",
AnalyticsParameterValue: revenune,
AnalyticsParameterCurrency: "USD",
])
// 2) AppsFlyer
let adRevenueParams:[AnyHashable: Any] = [
"AdUnitName" : "ADX Banner Ad",
"AdType" : "BannerAd",
]
AppsFlyerAdRevenue.shared().logAdRevenue(
monetizationNetwork: "AD(X)",
mediationNetwork: .custom,
eventRevenue: revenune,
revenueCurrency: "USD",
additionalParameters: adRevenueParams)
}
}
extension BannerViewController: ADXAdViewDelegate {
func adViewDidLoad(_ adView: ADXAdView) {}
func adView(_ adView: ADXAdView, didFailToLoadWithError error: Error) {}
func adViewDidClick(_ adView: ADXAdView) {}
}
Last updated