多媒體廣告類型自訂原生廣告格式和 Open Measurement

如果您打算在沒有影片素材資源的自訂原生廣告格式中使用公開評估功能,就必須自行呼叫公開評估 API。只有 7.43.0 以上版本支援顯示型自訂原生廣告格式的開放式評估功能。如果您使用自訂原生廣告格式搭配影片素材資源,則無須按照本指南操作,因為 Google Mobile Ads SDK 會代您追蹤影片素材資源的可視度。

必要條件

載入廣告

無論是否使用開放式評估,廣告載入方式都相同。在本例中,我們將使用簡單的 ViewController 來示範如何載入 GADNativeCustomFormatAd

@interface OpenMeasurementNativeCustomFormatAdViewController ()
    <GADNativeCustomFormatAdLoaderDelegate> {
  IBOutlet UIView *_parentView;
  GADAdLoader *_adLoader;
  GADNativeCustomFormatAd *_customTemplateAd;
  MySimpleNativeAdView *_simpleNativeAdView;
}

@end

@implementation OpenMeasurementNativeCustomFormatAdViewController

- (void) viewDidLoad {
  [super viewDidLoad];

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

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

註冊檢視畫面並開始評估

顯示 GADNativeCustomFormatAd 時,您需要使用 displayAdMeasurement.view 屬性,透過 GADNativeTemplateAd 註冊自訂廣告檢視畫面。

您也必須明確告知 SDK 才能開始評估廣告。方法是在 GADNativeCustomFormatAddisplayAdMeasurement 屬性上呼叫 startWithError: 方法。startWithError: 必須從主執行緒呼叫,後續的呼叫不會有任何效果。

@implementation OpenMeasurementNativeCustomFormatAdViewController
...
#pragma mark - GADNativeCustomFormatAdLoaderDelegate

- (void) adLoader:(GADAdLoader *) adLoader
    didReceiveNativeCustomFormatAd:(GADNativeCustomFormatAd *)nativeCustomFormatAd {
  NSLog(@"Received custom native ad: %@", nativeCustomFormatAd);

  _customTemplateAd = nativeCustomFormatAd;

  // 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 GADNativeCustomFormatAd 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 認證程序,資料才會獲得認證。