맞춤 네이티브 광고 형식

맞춤 네이티브 광고 형식

Ad Manager 게시자는 시스템 정의 네이티브 형식 외에 맞춤 동영상 목록을 정의하여 네이티브 광고 형식을 합니다. 이를 맞춤 네이티브 광고라고 합니다 형식을 사용할 수 있으며 예약 광고. 이를 통해 게시자는 임의의 구조화된 데이터를 확인할 수 있습니다. 이러한 광고는 NativeCustomFormatAd 드림 객체를 지정합니다.

맞춤 네이티브 광고 형식 로드

이 가이드에서는 맞춤 네이티브 광고 형식을 로드하고 표시하는 방법을 설명합니다.

AdLoader 구축

네이티브 광고와 마찬가지로 맞춤 네이티브 광고 형식은 AdLoader 클래스를 사용하여 로드됩니다.

자바

AdLoader adLoader = new AdLoader.Builder(context, "/21775744923/example/native")
    .forCustomFormatAd("10063170",
      new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
          @Override
          public void onCustomFormatAdLoaded(NativeCustomFormatAd ad) {
              // Show the custom format and record an impression.
          }
      },
      new NativeCustomFormatAd.OnCustomClickListener() {
          @Override
          public void onCustomClick(NativeCustomFormatAd ad, String s) {
              // Handle the click action
          }
      })
    .withAdListener( ... )
    .withNativeAdOptions( ... )
    .build();

Kotlin

val adLoader = AdLoader.Builder(this, "/21775744923/example/native")
        .forCustomFormatAd("10063170",
            { ad ->
                // Show the custom format and record an impression.
            },
            { ad, s ->
            // Handle the click action
            })
        .withAdListener( ... )
        .withNativeAdOptions( ... )
        .build()

forCustomFormatAd 메서드는 AdLoader가 커스텀 네이티브 광고 형식을 지원합니다. 이 메서드에 전달되는 매개변수는 다음과 같은 세 가지입니다.

  • AdLoader가 요청해야 하는 맞춤 네이티브 광고 형식의 ID입니다. 각 맞춤 네이티브 광고 형식에 ID가 연결되어 있습니다. 이 매개변수는 앱에서 AdLoader를 통해 요청할 형식을 나타냅니다.
  • OnCustomFormatAdLoadedListener 드림 광고가 성공적으로 로드되면 호출됩니다.
  • 선택적 OnCustomClickListener 드림 호출될 때 호출되어야 합니다. 자세한 내용은 자세한 내용은 '클릭 및 노출 처리' 섹션을 참조하세요.

단일 광고 단위가 둘 이상의 광고 소재를 게재하도록 설정될 수 있기 때문에 forCustomFormatAd는 두 개 이상의 형식을 사용할 수 있도록 광고 로더를 준비하기 위한 형식 ID 맞춤 네이티브 광고 형식을 사용합니다.

맞춤 네이티브 광고 형식 ID

맞춤 네이티브 광고 형식을 식별하는 데 사용되는 형식 ID는 Ad Manager UI의 게재 섹션 내 네이티브 섹션에서 찾을 수 있습니다. 드롭다운:

각 맞춤 네이티브 광고 형식 ID가 이름 옆에 표시됩니다. 오른쪽에 있는 이름은 형식의 세부정보를 보여주는 세부정보 화면으로 필드:

여기에서 개별 필드를 추가, 수정, 삭제할 수 있습니다. 참고: 각 애셋의 이름입니다. 이름은 각 애셋을 표시합니다.

맞춤 네이티브 광고 형식 표시

맞춤 네이티브 광고 형식은 게시자가 시스템 정의 광고 형식과 고유한 애셋 목록을 정의하여 도움이 됩니다. 따라서 맞춤 URL을 표시하는 프로세스는 시스템 정의 광고 항목과 다음과 같은 몇 가지 방법이 있습니다.

  1. NativeCustomFormatAd 클래스는 맞춤 네이티브 광고 형식을 지정하는 경우 'getters' 하세요. 대신 getText 및 필드 이름을 매개변수로 사용하는 getImage입니다.
  2. NativeAdView와 같은 광고 조회 전용 클래스는 없습니다. NativeCustomFormatAd입니다. 어떤 레이아웃을 사용하든 원하는 대로 생각해 보시기 바랍니다.
  3. 전용 ViewGroup 클래스가 없으므로 등록할 필요가 없습니다. 광고의 애셋을 표시하는 데 사용하는 모든 보기입니다. 이렇게 하면 코드를 실행할 수 있지만, 이는 광고를 표시하기 위해 나중에 클릭을 처리하도록 하기 위한 것입니다.

다음은 NativeCustomFormatAd를 표시하는 함수의 예입니다.

자바

public void displayCustomFormatAd (ViewGroup parent,
                                     NativeCustomFormatAd customFormatAd) {
    // Inflate a layout and add it to the parent ViewGroup.
    LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View adView = inflater.inflate(R.layout.custom_format_ad, parent);

    // Locate the TextView that will hold the value for "Headline" and
    // set its text.
    TextView myHeadlineView = (TextView) adView.findViewById(R.id.headline);
    myHeadlineView.setText(customFormatAd.getText("Headline"));

    // Locate the ImageView that will hold the value for "MainImage" and
    // set its drawable.
    Button myMainImageView = (ImageView) adView.findViewById(R.id.main_image);
    myMainImageView.setImageDrawable(
            customFormatAd.getImage("MainImage").getDrawable());

    ...
    // Continue locating views and displaying assets until finished.
    ...
}

Kotlin

public fun displayCustomFormatAd (parent: ViewGroup,
                                customFormatAd: NativeCustomFormatAd) {
    val adView = layoutInflater
            .inflate(R.layout.ad_simple_custom_format, null)

    val myHeadlineView = adView.findViewById<TextView>(R.id.headline)
    myHeadlineView.setText(customFormatAd.getText("Headline"));

    // Locate the ImageView that will hold the value for "MainImage" and
    // set its drawable.
    val myMainImageView = adView.findViewById(R.id.main_image);
    myMainImageView.setImageDrawable(
            customFormatAd.getImage("MainImage").drawable);

    ...
    // Continue locating views and displaying assets until finished.
    ...
}

AdChoices 아이콘 렌더링

디지털 서비스법 (DSA) 지원의 일환으로 유럽 경제 지역 (EEA)에서 게재되는 예약 광고의 경우 AdChoices 아이콘과 Google의 광고 수신 정보 페이지로 연결되는 링크 맞춤 네이티브 광고를 구현할 때는 AdChoices 아이콘 광고를 렌더링하고 클릭 태그를 설정하는 것이 좋습니다. AdChoices 아이콘의 리스너를 추가해야 합니다.

다음 예에서는 <ImageView /> 요소를 뷰 계층 구조에 AdChoices 로고를 고정합니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
        android:id="@+id/adChoices"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:adjustViewBounds="true"
        android:contentDescription="AdChoices icon." />
</LinearLayout>

다음 예에서는 AdChoices 아이콘을 렌더링하고 적절한 클릭 동작을 구성합니다.

자바

private AdSimpleCustomTemplateBinding customTemplateBinding;

private void populateAdView(final NativeCustomFormatAd nativeCustomFormatAd) {
  // Render the AdChoices icon.
  String adChoicesKey = NativeAdAssetNames.ASSET_ADCHOICES_CONTAINER_VIEW;
  NativeAd.Image adChoicesAsset = nativeCustomFormatAd.getImage(adChoicesKey);
  if (adChoicesAsset == null) {
    customTemplateBinding.adChoices.setVisibility(View.GONE);
  } else {
    customTemplateBinding.adChoices.setVisibility(View.VISIBLE);
    customTemplateBinding.adChoices.setImageDrawable(adChoicesAsset.getDrawable());

    // Enable clicks on AdChoices.
    customTemplateBinding.adChoices.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            nativeCustomFormatAd.performClick(adChoicesKey);
          }
        });
  }
  ...
}

Kotlin

private lateinit var customTemplateBinding: AdSimpleCustomTemplateBinding

private fun populateAdView(nativeCustomFormatAd: NativeCustomFormatAd) {
  // Render the AdChoices icon.
  val adChoicesKey = NativeAdAssetNames.ASSET_ADCHOICES_CONTAINER_VIEW
  val adChoicesAsset = nativeCustomFormatAd.getImage(adChoicesKey)
  if (adChoicesAsset == null) {
    customTemplateBinding.adChoices.visibility = View.GONE
  } else {
    customTemplateBinding.adChoices.setImageDrawable(adChoicesAsset.drawable)
    customTemplateBinding.adChoices.visibility = View.VISIBLE

    // Enable clicks on AdChoices.
    customTemplateBinding.adChoices.setOnClickListener {
      nativeCustomFormatAd.performClick(adChoicesKey)
    }
  }
  ...
}

맞춤 네이티브 광고 형식의 네이티브 동영상

맞춤 형식을 만들 때는 다음 안내를 따르세요. 동영상에 적합한 형식을 선택할 수 있습니다.

앱 구현에서 다음을 사용할 수 있습니다. NativeCustomFormatAd.getMediaContent() 드림 미디어 콘텐츠를 가져올 수 있습니다. 그런 다음 setMediaContent()를 호출합니다. 미디어 뷰에서 미디어 콘텐츠를 설정할 수 있습니다. 추가할 수 있습니다. 광고에 동영상 콘텐츠가 없는 경우 광고를 게재할 대체 계획을 세웁니다. 동영상이 없는 광고를 말합니다.

아래 예에서는 광고에 동영상 콘텐츠가 있는지 확인하고 이미지를 표시합니다. 이 표시됩니다.

자바

// Called when a custom native ad loads.
@Override
public void onCustomFormatAdLoaded(final NativeCustomFormatAd ad) {

  MediaContent mediaContent = ad.getMediaContent();

  // Assumes you have a FrameLayout in your view hierarchy with the id media_placeholder.
  FrameLayout mediaPlaceholder = (FrameLayout) findViewById(R.id.media_placeholder);

  // Apps can check the MediaContent's hasVideoContent property to determine if the
  // NativeCustomFormatAd has a video asset.
  if (mediaContent != null && mediaContent.hasVideoContent()) {
    MediaView mediaView = new MediaView(mediaPlaceholder.getContext());
    mediaView.setMediaContent(mediaContent);
    mediaPlaceholder.addView(mediaView);

    // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
    // VideoController will call methods on this object when events occur in the video
    // lifecycle.
    VideoController vc = mediaContent.getVideoController();
    vc.setVideoLifecycleCallbacks(
        new VideoController.VideoLifecycleCallbacks() {
          @Override
          public void onVideoEnd() {
            // Publishers should allow native ads to complete video playback before
            // refreshing or replacing them with another ad in the same UI location.
            super.onVideoEnd();
          }
        });
  } else {
    ImageView mainImage = new ImageView(this);
    mainImage.setAdjustViewBounds(true);
    mainImage.setImageDrawable(ad.getImage("MainImage").getDrawable());
    mediaPlaceholder.addView(mainImage);
    mainImage.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ad.performClick("MainImage");
          }
        });
  }
}

Kotlin

// Called when a custom native ad loads.
NativeCustomFormatAd.OnCustomFormatAdLoadedListener { ad ->

  val mediaContent = ad.mediaContent

  // Apps can check the MediaContent's hasVideoContent property to determine if the
  // NativeCustomFormatAd has a video asset.
  if (mediaContent != null && mediaContent.hasVideoContent()) {
    val mediaView = MediaView(mediaPlaceholder.getContest())
    mediaView.mediaContent = mediaContent

    val videoController = mediaContent.videoController

    // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
    // VideoController will call methods on this object when events occur in the video
    // lifecycle.
    if (videoController != null) {
      videoController.videoLifecycleCallbacks =
        object : VideoController.VideoLifecycleCallbacks() {
          override fun onVideoEnd() {
            // Publishers should allow native ads to complete video playback before refreshing
            // or replacing them with another ad in the same UI location.
            super.onVideoEnd()
          }
        }
    }
  } else {
    val mainImage = ImageView(this)
    mainImage.adjustViewBounds = true
    mainImage.setImageDrawable(ad.getImage("MainImage")?.drawable)

    mainImage.setOnClickListener { ad.performClick("MainImage") }
    customTemplateBinding.simplecustomMediaPlaceholder.addView(mainImage)
  }
}

미디어 콘텐츠를 업로드하는 방법에 대한 자세한 내용은 MediaContent를 참조하세요. 맞춤 네이티브 광고의 동영상 환경을 맞춤설정할 수 있습니다.

Ad Manager 맞춤 렌더링 예시: 네이티브 동영상의 실제 사용 사례

맞춤 네이티브 광고 형식 클릭수 및 노출수

맞춤 네이티브 광고 형식을 사용하면 앱에서 Google 모바일 광고 SDK에 노출을 보고 클릭 이벤트를 보고해야 합니다.

노출 기록

맞춤 형식 광고의 노출을 기록하려면 recordImpression를 호출합니다. 메서드를 NativeCustomFormatAd합니다.

myCustomFormatAd.recordImpression();

앱에서 실수로 동일한 광고에 대해 메서드를 두 번 호출하면 SDK는 광고 1개에 대해 중복 노출이 기록되지 않도록 합니다.

클릭수 보고

애셋 보기에서 클릭이 발생했음을 SDK에 보고하려면 상응하는 NativeCustomFormatAd에서 performClick 메서드를 호출하고 클릭된 애셋의 이름입니다. 예를 들어 'MainImage'라는 맞춤 형식을 게시자 사이트의 클릭을 보고하고자 했으나 ImageView가 있는 경우 코드는 다음과 같습니다.

myCustomFormatAd.performClick("MainImage");

합니다. '캡션'이라는 다른 입력란이 있는 경우 그 것은 앱이 표시되긴 하지만 사용자가 클릭하거나 탭하지 않은 경우에는 앱에서 해당 애셋 보기에 대해 performClick를 호출합니다.

맞춤 클릭 작업에 응답

맞춤 형식 광고에서 클릭이 발생하면 세 가지 가능성이 있습니다. 다음 순서로 시도해야 합니다.

  1. AdLoader에서 OnCustomClickListener를 호출합니다(제공된 경우).
  2. 광고의 딥 링크 URL별로 콘텐츠 리졸버를 찾습니다. 해결되는 첫 번째 항목을 시작합니다.
  3. 브라우저를 열고 광고의 기존 도착 URL로 이동합니다.

forCustomFormatAd 메서드는 OnCustomClickListener를 허용합니다. 만약 리스너 객체를 전달하면 SDK가 onCustomClick 메서드를 대신 호출합니다. 추가 조치를 취하지 않습니다. 그러나 null 값을 리스너로 전달하면 SDK는 있습니다.

맞춤 클릭 리스너를 사용하면 앱이 최적의 액션을 결정할 수 있습니다. 예를 들어 UI 업데이트, 새 활동 실행 또는 기록할 수 있습니다. 다음은 클릭이 1회 이상 발생했다는 것을 장소:

자바

AdLoader adLoader = new AdLoader.Builder(context, "/21775744923/example/native")
    .forCustomFormatAd("10063170",
      new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
        // Display the ad.
      },
      new NativeCustomFormatAd.OnCustomClickListener() {
          @Override
          public void onCustomClick(NativeCustomFormatAd ad, String assetName) {
            Log.i("MyApp", "A custom click just happened for " + assetName + "!");
          }
      }).build();

Kotlin

val adLoader = AdLoader.Builder(this, "/21775744923/example/native")
    .forCustomFormatAd("10063170",
        { ad ->
            // Display the ad.
        },
        { ad, assetName ->
                Log.i("MyApp", "A custom click just happened for $assetName!")
    }).build()

처음에는 맞춤 클릭 리스너가 존재한다는 것이 이상하게 보일 수 있습니다. 결국 방금 앱에서 SDK에 클릭이 발생했음을 알렸는데, SDK가 앱에 신고할까요?

이러한 정보 흐름은 몇 가지 이유로 유용하지만, 무엇보다도 SDK가 클릭에 대한 응답을 계속 제어할 수 있게 합니다. 가능 설정한 제3자 추적 URL을 자동으로 핑(ping)합니다. 다른 작업은 별도의 작업 없이 보이지 않게 처리합니다. 추가할 수 있습니다.