보상형 광고

보상형 광고 를 사용하면 동영상 광고, 플레이어블 광고, 설문조사와 상호작용하는 사용자에게 인앱 상품을 보상으로 제공할 수 있습니다.

기본 요건

  • Google 모바일 광고 SDK 19.7.0 이상
  • 시작 가이드에 따라 필요한 과정을 완료합니다.

항상 테스트 광고로 테스트

앱을 제작하고 테스트할 때는 운영 중인 실제 광고 대신 테스트 광고를 사용하세요. 이렇게 하지 않으면 계정이 정지될 수 있습니다.

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

ca-app-pub-3940256099942544/5224354917

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

모바일 광고 SDK의 테스트 광고가 작동하는 방식을 자세히 알아보려면 테스트 광고를 참고하세요.

Load a rewarded ad object

Rewarded ads are loaded by calling the static load() method on the RewardedAd class and passing in a RewardedAdLoadCallback. This is usually done in the onCreate() method of an Activity. Notice that like other format load callbacks, RewardedAdLoadCallback leverages LoadAdError to provide higher fidelity error details.

Java

import com.google.android.gms.ads.rewarded.RewardedAd;

public class MainActivity extends Activity {
  private RewardedAd rewardedAd;
  private final String TAG = "MainActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    AdRequest adRequest = new AdRequest.Builder().build();
    RewardedAd.load(this, "ca-app-pub-3940256099942544/5224354917",
      adRequest, new RewardedAdLoadCallback() {
        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
          // Handle the error.
          Log.d(TAG, loadAdError.toString());
          rewardedAd = null;
        }

        @Override
        public void onAdLoaded(@NonNull RewardedAd ad) {
          rewardedAd = ad;
          Log.d(TAG, "Ad was loaded.");
        }
    });
  }
}

Kotlin

class MainActivity : AppCompatActivity() {

  private var rewardedAd: RewardedAd? = null
  private final var TAG = "MainActivity"

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    var adRequest = AdRequest.Builder().build()
    RewardedAd.load(this,"ca-app-pub-3940256099942544/5224354917", adRequest, object : RewardedAdLoadCallback() {
      override fun onAdFailedToLoad(adError: LoadAdError) {
        Log.d(TAG, adError?.toString())
        rewardedAd = null
      }

      override fun onAdLoaded(ad: RewardedAd) {
        Log.d(TAG, "Ad was loaded.")
        rewardedAd = ad
       }
    })
  }
}

Set the FullScreenContentCallback

The FullScreenContentCallback handles events related to displaying your RewardedAd. Before you show your RewardedAd, make sure to set the callback like so:

Java

rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {
  @Override
  public void onAdClicked() {
    // Called when a click is recorded for an ad.
    Log.d(TAG, "Ad was clicked.");
  }

   @Override
  public void onAdDismissedFullScreenContent() {
    // Called when ad is dismissed.
    // Set the ad reference to null so you don't show the ad a second time.
    Log.d(TAG, "Ad dismissed fullscreen content.");
    rewardedAd = null;
  }

  @Override
  public void onAdFailedToShowFullScreenContent(AdError adError) {
    // Called when ad fails to show.
    Log.e(TAG, "Ad failed to show fullscreen content.");
    rewardedAd = null;
  }

  @Override
  public void onAdImpression() {
    // Called when an impression is recorded for an ad.
    Log.d(TAG, "Ad recorded an impression.");
  }

  @Override
  public void onAdShowedFullScreenContent() {
    // Called when ad is shown.
    Log.d(TAG, "Ad showed fullscreen content.");
  }
});

Kotlin

rewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
  override fun onAdClicked() {
    // Called when a click is recorded for an ad.
    Log.d(TAG, "Ad was clicked.")
  }

  override fun onAdDismissedFullScreenContent() {
    // Called when ad is dismissed.
    // Set the ad reference to null so you don't show the ad a second time.
    Log.d(TAG, "Ad dismissed fullscreen content.")
    rewardedAd = null
  }

  override fun onAdFailedToShowFullScreenContent(adError: AdError?) {
    // Called when ad fails to show.
    Log.e(TAG, "Ad failed to show fullscreen content.")
    rewardedAd = null
  }

  override fun onAdImpression() {
    // Called when an impression is recorded for an ad.
    Log.d(TAG, "Ad recorded an impression.")
  }

  override fun onAdShowedFullScreenContent() {
    // Called when ad is shown.
    Log.d(TAG, "Ad showed fullscreen content.")
  }
}

Show the ad

When you show a rewarded ad, you will use an OnUserEarnedRewardListener object to handle reward events.

Java

if (rewardedAd != null) {
  Activity activityContext = MainActivity.this;
  rewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
    @Override
    public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
      // Handle the reward.
      Log.d(TAG, "The user earned the reward.");
      int rewardAmount = rewardItem.getAmount();
      String rewardType = rewardItem.getType();
    }
  });
} else {
  Log.d(TAG, "The rewarded ad wasn't ready yet.");
}

Kotlin

rewardedAd?.let { ad ->
  ad.show(this, OnUserEarnedRewardListener { rewardItem ->
    // Handle the reward.
    val rewardAmount = rewardItem.amount
    val rewardType = rewardItem.type
    Log.d(TAG, "User earned the reward.")
  })
} ?: run {
  Log.d(TAG, "The rewarded ad wasn't ready yet.")
}

[Optional] Validate server-side verification (SSV) callbacks

Apps that require extra data in server-side verification callbacks should use the custom data feature of rewarded ads. Any string value set on a rewarded ad object is passed to the custom_data query parameter of the SSV callback. If no custom data value is set, the custom_data query parameter value won't be present in the SSV callback.

The following code sample demonstrates how to set custom data on a rewarded ad object before requesting an ad.

Java

RewardedAd.load(MainActivity.this, "ca-app-pub-3940256099942544/5354046379",
    new AdRequest.Builder().build(),  new RewardedAdLoadCallback() {
  @Override
  public void onAdLoaded(RewardedAd ad) {
    Log.d(TAG, "Ad was loaded.");
    rewardedAd = ad;
    ServerSideVerificationOptions options = new ServerSideVerificationOptions
        .Builder()
        .setCustomData("SAMPLE_CUSTOM_DATA_STRING")
        .build();
    rewardedAd.setServerSideVerificationOptions(options);
  }
  @Override
  public void onAdFailedToLoad(LoadAdError loadAdError) {
      Log.d(TAG, loadAdError.toString());
      rewardedAd = null;
  }
});

Kotlin

RewardedAd.load(this, "ca-app-pub-3940256099942544/5354046379",
    AdRequest.Builder().build(), object : RewardedAdLoadCallback() {
  override fun onAdLoaded(ad: RewardedAd) {
    Log.d(TAG, "Ad was loaded.")
    rewardedInterstitialAd = ad
    val options = ServerSideVerificationOptions.Builder()
        .setCustomData("SAMPLE_CUSTOM_DATA_STRING")
        .build()
    rewardedAd.setServerSideVerificationOptions(options)
  }

  override fun onAdFailedToLoad(adError: LoadAdError) {
      Log.d(TAG, adError?.toString())
      rewardedAd = null
  }
})

If you want to set the custom reward string, you must do so before showing the ad.

FAQ

초기화 호출에 제한 시간이 있나요?
10초가 지나면 미디에이션 네트워크에서 아직 초기화를 완료하지 않은 경우에도 Google 모바일 광고 SDK가 OnInitializationCompleteListener를 호출합니다.
초기화 콜백을 받을 때 일부 미디에이션 네트워크가 준비되지 않은 경우 어떻게 해야 하나요?

OnInitializationCompleteListener의 콜백 내에서 광고를 로드하는 것이 좋습니다. 미디에이션 네트워크가 준비되지 않은 경우에도 Google 모바일 광고 SDK에서 해당 네트워크에 광고를 요청합니다. 따라서 미디에이션 네트워크에서 시간이 초과된 후에 초기화를 완료해도 해당 세션에서 향후 광고 요청을 처리할 수 있습니다.

MobileAds.getInitializationStatus()를 호출하여 앱 세션 전체에서 모든 어댑터의 초기화 상태를 폴링할 수 있습니다.

특정 미디에이션 네트워크가 준비되지 않은 이유를 확인하려면 어떻게 해야 하나요?

AdapterStatus.getDescription()를 통해 어댑터에서 광고 요청을 처리할 준비가 되지 않은 이유를 알아볼 수 있습니다.

onUserEarnedReward() 콜백이 항상 onAdDismissedFullScreenContent() 콜백보다 먼저 호출되나요?

Google 광고의 경우 모든 onUserEarnedReward() 호출은 onAdDismissedFullScreenContent() 전에 발생합니다. 미디에이션을 통해 게재되는 광고의 경우 서드 파티 광고 네트워크 SDK의 구현에 따라 콜백 순서가 결정됩니다. 단일 닫기 콜백에 리워드 정보를 제공하는 광고 네트워크 SDK의 경우 미디에이션 어댑터가 onAdDismissedFullScreenContent() 전에 onUserEarnedReward()를 호출합니다.

GitHub의 예

다음 단계

다음 주제를 살펴보세요.