1. 기본 요건
Rewarded Ad용으로 발급받은 Ad Unit ID를 사용합니다.
광고를 요청하기 전에 SDK 초기화를 먼저 진행합니다.
SDK 초기화는 앱 실행 시 한 번만 호출하여 주시고, 광고 요청은 초기화가 완료된 후에 이뤄져야 합니다.
2. 구현
Rewarded Ad load에 시간이 걸릴 수 있으니, 미리 load 해두신 다음 사용하시는 것을 권장드립니다.
initWithAdUnitId:
메서드를 사용하여 ADXRewardedAd
를 인스턴스화하고 ADXRewardedAdDelegate
callback을 등록합니다.
isLoaded
로 표시할 광고가 있는지 확인 후, showAdFromRootViewController:
로 광고를 표시합니다.
광고 시청을 모두 완료하면 ADXRewardedAdDelegate
의 rewardedAdDidRewardUser:withReward:
가 호출 되므로, rewardedAdDidRewardUser:withReward:
가 호출된 경우에 보상을 지급하도록 처리합니다.
#import <ADXLibrary/ADXRewardedAd.h>
@interface RewardedAdViewController () <ADXRewardedAdDelegate>
@property (strong) ADXRewardedAd *rewardedAd;
@end
@implementation RewardedAdViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.rewardedAd = [[ADXRewardedAd alloc]
initWithAdUnitId:@"<ADX_REWARDED_AD_UNIT_ID>"];
self.rewardedAd.delegate = self;
}
- (IBAction)loadAd:(id)sender {
[self.rewardedAd loadAd];
}
- (IBAction)showAd:(id)sender {
if (self.rewardedAd.isLoaded) {
[self.rewardedAd showAdFromRootViewController:self];
}
}
#pragma mark - ADXRewardedAdDelegate
- (void)rewardedAdDidLoad:(ADXRewardedAd *)rewardedAd {
NSLog(@"rewardedAdDidLoad");
}
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd didFailToLoadWithError:(NSError *)error {
NSLog(@"rewardedAd:didFailToLoadWithError: %@", error);
}
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd didFailToShowWithError:(NSError *)error {
NSLog(@"rewardedAd:didFailToShowWithError: %@", error);
}
- (void)rewardedAdWillPresentScreen:(ADXRewardedAd *)rewardedAd {
NSLog(@"rewardedAdWillPresentScreen");
}
- (void)rewardedAdDidClick:(ADXRewardedAd *)rewardedAd {
NSLog(@"rewardedAdDidClick");
}
- (void)rewardedAdWillDismissScreen:(ADXRewardedAd *)rewardedAd {
NSLog(@"rewardedAdWillDismissScreen");
}
- (void)rewardedAdDidDismissScreen:(ADXRewardedAd *)rewardedAd {
NSLog(@"rewardedAdDidDismissScreen");
}
- (void)rewardedAdDidRewardUser:(ADXRewardedAd *)rewardedAd withReward:(ADXReward *)reward {
NSLog(@"rewardedAdDidRewardUser");
}
import UIKit
import ADXLibrary
class RewardedAdViewController: UIViewController {
fileprivate var rewardedAd: ADXRewardedAd!
override func viewDidLoad() {
super.viewDidLoad()
rewardedAd = ADXRewardedAd(adUnitId: "<ADX_REWARDED_AD_UNIT_ID>")
rewardedAd.delegate = self
}
@IBAction func loadAd(_ sender: Any) {
rewardedAd.load()
}
@IBAction func showAd(_ sender: Any) {
if rewardedAd.isLoaded {
rewardedAd.show(fromRootViewController: self)
}
}
}
extension RewardedAdViewController: ADXRewardedAdDelegate {
func rewardedAdDidLoad(_ rewardedAd: ADXRewardedAd) {
print("rewardedAdDidLoad")
}
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToLoadWithError error: Error) {
print("rewardedAd:didFailToLoadWithError")
}
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToShowWithError error: Error) {
print("rewardedAd:didFailToShowWithError")
}
func rewardedAdWillPresentScreen(_ rewardedAd: ADXRewardedAd) {
print("rewardedAdWillPresentScreen")
}
func rewardedAdWillDismissScreen(_ rewardedAd: ADXRewardedAd) {
print("rewardedAdWillDismissScreen")
}
func rewardedAdDidDismissScreen(_ rewardedAd: ADXRewardedAd) {
print("rewardedAdDidDismissScreen")
}
func rewardedAdDidClick(_ rewardedAd: ADXRewardedAd) {
print("rewardedAdDidClick")
}
func rewardedAdDidRewardUser(_ rewardedAd: ADXRewardedAd, with reward: ADXReward) {
print("rewardedAdDidRewardUser")
}
}
3. Callback
ADXRewardedAdDelegate
를 설정하여 특정 이벤트를 수신할 수 있습니다.
- (void)rewardedAdDidLoad:(ADXRewardedAd *)rewardedAd;
- (void)rewardedAdWillPresentScreen:(ADXRewardedAd *)rewardedAd;
- (void)rewardedAdDidClick:(ADXRewardedAd *)rewardedAd;
- (void)rewardedAdWillDismissScreen:(ADXRewardedAd *)rewardedAd;
- (void)rewardedAdDidDismissScreen:(ADXRewardedAd *)rewardedAd;
- (void)rewardedAdDidRewardUser:(ADXRewardedAd *)rewardedAd
withReward:(ADXReward *)reward;
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd
didFailToLoadWithError:(NSError *)error;
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd
didFailToShowWithError:(NSError *)error;
func rewardedAdDidLoad(_ rewardedAd: ADXRewardedAd)
func rewardedAdWillPresentScreen(_ rewardedAd: ADXRewardedAd)
func rewardedAdWillDismissScreen(_ rewardedAd: ADXRewardedAd)
func rewardedAdDidDismissScreen(_ rewardedAd: ADXRewardedAd)
func rewardedAdDidClick(_ rewardedAd: ADXRewardedAd)
func rewardedAdDidRewardUser(_ rewardedAd: ADXRewardedAd, with reward: ADXReward)
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToLoadWithError error: Error)
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToShowWithError error: Error)
4. Ad Revenue (paidEventHandler)
광고 노출에 대한 예상 광고 수익을 확인할 수 있습니다.
이 기능은 iOS ADX SDK 2.4.1 버전 이상에서 사용하는 것이 권장됩니다.
아래 예제와 같이' paidEventHandler
' 를 사용하여 예상되는 eCPM 값을 확인할 수 있습니다.
미디에이션 설정 과정에서 수동적으로 설정한 값과 정확한 값이 섞여 있어서 예상 값으로 사용하시는 것을 권장드립니다.
eCPM의 통화(Currency) 단위는 USD입니다.
#import <UIKit/UIKit.h>
#import <ADXLibrary/ADXInterstitialAd.h>
#import <FirebaseAnalytics/FirebaseAnalytics.h>
#import <AppsFlyerAdRevenue/AppsFlyerAdRevenue.h>
@interface RewardedViewController () <ADXRewardedAdDelegate>
@property (strong) ADXRewardedAd *rewardedAd;
@end
@implementation RewardedViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.rewardedAd = [[ADXRewardedAd alloc]
initWithAdUnitId:@"<ADX_REWARDED_AD_UNIT_ID>"];
self.rewardedAd.delegate = self;
__weak typeof(self) weakSelf = self;
self.rewardedAd.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: @"RewardedAd",
kFIRParameterAdUnitName: @"ADX Rewarded Ad",
kFIRParameterCurrency: @"USD",
kFIRParameterValue: revenune
}];
// 2) AppsFlyer
NSDictionary * adRevenueParams = @{
@"AdUnitName" : @"ADX Rewarded Ad",
@"AdType" : @"RewardedAd",
};
AppsFlyerAdRevenue * appsFlyerAdRevenue = [AppsFlyerAdRevenue shared];
[appsFlyerAdRevenue
logAdRevenueWithMonetizationNetwork:@"AD(X)"
mediationNetwork:AppsFlyerAdRevenueMediationNetworkTypeCustom
eventRevenue:revenune
revenueCurrency:@"USD"
additionalParameters:adRevenueParams];
}
#pragma mark - ADXRewardedAdDelegate
- (void)rewardedAdDidLoad:(ADXRewardedAd *)rewardedAd {}
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd didFailToLoadWithError:(NSError *)error {}
- (void)rewardedAd:(ADXRewardedAd *)rewardedAd didFailToShowWithError:(NSError *)error {}
- (void)rewardedAdWillPresentScreen:(ADXRewardedAd *)rewardedAd {}
- (void)rewardedAdDidClick:(ADXRewardedAd *)rewardedAd {}
- (void)rewardedAdWillDismissScreen:(ADXRewardedAd *)rewardedAd {}
- (void)rewardedAdDidDismissScreen:(ADXRewardedAd *)rewardedAd {}
- (void)rewardedAdDidRewardUser:(ADXRewardedAd *)rewardedAd withReward:(ADXReward *)reward {}
@end
import UIKit
import ADXLibrary
import FirebaseAnalytics
import AppsFlyerAdRevenue
class RewardedViewController: UIViewController, ADXRewardedAdDelegate {
var rewardedAd: ADXRewardedAd!
override func viewDidLoad() {
super.viewDidLoad()
rewardedAd = ADXRewardedAd(adUnitId: "<ADX_REWARDED_AD_UNIT_ID>")
rewardedAd.delegate = self
rewardedAd.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 Rewarded Ad",
AnalyticsParameterAdFormat: "RewardedAd",
AnalyticsParameterValue: revenune,
AnalyticsParameterCurrency: "USD",
])
// 2) AppsFlyer
let adRevenueParams:[AnyHashable: Any] = [
"AdUnitName" : "ADX Rewarded Ad",
"AdType" : "RewardedAd",
]
AppsFlyerAdRevenue.shared().logAdRevenue(
monetizationNetwork: "AD(X)",
mediationNetwork: .custom,
eventRevenue: revenune,
revenueCurrency: "USD",
additionalParameters: adRevenueParams)
}
}
extension RewardedAdViewController: ADXRewardedAdDelegate {
func rewardedAdDidLoad(_ rewardedAd: ADXRewardedAd) {}
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToLoadWithError error: Error) {}
func rewardedAd(_ rewardedAd: ADXRewardedAd, didFailToShowWithError error: Error) {}
func rewardedAdWillPresentScreen(_ rewardedAd: ADXRewardedAd) {}
func rewardedAdWillDismissScreen(_ rewardedAd: ADXRewardedAd) {}
func rewardedAdDidDismissScreen(_ rewardedAd: ADXRewardedAd) {}
func rewardedAdDidClick(_ rewardedAd: ADXRewardedAd) {}
func rewardedAdDidRewardUser(_ rewardedAd: ADXRewardedAd, with reward: ADXReward) {}
}
5. SSV (Server-side verification) 설정
SSV 설정은 선택사항으로 필요한 경우에만 설정하여 사용할 수 있습니다.
SSV 설정은 보상 이벤트가 발생될 때 개발사에서 등록한 Callback URL을 Server to Server 방식으로 호출을 하기 위한 설정입니다.
SSV 설정에 대한 호출 조건은 아래와 같습니다.
대시보드를 통해 Rewarded Video
타입에서 Callback URL 등록이 되어 있어야 합니다.
비디오 시청 완료 후 보상 이벤트가 발생해야 합니다.
필요한 경우 광고 요청 전에 SDK를 통해 User ID
또는 Custom Data
정보를 설정합니다.
클라이언트에서 설정한 User ID
와 Custom Data
정보가 있다면 Callback URL에 포함되어 호출하도록 적용되어 있습니다.
(예시) https://callback_url?param=value&userid=<valule>&customdata=<value>
해당 설정은 반드시 광고 요청 전에 호출해야 정상적으로 데이터가 Callback URL에 포함됩니다.
SDK v2.2 이상에서 동작하며 이전 버전에서는 동작하지 않습니다.
// SSV 설정 (optional)
[self.rewardedAd setSSVOptionWithUserId:@"<USER_ID>"];
[self.rewardedAd setSSVOptionWithCustomData:@"<CUSTOM_DATA>"];
// 광고 요청
[self.rewardedAd loadAd];
// SSV 설정 (optional)
rewardedAd.setSSVOptionWithUserId("<USER_ID>")
rewardedAd.setSSVOptionWithCustomData("<CUSTOM_DATA>")
// 광고 요청
rewardedAd.load()
Last updated