Native Ad
eCPM의 통화(Currency) 단위는 USD입니다.
#import <UIKit/UIKit.h>
#import <ADXLibrary/ADXNativeAdFactory.h>
#import "NativeAdViewController.h"
#import "NativeAdView.h"
#import <FirebaseAnalytics/FirebaseAnalytics.h>
#import <AppsFlyerAdRevenue/AppsFlyerAdRevenue.h>
@interface NativeAdViewController () <ADXNativeAdFactoryDelegate, ADXNativeAdDelegate>
@property (nonatomic, strong) ADXNativeAd *nativeAd;
@end
@implementation NativeAdViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[ADXNativeAdFactory sharedInstance]
setRenderingViewClass:@"<ADX_NATIVE_AD_UNIT_ID>"
renderingViewClass:[NativeAdView class]];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[ADXNativeAdFactory sharedInstance] addDelegate:self];
[[ADXNativeAdFactory sharedInstance] loadAd:@"<ADX_NATIVE_AD_UNIT_ID>"];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[ADXNativeAdFactory sharedInstance] removeDelegate:self];
}
- (void)handleAdRevenue:(NSNumber *)revenue {
// Firebase Analytics 샘플
[FIRAnalytics logEventWithName:kFIREventAdImpression
parameters: @{
kFIRParameterAdPlatform: @"AD(X)",
kFIRParameterAdFormat: @"NativeAd",
kFIRParameterAdUnitName: @"ADX Native Ad",
kFIRParameterCurrency: @"USD",
kFIRParameterValue: revenune
}];
// AppsFlyer 샘플
NSDictionary * adRevenueParams = @{
@"AdUnitName" : @"ADX Native Ad",
@"AdType" : @"NativeAd",
};
AppsFlyerAdRevenue * appsFlyerAdRevenue = [AppsFlyerAdRevenue shared];
[appsFlyerAdRevenue
logAdRevenueWithMonetizationNetwork:@"AD(X)"
mediationNetwork:AppsFlyerAdRevenueMediationNetworkTypeCustom
eventRevenue:revenune
revenueCurrency:@"USD"
additionalParameters:adRevenueParams];
}
#pragma mark - ADXNativeAdFactoryDelegate
- (void)onSuccess:(NSString *)adUnitId nativeAd:(ADXNativeAd *)nativeAd {
NSLog(@"onSuccess : %@", adUnitId);
if([adUnitId isEqualToString:@"<ADX_NATIVE_AD_UNIT_ID>"]) {
self.nativeAd = nativeAd;
self.nativeAd.delegate = self;
__weak typeof(self) weakSelf = self;
self.nativeAd.paidEventHandler = ^(double eCPM) {
__strong typeof(self) strongSelf = weakSelf;
if(!strongSelf) { return; }
NSNumber * revenue = [NSNumber numberWithDouble:eCPM/1000];
[strongSelf handleAdRevenue:revenue];
};
UIView *nativeAdView = [[ADXNativeAdFactory sharedInstance]
getNativeAdView:@"<ADX_NATIVE_AD_UNIT_ID>"];
nativeAdView.frame = CGRectMake(0.0,
100.0,
320.0,
300.0);
[self.view addSubview:nativeAdView];
}
}
- (void)onFailure:(NSString *)adUnitId {
NSLog(@"onFailure : %@", adUnitId);
}
#pragma mark - ADXNativeAdDelegate
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
@end
import UIKit
import ADXLibrary
import FirebaseAnalytics
import AppsFlyerAdRevenue
class NativeAdViewController: UIViewController {
var nativeAd: ADXNativeAd?
override func viewDidLoad() {
super.viewDidLoad()
ADXNativeAdFactory.sharedInstance().setRenderingViewClass(
"<ADX_NATIVE_AD_UNIT_ID>",
renderingViewClass: NativeAdView.self)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
ADXNativeAdFactory.sharedInstance().add(self)
ADXNativeAdFactory.sharedInstance().loadAd("<ADX_NATIVE_AD_UNIT_ID>")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
ADXNativeAdFactory.sharedInstance().remove(self)
}
func handleAdRevenue(revenue:NSNumber) {
// Firebase Analytics 샘플
Analytics.logEvent(
AnalyticsEventAdImpression,
parameters: [
AnalyticsParameterAdPlatform: "AD(X)",
AnalyticsParameterAdUnitName: "ADX Native Ad",
AnalyticsParameterAdFormat: "NativeAd",
AnalyticsParameterValue: revenune,
AnalyticsParameterCurrency: "USD",
])
// AppsFlyer 샘플
let adRevenueParams:[AnyHashable: Any] = [
"AdUnitName" : "ADX Native Ad",
"AdType" : "NativeAd",
]
AppsFlyerAdRevenue.shared().logAdRevenue(
monetizationNetwork: "AD(X)",
mediationNetwork: .custom,
eventRevenue: revenune,
revenueCurrency: "USD",
additionalParameters: adRevenueParams)
}
}
extension NativeAdViewController: ADXNativeAdFactoryDelegate,
ADXNativeAdDelegate
{
// MARK: - ADXNativeAdFactoryDelegate
public func onSuccess(_ adUnitId: String!, nativeAd: ADXNativeAd!) {
if (adUnitId == "<ADX_NATIVE_AD_UNIT_ID>") {
self.nativeAd = nativeAd
self.nativeAd?.delegate = self
self.nativeAd?.paidEventHandler = { [weak self] eCPM in
let revenue:NSNumber = (eCPM / 1000) as NSNumber
self?.handleAdRevenue(revenue: revenue)
}
let nativeAdView = ADXNativeAdFactory.sharedInstance()
.getNativeAdView("<ADX_NATIVE_AD_UNIT_ID>")
nativeAdView?.frame = CGRect(
x: (UIScreen.main.bounds.width - 300.0)/2,
y: 100.0,
width: 300.0,
height: 270.0)
self.view.addSubview(nativeAdView!)
} else {
print("fail to load")
}
}
public func onFailure(_ adUnitId: String!) {
print("onFailure :", adUnitId!)
}
// MARK: - ADXNativeAdDelegate
func viewControllerForPresentingModalView() -> UIViewController {
return self
}
}
Last updated