단일 보상형 전면 광고 로드

단일 로드 API가 포함된 차세대 SDK

보상형 전면 광고는 자연스러운 앱 전환 중에 자동으로 게재되는 광고에 대해 보상을 제공하는 형식입니다. 보상형 광고와 달리 사용자는 수신 동의하지 않고도 보상형 전면 광고를 볼 수 있습니다. 자세한 내용은 보상형 전면 광고 가이드를 참고하세요.

이 가이드에서는 보상형 전면 광고를 Android 앱에 통합하는 방법을 설명합니다.

기본 요건

설정 GMA Next-Gen SDK.

항상 테스트 광고로 테스트

앱을 빌드하고 테스트할 때는 운영 중인 실제 광고 대신 테스트 광고를 사용하세요. 테스트 광고를 사용하지 않으면 Google에서 계정을 정지할 수 있습니다.

테스트 광고를 로드하는 가장 쉬운 방법은 Android 보상형 전면 광고 테스트를 위한 전용 테스트 광고 단위 ID를 사용하는 것입니다.

ca-app-pub-3940256099942544/5354046379

이 광고 단위 ID는 모든 요청에 대해 테스트 광고를 반환하도록 특별히 구성되었습니다. 코딩, 테스트, 디버깅 중에 자체 앱에서 자유롭게 사용할 수 있습니다. 앱을 게시하기 전에 이 ID를 자체 광고 단위 ID로 바꿔야 합니다.

GMA Next-Gen SDK 테스트 광고에 관한 자세한 내용은 테스트 광고 사용 설정을 참고하세요.

광고 로드

다음 예에서는 단일 광고를 로드하는 방법을 보여줍니다.

Kotlin

// Load ads after you initialize MobileAds.
RewardedInterstitialAd.load(
  AdRequest.Builder(adUnitId).build(),
  object : AdLoadCallback<RewardedInterstitialAd> {
    override fun onAdLoaded(ad: RewardedInterstitialAd) {
      // Rewarded interstitial ad loaded.
      rewardedInterstitialAd = ad
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      // Rewarded interstitial ad failed to load.
      Log.e(TAG, "Rewarded interstitial ad failed to load: ${adError.message}")
      rewardedInterstitialAd = null
    }
  },
)

자바

// Load ads after you initialize MobileAds.
RewardedInterstitialAd.load(
    new AdRequest.Builder(adUnitId).build(),
    new AdLoadCallback<RewardedInterstitialAd>() {
      @Override
      public void onAdLoaded(@NonNull RewardedInterstitialAd ad) {
        // Rewarded interstitial ad loaded.
        rewardedInterstitialAd = ad;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError adError) {
        // Rewarded interstitial ad failed to load.
        Log.e(TAG, "Rewarded interstitial ad failed to load: " + adError.getMessage());
        rewardedInterstitialAd = null;
      }
    });

테스트할 때는 테스트 광고 단위 ID ca-app-pub-3940256099942544/5354046379를 사용하세요.

광고 표시

보상형 전면 광고를 표시하려면 show 메서드를 사용하세요. OnUserEarnedRewardListener 객체를 사용하여 보상 이벤트를 처리합니다.

Kotlin

private fun showAd(rewardedInterstitialAd: RewardedInterstitialAd, activity: Activity) {
  // Show the ad.
  rewardedInterstitialAd.show(
    activity,
    object : OnUserEarnedRewardListener {
      override fun onUserEarnedReward(rewardItem: RewardItem) {
        // User earned the reward.
        val rewardAmount = rewardItem.amount
        val rewardType = rewardItem.type
      }
    },
  )
}

자바

private void showAd(RewardedInterstitialAd rewardedInterstitialAd, Activity activity) {
  // Show the ad.
  rewardedInterstitialAd.show(
      activity,
      new OnUserEarnedRewardListener() {
        @Override
        public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
          // User earned the reward.
          int rewardAmount = rewardItem.getAmount();
          String rewardType = rewardItem.getType();
        }
      });
}

광고 이벤트 수신 대기

광고를 표시하기 전에 광고 수명 주기 이벤트를 수신 대기합니다.

Kotlin

private fun listenToAdEvents() {
  // Listen for ad events.
  val ad = rewardedInterstitialAd
  if (ad == null) {
    Log.e(TAG, "Rewarded interstitial ad is not ready yet.")
    return
  }

  ad.adEventCallback =
    object : RewardedInterstitialAdEventCallback {
      override fun onAdShowedFullScreenContent() {
        // Rewarded interstitial ad did show.
      }

      override fun onAdDismissedFullScreenContent() {
        // Rewarded interstitial ad did dismiss.
        rewardedInterstitialAd = null
      }

      override fun onAdFailedToShowFullScreenContent(
        fullScreenContentError: FullScreenContentError
      ) {
        // Rewarded interstitial ad failed to show.
        Log.e(TAG, "Rewarded interstitial ad failed to show: ${fullScreenContentError.message}")
      }

      override fun onAdImpression() {
        // Rewarded interstitial ad did record an impression.
      }

      override fun onAdClicked() {
        // Rewarded interstitial ad did record a click.
      }
    }
}

자바

private void listenToAdEvents() {
  // Listen for ad events.
  if (rewardedInterstitialAd == null) {
    Log.e(TAG, "Rewarded interstitial ad is not ready yet.");
    return;
  }

  rewardedInterstitialAd.setAdEventCallback(
      new RewardedInterstitialAdEventCallback() {
        @Override
        public void onAdShowedFullScreenContent() {
          // Rewarded interstitial ad did show.
        }

        @Override
        public void onAdDismissedFullScreenContent() {
          // Rewarded interstitial ad did dismiss.
          rewardedInterstitialAd = null;
        }

        @Override
        public void onAdFailedToShowFullScreenContent(
            @NonNull FullScreenContentError fullScreenContentError) {
          // Rewarded interstitial ad failed to show.
          Log.e(
              TAG,
              "Rewarded interstitial ad failed to show: " + fullScreenContentError.getMessage());
        }

        @Override
        public void onAdImpression() {
          // Rewarded interstitial ad did record an impression.
        }

        @Override
        public void onAdClicked() {
          // Rewarded interstitial ad did record a click.
        }
      });
}

선택사항: 서버 측 확인 (SSV) 콜백 검사

앱에 서버 측 확인 콜백에서 추가 데이터가 필요한 경우 보상형 전면 광고의 맞춤 데이터 기능을 사용하세요. 보상형 전면 광고 객체에 설정된 모든 문자열 값은 SSV 콜백의 custom_data 쿼리 매개변수에 전달됩니다. 맞춤 데이터 값이 설정되지 않은 경우 custom_data 쿼리 매개변수 값이 SSV 콜백에 표시되지 않습니다.

다음 코드 샘플에서는 광고를 요청하기 전에 보상형 전면 광고 객체에 맞춤 데이터를 설정하는 방법을 보여줍니다.

Kotlin

RewardedInterstitialAd.load(
  context,
  AD_UNIT_ID,
  AdRequest.Builder().build(),
  object : RewardedInterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: RewardedInterstitialAd) {
      rewardedInterstitialAd = ad
      val options =
        ServerSideVerificationOptions.Builder().setCustomData("SAMPLE_CUSTOM_DATA_STRING").build()
      rewardedInterstitialAd?.setServerSideVerificationOptions(options)
    }
  },
)

자바

RewardedInterstitialAd.load(
    context,
    AD_UNIT_ID,
    new AdRequest.Builder().build(),
    new RewardedInterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(RewardedInterstitialAd ad) {
        rewardedInterstitialAd = ad;
        ServerSideVerificationOptions options =
            new ServerSideVerificationOptions.Builder()
                .setCustomData("SAMPLE_CUSTOM_DATA_STRING")
                .build();
        rewardedInterstitialAd.setServerSideVerificationOptions(options);
      }
    });

SAMPLE_CUSTOM_DATA_STRING을 맞춤 데이터로 바꿉니다.

맞춤 보상 문자열을 설정하려면 광고를 표시하기 전에 설정해야 합니다.