보상형 광고 맞춤 이벤트
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
기본 요건
맞춤 이벤트 설정을 완료합니다.
보상형 광고 요청
폭포식 구조 미디에이션 체인에서 맞춤 이벤트 광고 항목에 도달하면 맞춤 이벤트를 만들 때 제공한 클래스 이름에 loadRewardedAd()
메서드가 호출됩니다. 이 경우 이 메서드는 SampleCustomEvent
에 있고 SampleRewardedCustomEventLoader
에서 loadRewardedAd()
메서드를 호출합니다.
보상형 광고를 요청하려면 Adapter
를 확장하여 loadRewardedAd()
를 구현하는 클래스를 만들거나 수정하세요. 또한 MediationRewardedAd
를 구현할 새 클래스를 만듭니다.
맞춤 이벤트 예에서 SampleCustomEvent
는 Adapter
클래스를 확장한 다음 SampleRewardedCustomEventLoader
에 위임합니다.
자바
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationRewardedAd;
import com.google.android.gms.ads.mediation.MediationRewardedAdCallback;
...
public class SampleCustomEvent extends Adapter {
private SampleNativeCustomEventLoader nativeLoader;
@Override
public void loadRewardedAd(
@NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,
@NonNull
MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
mediationAdLoadCallback) {
rewardedLoader =
new SampleRewardedCustomEventLoader(
mediationRewardedAdConfiguration, mediationAdLoadCallback);
rewardedLoader.loadAd();
}
}
SampleRewardedCustomEventLoader
는 다음 작업을 담당합니다.
Ad Manager UI에 정의된 선택적 매개변수는 광고 구성에 포함됩니다. adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD)
를 통해 매개변수에 액세스할 수 있습니다.
이 매개변수는 일반적으로 광고 네트워크 SDK가 광고 객체를 인스턴스화할 때 요구하는 광고 단위 식별자입니다.
자바
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationRewardedAd;
import com.google.android.gms.ads.mediation.MediationRewardedAdCallback;
...
public class SampleRewardedCustomEventLoader extends SampleRewardedAdListener
implements MediationRewardedAd {
/** Configuration for requesting the rewarded ad from the third-party network. */
private final MediationRewardedAdConfiguration mediationRewardedAdConfiguration;
/**
* A {@link MediationAdLoadCallback} that handles any callback when a Sample
* rewarded ad finishes loading.
*/
private final MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
mediationAdLoadCallback;
/** Callback for rewarded ad events. */
private MediationRewardedAdCallback rewardedAdCallback;
/** Constructor. */
public SampleRewardedCustomEventLoader(
@NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,
@NonNull MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
mediationAdLoadCallback) {
this.mediationRewardedAdConfiguration = mediationRewardedAdConfiguration;
this.mediationAdLoadCallback = mediationAdLoadCallback;
}
/** Loads the rewarded ad from the third-party ad network. */
public void loadAd() {
// All custom events have a server parameter named "parameter" that returns
// back the parameter entered into the AdMob UI when defining the custom event.
Log.i("RewardedCustomEvent", "Begin loading rewarded ad.");
String serverParameter = mediationRewardedAdConfiguration
.getServerParameters()
.getString(MediationConfiguration
.CUSTOM_EVENT_SERVER_PARAMETER_FIELD);
Log.d("RewardedCustomEvent", "Received server parameter.");
SampleAdRequest request = createSampleRequest(mediationRewardedAdConfiguration);
sampleRewardedAd = new SampleRewardedAd(serverParameter);
sampleRewardedAd.setListener(this);
Log.i("RewardedCustomEvent", "Start fetching rewarded ad.");
sampleRewardedAd.loadAd(request);
}
public SampleAdRequest createSampleRequest(
MediationAdConfiguration mediationAdConfiguration) {
SampleAdRequest request = new SampleAdRequest();
request.setTestMode(mediationAdConfiguration.isTestRequest());
request.setKeywords(mediationAdConfiguration.getMediationExtras().keySet());
return request;
}
}
광고를 성공적으로 가져왔는지 아니면 오류가 발생했는지에 따라 onSuccess()
또는 onFailure()
를 호출합니다.
MediationRewardedAd
를 구현하는 클래스의 인스턴스를 전달하여 onSuccess()
가 호출됩니다.
일반적으로 이러한 메서드는 어댑터가 구현하는 서드 파티 SDK의 콜백 내에서 구현됩니다. 다음 예시의 샘플 SDK에는 관련 콜백이 있는 SampleAdListener
가 있습니다.
자바
@Override
public void onRewardedAdLoaded() {
rewardedAdCallback = mediationAdLoadCallback.onSuccess(this);
}
@Override
public void onRewardedAdFailedToLoad(SampleErrorCode errorCode) {
mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));
}
MediationRewardedAd
에서는 광고를 표시하기 위해 showAd()
메서드를 구현해야 합니다.
자바
@Override
public void showAd(Context context) {
if (!(context instanceof Activity)) {
rewardedAdCallback.onAdFailedToShow(
SampleCustomEventError.createCustomEventNoActivityContextError());
return;
}
Activity activity = (Activity) context;
if (!sampleRewardedAd.isAdAvailable()) {
rewardedAdCallback.onAdFailedToShow(
SampleCustomEventError.createCustomEventAdNotAvailableError());
return;
}
sampleRewardedAd.showAd(activity);
}
onSuccess()
가 호출되면 어댑터가 반환된 MediationRewardedAdCallback
객체를 사용하여 프레젠테이션 이벤트를 서드 파티 SDK에서 Google 모바일 광고 SDK로 전달할 수 있습니다. SampleRewardedCustomEventLoader
클래스는 SampleAdListener
인터페이스를 확장하여 샘플 광고 네트워크의 콜백을 Google 모바일 광고 SDK에 전달합니다.
맞춤 이벤트가 이러한 콜백을 최대한 많이 전달하여 앱이 Google 모바일 광고 SDK에서 동등한 이벤트를 수신하도록 하는 것이 중요합니다. 다음은 콜백을 사용하는 방법의 예시입니다.
자바
@Override
public void onAdRewarded(final String rewardType, final int amount) {
RewardItem rewardItem =
new RewardItem() {
@Override
public String getType() {
return rewardType;
}
@Override
public int getAmount() {
return amount;
}
};
rewardedAdCallback.onUserEarnedReward(rewardItem);
}
@Override
public void onAdClicked() {
rewardedAdCallback.reportAdClicked();
}
@Override
public void onAdFullScreen() {
rewardedAdCallback.onAdOpened();
rewardedAdCallback.onVideoStart();
rewardedAdCallback.reportAdImpression();
}
@Override
public void onAdClosed() {
rewardedAdCallback.onAdClosed();
}
@Override
public void onAdCompleted() {
rewardedAdCallback.onVideoComplete();
}
보상형 광고용 맞춤 이벤트 구현이 완료되었습니다. 전체 예시는 GitHub에서 확인할 수 있습니다.
이미 지원되는 광고 네트워크에 예를 사용하거나 예를 수정하여 맞춤 이벤트 보상형 광고를 게재할 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-02(UTC)
[null,null,["최종 업데이트: 2025-09-02(UTC)"],[[["\u003cp\u003eTo request a rewarded ad through a custom event, create a class extending \u003ccode\u003eAdapter\u003c/code\u003e and implement the \u003ccode\u003eloadRewardedAd()\u003c/code\u003e method, delegating the ad loading process to a separate loader class.\u003c/p\u003e\n"],["\u003cp\u003eThe loader class is responsible for loading the ad, implementing the \u003ccode\u003eMediationRewardedAd\u003c/code\u003e interface, and handling ad event callbacks.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful ad loading, call \u003ccode\u003eonSuccess()\u003c/code\u003e on the \u003ccode\u003eMediationAdLoadCallback\u003c/code\u003e, passing in the \u003ccode\u003eMediationRewardedAd\u003c/code\u003e implementation; on failure, call \u003ccode\u003eonFailure()\u003c/code\u003e with the error.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMediationRewardedAd\u003c/code\u003e implementation must include a \u003ccode\u003eshowAd()\u003c/code\u003e method to display the ad when called.\u003c/p\u003e\n"],["\u003cp\u003eForward ad events from the third-party SDK to the Google Mobile Ads SDK using the \u003ccode\u003eMediationRewardedAdCallback\u003c/code\u003e to ensure consistent ad behavior and reporting.\u003c/p\u003e\n"]]],[],null,["Prerequisites\n\nComplete the [custom events setup](/ad-manager/mobile-ads-sdk/android/custom-events/setup).\n\nRequest a rewarded ad\n\nWhen the custom event line item is reached in the waterfall mediation chain,\nthe `loadRewardedAd()` method is called on the class name you\nprovided when [creating a custom\nevent](/ad-manager/mobile-ads-sdk/android/custom-events/setup#create). In this case,\nthat method is in `SampleCustomEvent`, which then calls the `loadRewardedAd()`\nmethod in `SampleRewardedCustomEventLoader`.\n\nTo request a rewarded ad, create or modify a class that extends `Adapter` to\nimplement `loadRewardedAd()`. Additionally, create a new class to implement\n`MediationRewardedAd`.\n\nIn our [custom event example](//github.com/googleads/googleads-mobile-android-mediation/blob/main/Example/customevent/src/main/java/com/google/ads/mediation/sample/customevent/SampleCustomEvent.java),\n`SampleCustomEvent` extends the `Adapter` class and then delegates to\n`SampleRewardedCustomEventLoader`. \n\nJava \n\n```java\npackage com.google.ads.mediation.sample.customevent;\n\nimport com.google.android.gms.ads.mediation.Adapter;\nimport com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;\nimport com.google.android.gms.ads.mediation.MediationAdConfiguration;\nimport com.google.android.gms.ads.mediation.MediationAdLoadCallback;\nimport com.google.android.gms.ads.mediation.MediationRewardedAd;\nimport com.google.android.gms.ads.mediation.MediationRewardedAdCallback;\n...\n\npublic class SampleCustomEvent extends Adapter {\n\n private SampleNativeCustomEventLoader nativeLoader;\n\n @Override\n public void loadRewardedAd(\n @NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,\n @NonNull\n MediationAdLoadCallback\u003cMediationRewardedAd, MediationRewardedAdCallback\u003e\n mediationAdLoadCallback) {\n rewardedLoader =\n new SampleRewardedCustomEventLoader(\n mediationRewardedAdConfiguration, mediationAdLoadCallback);\n rewardedLoader.loadAd();\n }\n}\n```\n\n`SampleRewardedCustomEventLoader` is responsible for the following tasks:\n\n- Loading the rewarded ad\n\n- Implementing the `MediationRewardedAd` interface.\n\n- Receiving and reporting ad event callbacks to Google Mobile Ads SDK.\n\nThe optional parameter defined in the Ad Manager UI is\nincluded in the ad configuration. The parameter can be accessed through\n`adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD)`.\nThis parameter is typically an ad unit identifier that an ad network SDK\nrequires when instantiating an ad object. \n\nJava \n\n```java\npackage com.google.ads.mediation.sample.customevent;\n\nimport com.google.android.gms.ads.mediation.Adapter;\nimport com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;\nimport com.google.android.gms.ads.mediation.MediationAdLoadCallback;\nimport com.google.android.gms.ads.mediation.MediationRewardedAd;\nimport com.google.android.gms.ads.mediation.MediationRewardedAdCallback;\n...\n\npublic class SampleRewardedCustomEventLoader extends SampleRewardedAdListener\n implements MediationRewardedAd {\n\n /** Configuration for requesting the rewarded ad from the third-party network. */\n private final MediationRewardedAdConfiguration mediationRewardedAdConfiguration;\n\n /**\n * A {@link MediationAdLoadCallback} that handles any callback when a Sample\n * rewarded ad finishes loading.\n */\n private final MediationAdLoadCallback\u003cMediationRewardedAd, MediationRewardedAdCallback\u003e\n mediationAdLoadCallback;\n\n /** Callback for rewarded ad events. */\n private MediationRewardedAdCallback rewardedAdCallback;\n\n /** Constructor. */\n public SampleRewardedCustomEventLoader(\n @NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,\n @NonNull MediationAdLoadCallback\u003cMediationRewardedAd, MediationRewardedAdCallback\u003e\n mediationAdLoadCallback) {\n this.mediationRewardedAdConfiguration = mediationRewardedAdConfiguration;\n this.mediationAdLoadCallback = mediationAdLoadCallback;\n }\n\n /** Loads the rewarded ad from the third-party ad network. */\n public void loadAd() {\n // All custom events have a server parameter named \"parameter\" that returns\n // back the parameter entered into the AdMob UI when defining the custom event.\n Log.i(\"RewardedCustomEvent\", \"Begin loading rewarded ad.\");\n String serverParameter = mediationRewardedAdConfiguration\n .getServerParameters()\n .getString(MediationConfiguration\n .CUSTOM_EVENT_SERVER_PARAMETER_FIELD);\n Log.d(\"RewardedCustomEvent\", \"Received server parameter.\");\n SampleAdRequest request = createSampleRequest(mediationRewardedAdConfiguration);\n sampleRewardedAd = new SampleRewardedAd(serverParameter);\n sampleRewardedAd.setListener(this);\n Log.i(\"RewardedCustomEvent\", \"Start fetching rewarded ad.\");\n sampleRewardedAd.loadAd(request);\n }\n\n public SampleAdRequest createSampleRequest(\n MediationAdConfiguration mediationAdConfiguration) {\n SampleAdRequest request = new SampleAdRequest();\n request.setTestMode(mediationAdConfiguration.isTestRequest());\n request.setKeywords(mediationAdConfiguration.getMediationExtras().keySet());\n return request;\n }\n}\n```\n\nDepending on whether the ad is successfully fetched or encounters an error, you\nwould call either\n[`onSuccess()`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/mediation/MediationAdLoadCallback#onSuccess(MediationAdT))\nor\n[`onFailure()`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/mediation/MediationAdLoadCallback#onFailure(com.google.android.gms.ads.AdError)).\n`onSuccess()` is called by passing in an instance of the class that implements\n`MediationRewardedAd`.\n\nTypically, these methods are implemented inside callbacks from the\nthird-party SDK your adapter implements. For this example, the Sample SDK\nhas a `SampleAdListener` with relevant callbacks: \n\nJava \n\n```java\n@Override\npublic void onRewardedAdLoaded() {\n rewardedAdCallback = mediationAdLoadCallback.onSuccess(this);\n}\n\n@Override\npublic void onRewardedAdFailedToLoad(SampleErrorCode errorCode) {\n mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));\n}\n```\n\n`MediationRewardedAd` requires implementing a `showAd()` method to display\nthe ad: \n\nJava \n\n```java\n@Override\npublic void showAd(Context context) {\n if (!(context instanceof Activity)) {\n rewardedAdCallback.onAdFailedToShow(\n SampleCustomEventError.createCustomEventNoActivityContextError());\n return;\n }\n Activity activity = (Activity) context;\n\n if (!sampleRewardedAd.isAdAvailable()) {\n rewardedAdCallback.onAdFailedToShow(\n SampleCustomEventError.createCustomEventAdNotAvailableError());\n return;\n }\n sampleRewardedAd.showAd(activity);\n}\n```\n\nForward mediation events to Google Mobile Ads SDK\n\nOnce `onSuccess()` is called, the returned `MediationRewardedAdCallback`\nobject can then be used by the adapter to forward presentation events from the\nthird-party SDK to Google Mobile Ads SDK. The\n`SampleRewardedCustomEventLoader` class extends the `SampleAdListener`\ninterface to forward callbacks from the sample ad network to the Google Mobile\nAds SDK.\n\nIt's important that your custom event forwards as many of these callbacks as\npossible, so that your app receives these equivalent events from the\nGoogle Mobile Ads SDK. Here's an example of using callbacks: \n\nJava \n\n```java\n@Override\npublic void onAdRewarded(final String rewardType, final int amount) {\n RewardItem rewardItem =\n new RewardItem() {\n @Override\n public String getType() {\n return rewardType;\n }\n\n @Override\n public int getAmount() {\n return amount;\n }\n };\n rewardedAdCallback.onUserEarnedReward(rewardItem);\n}\n\n@Override\npublic void onAdClicked() {\n rewardedAdCallback.reportAdClicked();\n}\n\n@Override\npublic void onAdFullScreen() {\n rewardedAdCallback.onAdOpened();\n rewardedAdCallback.onVideoStart();\n rewardedAdCallback.reportAdImpression();\n}\n\n@Override\npublic void onAdClosed() {\n rewardedAdCallback.onAdClosed();\n}\n\n@Override\npublic void onAdCompleted() {\n rewardedAdCallback.onVideoComplete();\n}\n```\n\nThis completes the custom events implementation for rewarded ads. The full\nexample is available on\n[GitHub](//github.com/googleads/googleads-mobile-android-mediation/tree/master/Example/customevent/src/main/java/com/google/ads/mediation/sample/customevent).\nYou can use it with an ad network that is already supported or modify it to\ndisplay custom event rewarded ads."]]