보상형 전면 광고는 자연스러운 앱 전환 중에 자동으로 게재되는 광고에 대해 보상을 제공하는 인센티브형 광고 형식입니다. 보상형 광고와 달리 사용자는 수신 동의하지 않고도 보상형 전면 광고를 볼 수 있습니다.
기본 요건
- Google 모바일 광고 SDK 19.2.0 이상
- 시작 가이드를 완료합니다.
구현
보상형 전면 광고를 통합하는 기본 단계는 다음과 같습니다.
- 광고 로드
- 전체 화면 이벤트 콜백 등록
- 보상 콜백 처리
- 광고 표시
- [선택사항] SSV 콜백 확인
광고 로드
광고는 RewardedInterstitialAd
클래스의 정적 load()
메서드를 사용하여 로드됩니다. 로드 메서드에는 컨텍스트, 광고 단위 ID, AdRequest
객체, 광고 로드에 성공하거나 실패할 때 알림을 받을 RewardedInterstitialAdLoadCallback
이 필요합니다. 로드된 RewardedInterstitialAd
객체는 onRewardedInterstitialAdLoaded()
콜백의 매개변수로 제공됩니다.
다음은 MainActivity
에서 RewardedInterstitialAd
를 로드하는 방법을 보여주는 예입니다.
자바
Kotlin
AD_UNIT_ID를 광고 단위 ID로 바꿉니다.
콜백 등록
표시 이벤트에 대한 알림을 받으려면 FullScreenContentCallback
객체를 광고의 setter에 전달해야 합니다. FullScreenContentCallback
객체는 광고 표시에 성공 또는 실패했을 때와 광고가 닫혔을 때의 콜백을 처리합니다. 다음 코드는 RewardedInterstitialAdLoadCallback
내에서 익명의 FullScreenContentCallback
객체를 설정하는 방법을 보여줍니다.
자바
rewardedInterstitialAd.setFullScreenContentCallback(
new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
// Called when fullscreen content is dismissed.
Log.d(TAG, "The ad was dismissed.");
// Make sure to set your reference to null so you don't
// show it a second time.
rewardedInterstitialAd = null;
if (googleMobileAdsConsentManager.canRequestAds()) {
loadRewardedInterstitialAd();
}
}
@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
// Called when fullscreen content failed to show.
Log.d(TAG, "The ad failed to show.");
// Make sure to set your reference to null so you don't
// show it a second time.
rewardedInterstitialAd = null;
}
@Override
public void onAdShowedFullScreenContent() {
// Called when fullscreen content is shown.
Log.d(TAG, "The ad was shown.");
}
@Override
public void onAdImpression() {
// Called when an impression is recorded for an ad.
Log.d(TAG, "The ad recorded an impression.");
}
@Override
public void onAdClicked() {
// Called when ad is clicked.
Log.d(TAG, "The ad was clicked.");
}
});
Kotlin
rewardedInterstitialAd?.fullScreenContentCallback =
object : FullScreenContentCallback() {
override fun onAdDismissedFullScreenContent() {
// Called when fullscreen content is dismissed.
Log.d(TAG, "Ad was dismissed.")
// Don't forget to set the ad reference to null so you
// don't show the ad a second time.
rewardedInterstitialAd = null
}
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
// Called when fullscreen content failed to show.
Log.d(TAG, "Ad failed to show.")
// Don't forget to set the ad reference to null so you
// don't show the ad a second time.
rewardedInterstitialAd = null
}
override fun onAdShowedFullScreenContent() {
// Called when fullscreen content is shown.
Log.d(TAG, "Ad showed fullscreen content.")
}
override fun onAdImpression() {
// Called when an impression is recorded for an ad.
Log.d(TAG, "Ad recorded an impression.")
}
override fun onAdClicked() {
// Called when an ad is clicked.
Log.d(TAG, "Ad was clicked.")
}
}
광고 표시
보상형 전면 광고를 게재할 때 OnUserEarnedRewardListener
객체를 사용하여 보상 이벤트를 처리합니다.
자바
rewardedInterstitialAd.show(
MainActivity.this,
new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
Log.d(TAG, "The user earned the reward.");
// Handle the reward.
int rewardAmount = rewardItem.getAmount();
String rewardType = rewardItem.getType();
}
});
Kotlin
rewardedInterstitialAd?.show(this) { rewardItem ->
Log.d(TAG, "User earned the reward.")
// Handle the reward.
val rewardAmount = rewardItem.amount
val rewardType = rewardItem.type
}
[선택사항] 서버 측 확인 (SSV) 콜백 검사
서버 측 확인 콜백에서 추가 데이터가 필요한 앱은 보상형 광고의 맞춤 데이터 기능을 사용해야 합니다. 보상형 광고 객체에 설정된 모든 문자열 값은 SSV 콜백의 custom_data
쿼리 매개변수에 전달됩니다. 맞춤 데이터 값이 설정되지 않은 경우 custom_data
쿼리 매개변수 값은 SSV 콜백에 표시되지 않습니다.
다음 코드 샘플은 광고를 요청하기 전에 보상형 전면 광고 객체에 맞춤 데이터를 설정하는 방법을 보여줍니다.
자바
Kotlin
SAMPLE_CUSTOM_DATA_STRING을 맞춤 데이터로 바꿉니다.
광고를 게재하기 전에 맞춤 보상 문자열을 설정해야 합니다.
GitHub의 예
다음 단계
다음 주제를 살펴봅니다.