디스플레이 유형 맞춤 네이티브 광고 형식 및 Open Measurement

동영상 애셋이 포함되지 않은 맞춤 네이티브 광고 형식과 함께 Open Measurement API를 사용하려는 경우 Open Measurement API를 직접 호출해야 합니다. 디스플레이 유형 맞춤 네이티브 광고 형식에 대한 Open Measurement는 버전 7.43.0 이상에서만 지원됩니다. 동영상 애셋과 함께 맞춤 네이티브 광고 형식을 사용하는 경우 이 가이드를 따르지 않아도 됩니다. Google 모바일 광고 SDK가 자동으로 동영상 애셋의 조회가능성을 추적합니다.

기본 요건

광고 로드

공개 측정의 사용 여부와 관계없이 광고를 로드하는 것은 동일합니다. 이 경우에는 간단한 ViewController를 사용하여 GADNativeCustomTemplateAd를 로드하는 방법을 보여줍니다.

@interface OpenMeasurementNativeCustomTemplateAdViewController ()
    <GADNativeCustomTemplateAdLoaderDelegate> {
  IBOutlet UIView *_parentView;
  GADAdLoader *_adLoader;
  GADNativeCustomTemplateAd *_customTemplateAd;
  MySimpleNativeAdView *_simpleNativeAdView;
}

@end

@implementation OpenMeasurementNativeCustomTemplateAdViewController

- (void) viewDidLoad {
  [super viewDidLoad];

  _adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"your ad unit ID"
                                 rootViewController:self
                                            adTypes:@[ kGADAdLoaderAdTypeNativeCustomTemplate ]
                                            options:nil];
  _adLoader.delegate = self;
  [self loadAd];
}

- (void) loadAd {
  GAMRequest *request = [GAMRequest request];
  [_adLoader loadRequest:request];
}
...
@end

뷰 등록 및 측정 시작

GADNativeCustomTemplateAd를 표시할 때 displayAdMeasurement.view 속성을 사용하여 GADNativeTemplateAd에 맞춤 광고 뷰를 등록해야 합니다.

또한 광고 측정을 시작하도록 SDK에 명시적으로 알려야 합니다. 이렇게 하려면 GADNativeCustomTemplateAddisplayAdMeasurement 속성에서 startWithError: 메서드를 호출합니다. startWithError:는 기본 스레드에서 호출해야 하며 후속 호출은 영향을 미치지 않습니다.

@implementation OpenMeasurementNativeCustomTemplateAdViewController
...
#pragma mark - GADNativeCustomTemplateAdLoaderDelegate

- (void) adLoader:(GADAdLoader *) adLoader
    didReceiveNativeCustomTemplateAd:(GADNativeCustomTemplateAd *)nativeCustomTemplateAd {
  NSLog(@"Received custom native ad: %@", nativeCustomTemplateAd);

  _customTemplateAd = nativeCustomTemplateAd;

  // Put the custom native ad on screen.
  _simpleNativeAdView =
    [[NSBundle mainBundle] loadNibNamed:@"SimpleCustomNativeAdView"
                                  owner:nil
                                options:nil]
    .firstObject;
  [_parentView addSubview:_simpleNativeAdView];
  [_simpleNativeAdView populateWithCustomNativeAd:_customTemplateAd];


  // Set the top-level native ad view on the GADNativeCustomTemplateAd so the
  // Google Mobile Ads SDK can track viewability for that view.
  _customTemplateAd.displayAdMeasurement.view = _simpleNativeAdView;
  // Begin measuring your impressions and clicks.
  NSError *error = nil;
  [_customTemplateAd.displayAdMeasurement startWithError:&error];

  if (error) {
    NSLog(@"Failed to start the display measurement.");
  }
}
...
@end

그러면 끝입니다. 앱을 출시하면 측정 데이터를 수신하기 시작하지만 IAB 인증 프로세스를 거쳐야만 데이터가 인증됩니다.