네이티브 광고는 플랫폼 고유의 UI 구성요소를 통해 사용자에게 표시되는 광고 애셋입니다. 이 광고는 스토리보드에 사용되는 것과 동일한 클래스를 통해 표시되며 앱의 시각적 디자인과 잘 어울리도록 만들 수 있습니다.
네이티브 광고가 로드되면 광고 애셋이 포함된 광고 객체를 앱에서 수신하며, 이때 Google 모바일 광고 SDK가 아니라 앱이 직접 광고를 표시합니다.
일반적으로 네이티브 광고의 성공적인 구현은 SDK를 사용하여 광고를 로드하는 작업과 앱에 광고 콘텐츠를 표시하는 작업으로 구성됩니다.
이 페이지에서는 SDK를 사용하여 네이티브 광고를 로드하는 방법을 설명합니다.
기본 요건
- 시작 가이드를 완료합니다.
항상 테스트 광고로 테스트
앱을 제작하고 테스트할 때는 운영 중인 실제 광고 대신 테스트 광고를 사용하세요.
테스트 광고를 로드하는 가장 쉬운 방법은 iOS의 네이티브 광고 전용 테스트 광고 단위 ID를 사용하는 것입니다.
ca-app-pub-3940256099942544/3986624511
이 ID는 모든 요청에 대해 테스트 광고를 반환하도록 특별히 구성되었으며, 코딩, 테스트, 디버깅 중에 앱에서 사용할 수 있습니다. 앱을 게시하기 전에 이 ID를 자체 광고 단위 ID로 바꿔야 합니다.
Google 모바일 광고 SDK의 테스트 광고가 작동하는 방식을 자세히 알아보려면 테스트 광고를 참고하세요.
광고 로드
네이티브 광고는 GADAdLoader
클래스를 통해 로드되며, 이 클래스는 GADAdLoaderDelegate
프로토콜에 따라 대리자에게 메시지를 보냅니다.
광고 로더 초기화
광고를 로드하기 전에 광고 로더를 초기화해야 합니다.
다음 코드에 GADAdLoader
를 초기화하는 방법이 나와 있습니다.
Swift
adLoader = AdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511",
// The UIViewController parameter is optional.
rootViewController: rootViewController,
adTypes: [ .native ],
options: [ ... ad loader options objects ... ])
adLoader.delegate = self
Objective-C
self.adLoader = [[GADAdLoader alloc]
initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
// The UIViewController parameter is nullable.
rootViewController:rootViewController
adTypes:@[ GADAdLoaderAdTypeNative ]
options:@[ ... ad loader options objects ... ]];
self.adLoader.delegate = self;
광고 단위 ID (테스트 ID를 사용할 수 있음), adTypes
배열을 전달하여
요청할 네이티브 형식을 지정할 상수, options
매개변수에 설정할 옵션이 필요합니다. options
매개변수에 사용할 수 있는 값은 네이티브 광고 옵션 설정 페이지에서 확인할 수 있습니다.
adTypes
배열에는 다음 상수가 포함되어야 합니다.
광고 로더 대리자 구현
광고 로더 대리자는 광고 유형별 프로토콜을 구현해야 합니다.
네이티브 광고의 경우 GADNativeAdLoaderDelegate
프로토콜에는 네이티브 광고가 로드된 후 대리자에게 전송되는 메시지가 포함됩니다.
Swift
public func adLoader(_ adLoader: AdLoader,
didReceive nativeAd: NativeAd)
Objective-C
- (void)adLoader:(GADAdLoader *)adLoader
didReceiveNativeAd:(GADNativeAd *)nativeAd;
광고 요청
GADAdLoader
가 초기화되었으면 loadRequest:
메서드를 호출하여 광고를 요청합니다.
Swift
adLoader.load(Request())
Objective-C
[self.adLoader loadRequest:[GADRequest request]];
GADAdLoader
의
loadRequest:
메서드는
배너 광고 및 전면 광고와 동일한 GADRequest
객체를 허용합니다. 다른 광고 유형에서처럼 요청 객체를 사용하여 타겟팅 정보를 추가할 수 있습니다.
여러 광고 로드 (선택사항)
단일 요청에서 여러 광고를 로드하려면 GADAdLoader
을 초기화할 때 GADMultipleAdsAdLoaderOptions
객체를 설정하세요.
Swift
let multipleAdOptions = MultipleAdsAdLoaderOptions()
multipleAdOptions.numberOfAds = 5;
adLoader = AdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511",
// The UIViewController parameter is optional.
rootViewController: self,
adTypes: [ .native ],
options: [ multipleAdOptions ])
Objective-C
GADMultipleAdsAdLoaderOptions *multipleAdsOptions =
[[GADMultipleAdsAdLoaderOptions alloc] init];
multipleAdsOptions.numberOfAds = 5;
self.adLoader = [[GADAdLoader alloc]
initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
// The UIViewController parameter is nullable.
rootViewController:rootViewController
adTypes:@[ GADAdLoaderAdTypeNative ]
options:@[ multipleAdsOptions ]];
요청당 광고 수는 5개로 제한되며 SDK가 요청된 수의 광고를 정확하게 반환하지 않을 수 있습니다.
반환된 Google 광고는 모두 서로 다르지만, 예약된 인벤토리 또는 서드 파티 구매자의 광고는 고유하지 않을 수 있습니다.
미디에이션을 사용하는 경우 GADMultipleAdsAdLoaderOptions
클래스를 사용하지 마세요. 현재 미디에이션을 위해 구성된 광고 단위 ID로는 여러 네이티브 광고에 대한 요청이 발생하지 않기 때문입니다.
로드 완료 시점 확인
앱이 loadRequest:
를 호출하면 다음에 대한 호출을 사용하여 요청 결과를 가져올 수 있습니다.
adLoader:didFailToReceiveAdWithError:
(GADAdLoaderDelegate
)adLoader:didReceiveNativeAd:
(GADNativeAdLoaderDelegate
)
단일 광고에 대한 요청으로 이러한 메서드 중 하나에 대한 호출이 발생합니다.
여러 광고를 요청하면 위 메서드에 대한 콜백이 하나 이상 발생하지만, 요청된 광고의 최대 개수는 넘지 않습니다.
또한 GADAdLoaderDelegate
에서는 adLoaderDidFinishLoading
콜백을 제공합니다. 이 대리자 메서드는 광고 로더를 통한 광고 로드를 완료했음을 나타내며, 요청에 대해 다른 광고 또는 오류는 보고되지 않습니다. 다음은 한 번에 여러 네이티브 광고를 로드하는 방법을 보여주는 예입니다.
Swift
class ViewController: UIViewController, NativeAdLoaderDelegate {
var adLoader: GADAdLoader!
override func viewDidLoad() {
super.viewDidLoad()
let multipleAdOptions = MultipleAdsAdLoaderOptions()
multipleAdOptions.numberOfAds = 5;
adLoader = AdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511",
// The UIViewController parameter is optional.
rootViewController: rootViewController,
adTypes: [ .native ],
options: [ multipleAdOptions ])
adLoader.delegate = self
adLoader.load(Request())
}
func adLoader(_ adLoader: AdLoader,
didReceive nativeAd: NativeAd) {
// A native ad has loaded, and can be displayed.
}
func adLoaderDidFinishLoading(_ adLoader: AdLoader) {
// The adLoader has finished loading ads, and a new request can be sent.
}
}
Objective-C
@interface ViewController () <GADNativeAdLoaderDelegate, GADVideoControllerDelegate>
@property(nonatomic, strong) GADAdLoader *adLoader;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
GADMultipleAdsAdLoaderOptions *multipleAdsOptions =
[[GADMultipleAdsAdLoaderOptions alloc] init];
multipleAdsOptions.numberOfAds = 5;
self.adLoader = [[GADAdLoader alloc]
initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511"
// The UIViewController parameter is nullable.
rootViewController:rootViewController
adTypes:@[ GADAdLoaderAdTypeNative ]
options:@[ multipleAdsOptions ]];
self.adLoader.delegate = self;
[self.adLoader loadRequest:[GADRequest request]];
}
- (void)adLoader:(GADAdLoader *)adLoader
didReceiveNativeAd:(GADNativeAd *)nativeAd {
// A native ad has loaded, and can be displayed.
}
- (void)adLoaderDidFinishLoading:(GADAdLoader *) adLoader {
// The adLoader has finished loading ads, and a new request can be sent.
}
@end
실패한 요청 처리
위 프로토콜은 광고 로드에 실패했을 때 전송되는 메시지를
정의하는 GADAdLoaderDelegate
프로토콜을 확장합니다.
Swift
public func adLoader(_ adLoader: AdLoader,
didFailToReceiveAdWithError error: NSError)
Objective-C
- (void)adLoader:(GADAdLoader *)adLoader
didFailToReceiveAdWithError:(NSError *)error;
네이티브 광고 이벤트 알림 받기
네이티브 광고 상호작용과 관련된 이벤트에 대한 알림을 받으려면 네이티브 광고의 대리자 속성을 설정하세요.
Swift
nativeAd.delegate = self
Objective-C
nativeAd.delegate = self;
그런 다음
GADNativeAdDelegate
를
구현하여 다음 대리자 호출을 수신하세요.
Swift
func nativeAdDidRecordImpression(_ nativeAd: NativeAd) {
// The native ad was shown.
}
func nativeAdDidRecordClick(_ nativeAd: NativeAd) {
// The native ad was clicked on.
}
func nativeAdWillPresentScreen(_ nativeAd: NativeAd) {
// The native ad will present a full screen view.
}
func nativeAdWillDismissScreen(_ nativeAd: NativeAd) {
// The native ad will dismiss a full screen view.
}
func nativeAdDidDismissScreen(_ nativeAd: NativeAd) {
// The native ad did dismiss a full screen view.
}
func nativeAdWillLeaveApplication(_ nativeAd: NativeAd) {
// The native ad will cause the app to become inactive and
// open a new app.
}
Objective-C
- (void)nativeAdDidRecordImpression:(GADNativeAd *)nativeAd {
// The native ad was shown.
}
- (void)nativeAdDidRecordClick:(GADNativeAd *)nativeAd {
// The native ad was clicked on.
}
- (void)nativeAdWillPresentScreen:(GADNativeAd *)nativeAd {
// The native ad will present a full screen view.
}
- (void)nativeAdWillDismissScreen:(GADNativeAd *)nativeAd {
// The native ad will dismiss a full screen view.
}
- (void)nativeAdDidDismissScreen:(GADNativeAd *)nativeAd {
// The native ad did dismiss a full screen view.
}
- (void)nativeAdWillLeaveApplication:(GADNativeAd *)nativeAd {
// The native ad will cause the app to become inactive and
// open a new app.
}
권장사항
광고를 로드할 때는 다음 규칙을 따르세요.
목록에서 네이티브 광고를 사용하는 앱은 광고 목록을 미리 캐시해야 합니다.
광고를 사전 캐시할 때는 1시간 후에 캐시를 지우고 다시 로드하세요.
이전 요청이
adLoaderDidFinishLoading:
에 표시된 대로 로드를 완료할 때까지GADAdLoader
에서loadRequest:
를 다시 호출하지 마세요.네이티브 광고 캐싱을 필요한 항목으로만 제한합니다. 예를 들어 사전 캐싱 시 화면에 즉시 표시되는 광고만 캐시합니다. 네이티브 광고는 메모리 사용량이 많으며, 네이티브 광고를 삭제하지 않고 캐싱하면 메모리 사용량이 과도해집니다.
더 이상 사용하지 않는 네이티브 광고는 소멸시킵니다.
광고 게재
광고를 로드한 후에는 사용자에게 광고를 게재하는 일만 남게 됩니다. 광고 게재 방식을 알아보려면 네이티브 광고 고급형 가이드를 참고하세요.