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

カスタム ネイティブ広告フォーマットでオープン測定を使用する予定がある場合は、 動画アセットが含まれていない場合は、 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 に明示的に指示する必要もあります。そのためには、 次のように、displayAdMeasurement プロパティの startWithError: メソッドを呼び出す GADNativeCustomFormatAdstartWithError: はメインスレッドから呼び出す必要があります。 後続の呼び出しは効果がありません。

@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 認定 プロセスをご覧ください。