Rewarded ads custom events
Stay organized with collections
Save and categorize content based on your preferences.
Prerequisites
Complete the custom events setup.
Request a rewarded ad
When the custom event line item is reached in the waterfall mediation chain,
the loadRewardedAd()
method is called on the class name you
provided when creating a custom
event. In this case,
that method is in SampleCustomEvent
, which then calls the loadRewardedAd()
method in SampleRewardedCustomEventLoader
.
To request a rewarded ad, create or modify a class that extends Adapter
to
implement loadRewardedAd()
. Additionally, create a new class to implement
MediationRewardedAd
.
In our custom event example,
SampleCustomEvent
extends the Adapter
class and then delegates to
SampleRewardedCustomEventLoader
.
Java
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
is responsible for the following tasks:
The optional parameter defined in the Ad Manager UI is
included in the ad configuration. The parameter can be accessed through
adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD)
.
This parameter is typically an ad unit identifier that an ad network SDK
requires when instantiating an ad object.
Java
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;
}
}
Depending on whether the ad is successfully fetched or encounters an error, you
would call either
onSuccess()
or
onFailure()
.
onSuccess()
is called by passing in an instance of the class that implements
MediationRewardedAd
.
Typically, these methods are implemented inside callbacks from the
third-party SDK your adapter implements. For this example, the Sample SDK
has a SampleAdListener
with relevant callbacks:
Java
@Override
public void onRewardedAdLoaded() {
rewardedAdCallback = mediationAdLoadCallback.onSuccess(this);
}
@Override
public void onRewardedAdFailedToLoad(SampleErrorCode errorCode) {
mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));
}
MediationRewardedAd
requires implementing a showAd()
method to display
the ad:
Java
@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);
}
Once onSuccess()
is called, the returned MediationRewardedAdCallback
object can then be used by the adapter to forward presentation events from the
third-party SDK to Next Gen Mobile Ads SDK. The
SampleRewardedCustomEventLoader
class extends the SampleAdListener
interface to forward callbacks from the sample ad network to the Google Mobile
Ads SDK.
It's important that your custom event forwards as many of these callbacks as
possible, so that your app receives these equivalent events from the
Next Gen Mobile Ads SDK. Here's an example of using callbacks:
Java
@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();
}
This completes the custom events implementation for rewarded ads. The full
example is available on
GitHub.
You can use it with an ad network that is already supported or modify it to
display custom event rewarded ads.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eTo request a rewarded ad via custom events, extend the \u003ccode\u003eAdapter\u003c/code\u003e class and implement the \u003ccode\u003eloadRewardedAd()\u003c/code\u003e method, delegating to a loader class that handles ad loading and event reporting.\u003c/p\u003e\n"],["\u003cp\u003eThe loader class, implementing \u003ccode\u003eMediationRewardedAd\u003c/code\u003e, is responsible for loading the ad, interacting with the third-party ad network, and forwarding ad events to the Google Mobile Ads SDK.\u003c/p\u003e\n"],["\u003cp\u003eAd configurations from the Ad Manager UI are accessible through \u003ccode\u003eadConfiguration.getServerParameters()\u003c/code\u003e, enabling retrieval of ad unit identifiers or other necessary parameters.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful ad loading, the \u003ccode\u003eonSuccess()\u003c/code\u003e method is called, providing a \u003ccode\u003eMediationRewardedAdCallback\u003c/code\u003e object to forward ad presentation events back to the Google Mobile Ads SDK.\u003c/p\u003e\n"],["\u003cp\u003eThe custom event adapter should forward all relevant ad events, like clicks, impressions, and rewards, to ensure the Google Mobile Ads SDK and your app receive comprehensive updates.\u003c/p\u003e\n"]]],["To request a rewarded ad, extend the `Adapter` class and implement `loadRewardedAd()`, delegating the task to a new class implementing `MediationRewardedAd`. This new class handles ad loading, implements `MediationRewardedAd`, and reports ad event callbacks. The `loadAd()` method in this class fetches the ad using a custom `SampleAdRequest`. Upon success or failure, call `onSuccess()` or `onFailure()`. Finally, implement `showAd()` and forward mediation events from the third-party SDK to the Google Mobile Ads SDK.\n"],null,["Prerequisites\n\nComplete the [custom events setup](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/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/early-access/nextgen/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 Next Gen 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/early-access/nextgen/reference/com/google/android/libraries/ads/mobile/sdk/mediation/MediationAdLoadCallback#onSuccess(MediationAdT))\nor\n[`onFailure()`](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/reference/com/google/android/libraries/ads/mobile/sdk/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 Next Gen 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 Next Gen 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\nNext Gen 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."]]