Banner Ad

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 {
    // Firebase Analytics 샘플
    [FIRAnalytics logEventWithName:kFIREventAdImpression
                        parameters: @{
        kFIRParameterAdPlatform: @"AD(X)",
        kFIRParameterAdFormat: @"BannerAd",
        kFIRParameterAdUnitName: @"ADX Banner Ad",
        kFIRParameterCurrency: @"USD",
        kFIRParameterValue: revenune
    }];
    
    // 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

Last updated