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

このガイドでは、カスタム ネイティブ広告フォーマットをオープン測定と統合する方法について説明します。

前提条件

続行する前に、次のことを行います。

統合

動画アセットを含まないカスタム ネイティブ広告フォーマットで Open Measurement を使用する場合は、Open Measurement API を自分で呼び出す必要があります。

動画アセットを含むカスタム ネイティブ広告フォーマットを使用している場合は、このガイドに沿って作業する必要はありません。Mobile Ads SDK が動画アセットの視認性をトラッキングします。

広告を読み込む

オープン測定を使用しているかどうかに関係なく、広告の読み込みは同じです。カスタム ネイティブ広告をリクエストする方法を示すメソッドを次に示します。

Java

private void loadCustomNativeAd(Context context, ViewGroup nativeCustomFormatAdContainer) {

  AdLoader adLoader =
      new AdLoader.Builder(context, "AD_UNIT_ID")
          .forCustomFormatAd(
              "CUSTOM_TEMPLATE_ID",
              new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
                @Override
                public void onCustomFormatAdLoaded(@NonNull NativeCustomFormatAd ad) {
                  // Show the ad first and then register your view and begin open measurement.
                  // Make sure to do this on the main thread.

                  // ...
                  // Show ad
                  // ...

                  startOpenMeasurement(ad, nativeCustomFormatAdContainer);
                }
              },
              new NativeCustomFormatAd.OnCustomClickListener() {
                @Override
                public void onCustomClick(NativeCustomFormatAd ad, String assetName) {
                  // Handle the click action
                }
              })
          .build();
  adLoader.loadAd(new AdRequest.Builder().build());
}

Kotlin

private fun loadCustomNativeAd(context: Context, nativeCustomFormatAdContainer: ViewGroup) {
  val adLoader =
    AdLoader.Builder(context, "AD_UNIT_ID")
      .forCustomFormatAd(
        "CUSTOM_TEMPLATE_ID",
        NativeCustomFormatAd.OnCustomFormatAdLoadedListener { ad ->
          // Show the ad first and then register your view and begin open measurement. Make sure
          // to do this on the main thread.

          // ...
          // Show ad
          // ...

          startOpenMeasurement(ad, nativeCustomFormatAdContainer)
        },
        NativeCustomFormatAd.OnCustomClickListener { ad, assetName ->
          // Handle the click action.
        },
      )
      .build()

  adLoader.loadAd(AdRequest.Builder().build())
}

AD_UNIT_IDCUSTOM_TEMPLATE_ID は、広告ユニット ID とカスタム テンプレート ID に置き換えます。

ビューを登録して測定を開始する

カスタム ネイティブ広告で Open Measurement を有効にするには、まず広告を表示してから、カスタム ネイティブ広告に関連付けられた DisplayOpenMeasurement オブジェクトを使用してカスタム広告ビューを登録します。DisplayOpenMeasurement オブジェクトは、コンテナビューをオープン測定に登録するための setView() メソッドを提供します。

また、広告の測定を開始するよう SDK に明示的に指示する必要があります。これを行うには、カスタム ネイティブ広告の DisplayOpenMeasurement オブジェクトで start() メソッドを呼び出します。start() メソッドはメインスレッドから呼び出す必要があります。以降の呼び出しは無効です。

画面のサンプルを次に示します。

Java

private void startOpenMeasurement(
    NativeCustomFormatAd ad, ViewGroup nativeCustomFormatAdContainer) {
  DisplayOpenMeasurement displayOpenMeasurement = ad.getDisplayOpenMeasurement();
  if (displayOpenMeasurement != null) {
    displayOpenMeasurement.setView(nativeCustomFormatAdContainer);
    displayOpenMeasurement.start();
  }
}

Kotlin

private fun startOpenMeasurement(
  ad: NativeCustomFormatAd,
  nativeCustomFormatAdContainer: ViewGroup,
) {
  ad.getDisplayOpenMeasurement()?.let { displayOpenMeasurement ->
    displayOpenMeasurement.setView(nativeCustomFormatAdContainer)
    displayOpenMeasurement.start()
  }
}

ビューを登録する前に広告を表示する必要があります。広告の表示については、カスタム ネイティブ広告フォーマットをご覧ください。

customTemplateAdFrame レイアウトはカスタム ネイティブ広告の広告コンテナであり、ビューのバウンディング ボックス内のすべてのアセットを含んでいる必要があります。

IAB で認定を受ける

アプリをリリースすると、測定データの受信が開始されますが、IAB 認定プロセスを完了するまで、データは認定されません。