광고 사전 로드 (베타)

광고 미리 로드는 Google Mobile Ads SDK (Legacy)의 Google 관리 광고 로드 기능으로, 사용자를 대신하여 광고 로드 및 캐싱을 관리합니다. 광고 미리 로드를 사용하려면 광고 로드 관리 방식을 변경해야 합니다. 광고 사전 로드를 사용하여 성능을 최적화하려면 맞춤 캐싱을 사용 중지하고 Google Mobile Ads SDK (Legacy)에 이 책임을 위임하세요.

광고 미리 로드는 수동 광고 로드에 비해 다음과 같은 이점을 제공합니다.

  • 참조 관리: 로드된 광고를 보관하므로 광고를 게재할 준비가 될 때까지 참조를 유지할 필요가 없습니다.
  • 자동 다시 로드: 캐시에서 광고를 가져오면 새 광고를 자동으로 로드합니다.
  • 관리되는 재시도: 지수 백오프를 사용하여 실패한 요청을 자동으로 다시 시도합니다.
  • 만료 처리: 만료되기 전에 (일반적으로 1시간 후) 광고를 자동으로 새로고침합니다.
  • 캐시 최적화: 캐시 크기가 1보다 큰 경우 Google Mobile Ads SDK (Legacy) 최적의 광고를 게재하기 위해 캐시 순서를 최적화합니다.

이 가이드에서는 광고 미리 로드 구성, 광고 미리 로드 가능 여부 확인, 미리 로드된 광고 게재 방법을 설명합니다.

기본 요건

이 가이드를 계속 진행하기 전에 설정해야 합니다Google Mobile Ads SDK (Legacy).

광고 미리 로드 시작

앱이 시작되면 start 메서드를 한 번 호출합니다. 메서드를 호출하면 Google Mobile Ads SDK (Legacy)는 광고를 자동으로 미리 로드하고 미리 로드된 구성에 대해 실패한 요청을 다시 시도합니다.start

다음 예에서는 광고 미리 로드를 시작합니다.

Kotlin

// Define a PreloadConfiguration.
val configuration = PreloadConfiguration.Builder("AD_UNIT_ID").build()
// Start the preloading with a given preload ID, preload configuration.
InterstitialAdPreloader.start("AD_UNIT_ID", configuration)

자바

// Define a PreloadConfiguration.
PreloadConfiguration configuration = new PreloadConfiguration.Builder("AD_UNIT_ID").build();
// Start the preloading with a given preload ID, preload configuration.
InterstitialAdPreloader.start("AD_UNIT_ID", configuration);

AD_UNIT_ID를 광고 단위 ID로 바꿉니다.

미리 로드된 광고 가져오기 및 표시

광고 미리 로드를 사용하면 Google Mobile Ads SDK (Legacy)는 캐시된 광고를 보관합니다. 광고를 게재하려면 pollAd 메서드를 호출합니다. Google Mobile Ads SDK (Legacy)는 사용 가능한 광고를 가져오고 백그라운드에서 다음 광고를 자동으로 미리 로드합니다.

광고를 게재할 준비가 될 때까지 pollAd 메서드를 호출하지 마세요. 광고를 캐시에 보관하면 Google Mobile Ads SDK (Legacy) 만료된 광고를 자동으로 새로고침하고 캐시 최적화를 실행할 수 있습니다.

다음 예에서는 미리 로드된 광고를 가져와서 게재합니다.

Kotlin

// pollAd() returns the next available ad and loads another ad in the background.
val ad = InterstitialAdPreloader.pollAd("AD_UNIT_ID")

// [Optional] Interact with the ad as needed.
ad?.onPaidEventListener = OnPaidEventListener {
  // [Optional] Send the impression-level ad revenue information to your preferred
  // analytics server directly within this callback.
}

// Show the ad immediately.
ad?.show(activity)

자바

// pollAd() returns the next available ad and loads another ad in the background.
InterstitialAd ad = InterstitialAdPreloader.pollAd("AD_UNIT_ID");

if (ad != null) {
  // [Optional] Interact with the ad object as needed.
  ad.setOnPaidEventListener(
      adValue -> {
        // [Optional] Send the impression-level ad revenue information to your preferred
        // analytics server directly within this callback.
      });

  // Show the ad immediately.
  ad.show(activity);
}

광고 미리 로드 가능 여부 확인

광고 가능 여부를 확인하려면 다음 중 하나를 선택하세요.

미리 로드된 광고 가능 여부 가져오기

다음 예에서는 광고 가능 여부를 확인합니다.

Kotlin

// Verify that a preloaded ad is available.
if (!InterstitialAdPreloader.isAdAvailable("AD_UNIT_ID")) {
  // No ads are available to show.
}

자바

// Verify that a preloaded ad is available.
if (!InterstitialAdPreloader.isAdAvailable("AD_UNIT_ID")) {
  // No ads are available to show.
}

미리 로드된 광고 가능 여부 수신 대기

광고가 미리 로드되거나, 미리 로드에 실패하거나, 광고 캐시가 소진될 때 알림을 받으려면 미리 로드 이벤트를 등록하세요.

미리 로드 이벤트는 분석 목적으로 사용됩니다. 미리 로드 이벤트 콜백 내에서 다음을 실행합니다.

  • start를 호출하지 마세요.
  • 광고가 즉시 게재되지 않는 한 pollAd를 호출하지 마세요.

다음 예에서는 광고 이벤트를 등록합니다.

Kotlin

// Define a callback to receive preload events.
val callback =
  object : PreloadCallbackV2() {
    override fun onAdPreloaded(preloadId: String, responseInfo: ResponseInfo?) {
      // Called when preloaded ads are available.
    }

    override fun onAdsExhausted(preloadId: String) {
      // Called when no preloaded ads are available.
    }

    override fun onAdFailedToPreload(preloadId: String, adError: AdError) {
      // Called when preloaded ads failed to load.
    }
  }

자바

// Define a callback to receive preload events.
PreloadCallbackV2 callback =
    new PreloadCallbackV2() {
      @Override
      public void onAdPreloaded(
          @NonNull String preloadId, @Nullable ResponseInfo responseInfo) {
        // Called when preloaded ads are available.
      }

      @Override
      public void onAdsExhausted(@NonNull String preloadId) {
        // Called when no preloaded ads are available.
      }

      @Override
      public void onAdFailedToPreload(@NonNull String preloadId, @NonNull AdError adError) {
        // Called when preloaded ads failed to load.
      }
    };

광고 미리 로드 중지

세션에서 미리 로드 ID의 광고를 다시 게재할 필요가 없는 경우 광고 미리 로드를 중지할 수 있습니다. 특정 미리 로드 ID의 광고 미리 로드를 중지하려면 미리 로드 ID와 함께 destroy를 호출합니다. 모든 미리 로더의 미리 로드를 중지하려면 destroyAll을 호출합니다.

Kotlin

// Stops the preloading and destroy preloaded ads.
InterstitialAdPreloader.destroy("AD_UNIT_ID")
// Stops the preloading and destroy all ads.
InterstitialAdPreloader.destroyAll()

자바

// Stops the preloading and destroy preloaded ads.
InterstitialAdPreloader.destroy("AD_UNIT_ID");
// Stops the preloading and destroy all ads.
InterstitialAdPreloader.destroyAll();

버퍼 사이즈 설정

버퍼 크기는 메모리에 보관되는 미리 로드된 광고 수를 제어합니다. 기본적으로 Google은 메모리 사용량과 광고 게재 지연 시간을 균형 있게 조정하기 위해 버퍼 크기를 최적화합니다. 앱에서 다음 광고가 로드되기 전에 광고를 게재하는 경우 맞춤 버퍼 크기를 설정하여 메모리에 보관되는 광고 수를 늘릴 수 있습니다.

Kotlin

// Define a PreloadConfiguration and buffer up to 3 preloaded ads.
val configuration = PreloadConfiguration.Builder("AD_UNIT_ID").setBufferSize(3).build()

자바

// Define a PreloadConfiguration and buffer up to 3 preloaded ads.
PreloadConfiguration configuration =
    new PreloadConfiguration.Builder("AD_UNIT_ID").setBufferSize(3).build();

미리 로드 캐시 한도

Google Mobile Ads SDK (Legacy)는 모든 광고 단위 및 미리 로드 ID에서 미리 로드된 광고의 총 수에 앱 전체 한도를 적용합니다.

  • 기본 한도: Google Mobile Ads SDK (Legacy)는 메모리에 미리 로드된 광고를 최대 6개까지 보관합니다. 이 한도는 모든 형식과 미리 로드 ID에서 공유됩니다.
  • 미리 로드 ID당 버퍼 사이즈를 2 또는 3으로 유지하는 것이 좋습니다.