Rewarded Ad

1. Basic requirements

  • Add ADX Android SDK to your project.

  • Use the Ad Unit ID issued for Rewarded Ad.

  • Before requesting an ad, SDK initialization must be done first.

    • SDK initialization should be called only once when the app launches and ad requests should be made after SDK initialization is complete.

2. Implementation

  1. Instantiate the RewardedAd and add the RewardedAdListener.

  2. Call loadAd() to load the ad.

  3. After the ad is loaded and the onAdLoaded() callback is received, either call show() or check isLoaded() to see if an ad is available, then call show() to display the ad.

  4. When the ad is no longer needed, call the destroy() method of RewardedAd in onDestroy() to remove the ad.

public class RewardedAdActivity extends AppCompatActivity {
    private com.adxcorp.ads.RewardedAd rewardedAd;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        rewardedAd = new RewardedAd(this, "<REWARDED_AD_UNIT_ID>");
        rewardedAd.setRewardedAdListener(new RewardedAd.RewardedAdListener() {
            @Override
            public void onAdLoaded() {
            }

            @Override
            public void onAdError(int errorCode) {
            }

            @Override
            public void onAdClicked() {
            }

            @Override
            public void onAdImpression() {
            }

            @Override
            public void onAdClosed() {
            }

            @Override
            public void onAdRewarded() {
            }

            @Override
            public void onAdFailedToShow() {
            }
        });

        rewardedAd.loadAd();
    }
    
    void show() {
        if (rewardedAd != null && rewardedAd.isLoaded()) {
            rewardedAd.show();
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    
        if (rewardedAd != null) {
            rewardedAd.destroy();
            rewardedAd = null;
        }
    }
}

3. Callback

Set the RewardedAd’s RewardedAdListener to receive specific events. Implement it as needed.

rewardedAd.setRewardedAdListener(new RewardedAd.RewardedAdListener() {
    @Override
    public void onAdLoaded() {
    }
    
    @Override
    public void onAdError(int errorCode) {
    }
    
    @Override
    public void onAdClicked() {
    }
    
    @Override
    public void onAdImpression() {
    }
    
    @Override
    public void onAdClosed() {
    }
    
    @Override
    public void onAdRewarded() {
    }
    
    @Override
    public void onAdFailedToShow() {
    }
});

4. Ad Revenue (OnPaidEvent)

  • You can receive the estimated ad revenue while an ad impression occurs.

  • Manually set values during mediation setup and actual values may be mixed, so it is recommended to treat this as an estimate.

  • The currency unit of eCPM is USD.

  • As shown in the example below, use OnPaidEvent to check the estimated eCPM value.

  • You can link ad revenue data with your MMP. For details, please refer to the SDK integration guides below:

rewardedAd.setOnPaidEventListener(new OnPaidEventListener() {
    @Override
    public void onPaidEvent(double ecpm) {
        /// Firebase Analytics Example
        double revenue = ecpm / 1000;

        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        Bundle params = new Bundle();
        params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "AD(X)");
        params.putString(FirebaseAnalytics.Param.AD_FORMAT, "RewardedAd");
        params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, "ADX Rewarded Ad");
        params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
        params.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
        
        /// AppsFlyer Example
        double revenue = ecpm / 1000;

        Map<String, String> customParams = new HashMap<>();
        customParams.put(Scheme.AD_TYPE, "RewardedAd");
        customParams.put("ad_unit_name", "ADX Rewarded Ad");

        AppsFlyerAdRevenue.logAdRevenue(
              "AD(X)",
              MediationNetwork.customMediation,
              Currency.getInstance(Locale.US),
              revenue,
              customParams
        );
    }
});

5. SSV (Server-side verification) Settings

  • SSV settings are optional and can be configured only if needed.

  • SSV allows the reward event to trigger a server-to-server callback via the Callback URL.

  • The conditions for using SSV are as follows:

    • A Rewarded Video type with a registered Callback URL must be configured in the dashboard.

    • A reward event must occur after the user has fully watched the video.

    • If necessary, set the User ID or Custom Data information via the SDK before requesting an ad.

  • If the client sets the User ID and Custom Data, they will be included in the Callback URL request.

    • Example: https://callback_url?param=value&userid=<value>&customdata=<value>

    • SSV settings must be configured before the ad request to ensure the Callback URL includes the data.

  • Refer to the server-side SSV callback verification guide to verify the reward.

// Setting SSV (optional)
rewardedAd.setUserIdForSSV("<USER_ID>");
rewardedAd.setCustomDataForSSV("<CUSTOM_DATA>");

// Reqeust ad
rewardedAd.loadAd();

Last updated

Was this helpful?