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.

  1. View ads in the app.

  2. 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

  1. Once the appropriate ad instance is created, set the MaxAdRevenueListener using the setRevenueListener method.

  2. Send data from the onAdRevenuePaid(MaxAd) method to the AppMetrica SDK: call the AppMetrica#reportExternalAdRevenue method, then pass the parameter sent to the MaxAd listener and the AppLovinSdk instance as arguments.

    val 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())));
    
    val 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())));
    
    val 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())));
    
    val 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())));
    
    val 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

  1. View ads in the app.

  2. 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

  1. For required ad types (Banner, Interstitial, and Rewarded), set the respective listener (BannerListener, InterstitalListener, or RewardedListener).

  2. Set up sending impressionData from the listener's onShow method to the AppMetrica SDK using the AppMetrica#reportExternalAdRevenue() method.

    Banner.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);
            //......
        }
        //......
    });
    
    Interstitial.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);
            //......
        }
    //.......
    });
    
    Rewarded.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

  1. View ads in the app.

  2. 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

  1. After creating an adView and before loading ads, call the setOnPaidEventListener method to register the OnPaidEventListener.

  2. In the OnPaidEventListener#onPaidEvent method, set up sending data to AppMetrica using the AppMetrica#reportExternalAdRevenue() method and passing the obtained AdValue and adView instances as arguments.

    val 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);
    
  1. In the InterstitialAdLoadCallback#onAdLoaded method of the ad load listener, set the OnPaidEventListener.

  2. In the OnPaidEventListener#onPaidEvent method, set up sending data to AppMetrica using the AppMetrica#reportExternalAdRevenue() method and passing the obtained AdValue and interstitialAd instances as arguments.

    InterstitialAd.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);
                //......
            });
            //......
        }
    });
    
  1. In the OnNativeAdLoadedListener#onNativeAdLoaded method of the ad load listener, set the OnPaidEventListener.

  2. In the OnPaidEventListener#onPaidEvent method, set up sending data to AppMetrica using the AppMetrica#reportExternalAdRevenue() method and passing the obtained AdValue and nativeAd instances as arguments.

    val 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();
    //......
    
  1. In the RewardedAdLoadCallback#onAdLoaded method of the ad load listener, set the OnPaidEventListener.

  2. In the OnPaidEventListener#onPaidEvent method, set up sending data to AppMetrica using the AppMetrica#reportExternalAdRevenue() method and passing the obtained AdValue and rewardedAd instances as arguments.

    //.....
    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);
                //........
            });
        }
    });
    //.....
    
  1. In the RewardedInterstitialAdLoadCallback#onAdLoaded method of the ad load listener, set the OnPaidEventListener.

  2. In the OnPaidEventListener#onPaidEvent method, set up sending data to AppMetrica using the AppMetrica#reportExternalAdRevenue() method and passing the obtained AdValue and rewardedInterstitialAd instances as arguments.

    RewardedInterstitialAd.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

  1. View ads in the app.

  2. 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

  1. Create an AdRevenue instance using the AdRevenue.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();
    
  2. Send the Ad Revenue instance using the AppMetrica.reportAdRevenue(AdRevenue adRevenue) method.

    AppMetrica.reportAdRevenue(adRevenue);
    

Step 3. Make sure that the ad revenue data is included in the reports

  1. View ads in the app.

  2. 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.

Contact support