Sending ad revenue data on Android
AppMetrica offers several options for sending ad revenue data from ad monetization and mediation services:
- Automatic integration. Supported for ironSource.
- Simplified integration. Supported for:
- AppLovin MAX
- Digital Turbine
- Google AdMob
- Manual integration and setup.
Automatic integration
Data is transmitted automatically. You can disable automatic collection of data where appropriate.
ironSource
Step 1. Set up sending ad revenue data
IronSource supports automatic collection of ad revenue data. The process is managed by the io.appmetrica.analytics:analytics-ad-revenue-ironsource-v7
module.
Activation example:
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
AppMetrica.activate(context, config);
Step 2. Make sure that the ad revenue data is included in the reports.
-
View ads in the app.
-
Make sure that the Revenue report shows the same number of ad revenue events as the number of ad views.
Disabling automatic collection of ad revenue data
To disable automatic collection of ad revenue data, exclude the following module from the list of dependencies:
configurations.configureEach {
exclude(group = "io.appmetrica.analytics", module = "io.appmetrica.analytics:analytics-ad-revenue-ironsource-v7")
}
configurations.configureEach {
exclude group: 'io.appmetrica.analytics', module: 'io.appmetrica.analytics:analytics-ad-revenue-ironsource-v7'
}
Simplified integration
Use the simplified API for sending data. It supports popular ad monetization and mediation services.
Applovin MAX
Step 1. Make sure that the SDK is activated
Activation example:
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
AppMetrica.activate(context, config);
Step 2. Set up sending ad revenue data
-
Once the appropriate ad instance is created, set the
MaxAdRevenueListener
using thesetRevenueListener
method. -
Send data from the
onAdRevenuePaid(MaxAd)
method to the AppMetrica SDK: call theAppMetrica#reportExternalAdRevenue
method, then pass the parameter sent to theMaxAd
listener and theAppLovinSdk
instance as arguments.App Open AdsBannerInterstitialNativeRewardedKotlinJavaval maxAppOpenAdView = MaxAppOpenAd( "ad-unit-ID", applicationContext) maxAppOpenAdView.setRevenueListener { AppMetrica.reportExternalAdRevenue(it, AppLovinSdk.getInstance(applicationContext)) }
MaxAppOpenAd maxAppOpenAd = new MaxAppOpenAd( "ad-unit-ID", getApplicationContext()); maxAppOpenAd.setRevenueListener(maxAdRevenue -> AppMetrica.reportExternalAdRevenue(maxAdRevenue, AppLovinSdk.getInstance(getApplicationContext())));
KotlinJavaval maxAdView = MaxAdView("ad-unit-ID", applicationContext) maxAdView.setRevenueListener { AppMetrica.reportExternalAdRevenue(it, AppLovinSdk.getInstance(applicationContext)) }
MaxAdView maxAdView = new MaxAdView("ad-unit-ID", getApplicationContext()); maxAdView.setRevenueListener(maxAdRevenue -> AppMetrica.reportExternalAdRevenue(maxAdRevenue, AppLovinSdk.getInstance(getApplicationContext())));
KotlinJavaval maxInterstitialAd = MaxInterstitialAd("ad-unit-ID", applicationContext) maxInterstitialAd.setRevenueListener { AppMetrica.reportExternalAdRevenue(it, AppLovinSdk.getInstance(applicationContext)) }
MaxInterstitialAd maxInterstitialAd = new MaxInterstitialAd("ad-unit-ID", getApplicationContext()); maxInterstitialAd.setRevenueListener(maxAdRevenue -> AppMetrica.reportExternalAdRevenue(maxAdRevenue, AppLovinSdk.getInstance(getApplicationContext())));
KotlinJavaval nativeAdLoader = MaxNativeAdLoader("ad-unit-ID", applicationContext) nativeAdLoader.setRevenueListener { AppMetrica.reportExternalAdRevenue(it, AppLovinSdk.getInstance(applicationContext)) }
MaxNativeAdLoader maxNativeAdLoader = new MaxNativeAdLoader("ad-unit-ID", getApplicationContext()); maxNativeAdLoader.setRevenueListener(maxAdRevenue -> AppMetrica.reportExternalAdRevenue(maxAdRevenue, AppLovinSdk.getInstance(getApplicationContext())));
KotlinJavaval maxRewardedAd = MaxRewardedAd.getInstance("ad-unit-ID", applicationContext); maxRewardedAd.setRevenueListener { AppMetrica.reportExternalAdRevenue(it, AppLovinSdk.getInstance(applicationContext)) }
MaxRewardedAd maxRewardedAd = MaxRewardedAd.getInstance("ad-unit-ID", getApplicationContext()); maxRewardedAd.setRevenueListener(maxAdRevenue -> AppMetrica.reportExternalAdRevenue(maxAdRevenue, AppLovinSdk.getInstance(getApplicationContext())));
Step 3. Make sure that the ad revenue data is included in the reports
-
View ads in the app.
-
Make sure that the Revenue report shows the same number of ad revenue events as the number of ad views.
Digital Turbine
Step 1. Make sure that the SDK is activated
Activation example:
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
AppMetrica.activate(context, config);
Step 2. Set up sending ad revenue data
-
For required ad types (
Banner
,Interstitial
, andRewarded
), set the respective listener (BannerListener
,InterstitalListener
, orRewardedListener
). -
Set up sending
impressionData
from the listener'sonShow
method to the AppMetrica SDK using theAppMetrica#reportExternalAdRevenue()
method.BannerInterstitialRewardedKotlinJavaBanner.setBannerListener(object:BannerListener { //.... override fun onShow(placementId: String, impressionData: ImpressionData) { AppMetrica.reportAdRevenue(impressionData) //..... } //.... })
Banner.setBannerListener(new BannerListener() { //...... @Override public void onShow(@NonNull String s, @NonNull ImpressionData impressionData) { AppMetrica.reportExternalAttribution(impressionData); //...... } //...... });
KotlinJavaInterstitial.setInterstitialListener(object:InterstitialListener { //.... override fun onShow(placementId: String, impressionData: ImpressionData) { AppMetrica.reportExternalAdRevenue(impressionData) //.... } //.... })
Interstitial.setInterstitialListener(new InterstitialListener() { //...... @Override public void onShow(@NonNull String s, @NonNull ImpressionData impressionData) { AppMetrica.reportExternalAdRevenue(impressionData); //...... } //....... });
KotlinJavaRewarded.setRewardedListener(object:RewardedListener { override fun onShow(placementId: String, impressionData: ImpressionData) { AppMetrica.reportExternalAdRevenue(impressionData); //....... } })
Rewarded.setRewardedListener(new RewardedListener() { //..... @Override public void onShow(@NonNull String s, @NonNull ImpressionData impressionData) { AppMetrica.reportExternalAdRevenue(impressionData); //...... } //..... });
Step 3. Make sure that the ad revenue data is included in the reports
-
View ads in the app.
-
Make sure that the Revenue report shows the same number of ad revenue events as the number of ad views.
Google AdMob
Step 1. Make sure that the SDK is activated
Activation example:
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
AppMetrica.activate(context, config);
Step 2. Set up sending ad revenue data
-
After creating an
adView
and before loading ads, call thesetOnPaidEventListener
method to register theOnPaidEventListener
. -
In the
OnPaidEventListener#onPaidEvent
method, set up sending data to AppMetrica using theAppMetrica#reportExternalAdRevenue()
method and passing the obtainedAdValue
andadView
instances as arguments.KotlinJavaval adMobAdView = AdView(this) //........ adMobAdView.setOnPaidEventListener { AppMetrica.reportExternalAdRevenue(it, adMobAdView) //....... } //........ adMobAdView.loadAd(adRequest)
AdView adMobAdView = new AdView(this); //...... adMobAdView.setOnPaidEventListener(adValue -> { AppMetrica.reportExternalAdRevenue(adValue, adMobAdView); //....... }); //....... adMobAdView.loadAd(adRequest);
-
In the
InterstitialAdLoadCallback#onAdLoaded
method of the ad load listener, set theOnPaidEventListener
. -
In the
OnPaidEventListener#onPaidEvent
method, set up sending data to AppMetrica using theAppMetrica#reportExternalAdRevenue()
method and passing the obtainedAdValue
andinterstitialAd
instances as arguments.KotlinJavaInterstitialAd.load(this, "add-unit-ID", adRequest, object : InterstitialAdLoadCallback() { //...... override fun onAdLoaded(adMobInterstitalAd: InterstitialAd) { super.onAdLoaded(adMobInterstitalAd) //....... adMobInterstitalAd.setOnPaidEventListener { adValue -> AppMetrica.reportExternalAdRevenue(adValue, adMobInterstitalAd) } //....... } })
InterstitialAd.load(this, "ad-unit-ID", adRequest, new InterstitialAdLoadCallback() { //........ @Override public void onAdLoaded(@NonNull InterstitialAd adMobInterstitialAd) { super.onAdLoaded(adMobInterstitialAd); adMobInterstitialAd.setOnPaidEventListener(adValue -> { AppMetrica.reportExternalAdRevenue(adValue, adMobInterstitialAd); //...... }); //...... } });
-
In the
OnNativeAdLoadedListener#onNativeAdLoaded
method of the ad load listener, set theOnPaidEventListener
. -
In the
OnPaidEventListener#onPaidEvent
method, set up sending data to AppMetrica using theAppMetrica#reportExternalAdRevenue()
method and passing the obtainedAdValue
andnativeAd
instances as arguments.KotlinJavaval adMobAdLoader = AdLoader.Builder(this, "add-unit-ID") .forNativeAd { adMobNativeAd -> adMobNativeAd.setOnPaidEventListener { adValue -> AppMetrica.reportExternalAdRevenue(adValue, adMobNativeAd) } } //....... .build() //.....
//..... AdLoader admobLoader = new AdLoader.Builder(this, "ad-unit-ID") .forNativeAd(adMobNativeAd -> { adMobNativeAd.setOnPaidEventListener(adValue -> { AppMetrica.reportExternalAdRevenue(adValue, adMobNativeAd); //...... }); //...... }) .build(); //......
-
In the
RewardedAdLoadCallback#onAdLoaded
method of the ad load listener, set theOnPaidEventListener
. -
In the
OnPaidEventListener#onPaidEvent
method, set up sending data to AppMetrica using theAppMetrica#reportExternalAdRevenue()
method and passing the obtainedAdValue
andrewardedAd
instances as arguments.KotlinJava//..... RewardedAd.load(this, "ad-unit-ID", adRequest, object : RewardedAdLoadCallback() { override fun onAdLoaded(rewardedAd: RewardedAd) { super.onAdLoaded(rewardedAd) //..... rewardedAd.onPaidEventListener = OnPaidEventListener { adValue -> AppMetrica.reportExternalAdRevenue( adValue, rewardedAd ) } } }) //.....
//..... RewardedAd.load(this, "ad-unit-ID", adRequest, new RewardedAdLoadCallback() { @Override public void onAdLoaded(@NonNull RewardedAd rewardedAd) { super.onAdLoaded(rewardedAd); //..... rewardedAd.setOnPaidEventListener(adValue -> { AppMetrica.reportExternalAdRevenue(adValue, rewardedAd); //........ }); } }); //.....
-
In the
RewardedInterstitialAdLoadCallback#onAdLoaded
method of the ad load listener, set theOnPaidEventListener
. -
In the
OnPaidEventListener#onPaidEvent
method, set up sending data to AppMetrica using theAppMetrica#reportExternalAdRevenue()
method and passing the obtainedAdValue
andrewardedInterstitialAd
instances as arguments.KotlinJavaRewardedInterstitialAd.load( this, "ad-unit-ID", adRequest, object : RewardedInterstitialAdLoadCallback() { override fun onAdLoaded(rewardedInterstitialAd: RewardedInterstitialAd) { super.onAdLoaded(rewardedInterstitialAd) rewardedInterstitialAd.onPaidEventListener = OnPaidEventListener { adValue -> AppMetrica.reportExternalAdRevenue( adValue, rewardedInterstitialAd ) //...... } //...... } })
RewardedInterstitialAd.load(this, "ad-unit-ID", adRequest, new RewardedInterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull RewardedInterstitialAd rewardedInterstitialAd) { super.onAdLoaded(rewardedInterstitialAd); rewardedInterstitialAd.setOnPaidEventListener(adValue -> { AppMetrica.reportExternalAdRevenue(adValue, rewardedInterstitialAd); //...... }); //...... } });
Step 3. Make sure that the ad revenue data is included in the reports
-
View ads in the app.
-
Make sure that the Revenue report shows the same number of ad revenue events as the number of ad views.
Manual integration and setup
Use this option to manually set up the data transfer from any other ad monetization service that provides impression-level revenue data.
Step 1. Make sure that the SDK is activated
Activation example:
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
AppMetrica.activate(context, config);
Step 2. Set up sending ad revenue data
-
Create an
AdRevenue
instance using theAdRevenue.Builder
.Map<String, String> adRevenuePayload = new HashMap<>(); adRevenuePayload.put("payload_key_1", "payload_value_1"); adRevenuePayload.put("payload_key_2", "payload_value_2"); AdRevenue adRevenue = AdRevenue.newBuilder(new BigDecimal("100.100"), Currency.getInstance("USD")) .withAdNetwork("ad_network") .withAdPlacementId("ad_placement_id") .withAdPlacementName("ad_placement_name") .withAdType(AdType.NATIVE) .withAdUnitId("ad_unit_id") .withAdUnitName("ad_unit_name") .withPrecision("some precision") .withPayload(adRevenuePayload) .build();
-
Send the
Ad Revenue
instance using theAppMetrica.reportAdRevenue(AdRevenue adRevenue)
method.AppMetrica.reportAdRevenue(adRevenue);
Step 3. Make sure that the ad revenue data is included in the reports
-
View ads in the app.
-
Make sure that the Revenue report shows the same number of ad revenue events as the number of ad views.
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.