ディスプレイ タイプのカスタム ネイティブ広告フォーマットと Open Measurement

動画アセットを含まないカスタムのネイティブ広告フォーマットで Open Measurement を使用する場合は、ご自身で Open Measurement API を呼び出す必要があります。ディスプレイ タイプのカスタム ネイティブ広告フォーマットの Open Measurement は、バージョン 7.43.0 以降でのみサポートされています。動画アセットでカスタムのネイティブ広告フォーマットを使用している場合は、このガイドに従う必要はありません。Google Mobile Ads 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 認定プロセスを終えるまでデータは認定されません。