Catch up on everthing we announced at this year's Firebase Summit. Learn more

Measure ad revenue

You can use Analytics to measure ad revenue generated from displaying ads with monetization platforms, such as AdMob, MoPub, and ironSource. Measuring your revenue sources helps you understand the lifetime value of your users and grow your app business.

Before you begin

Make sure that you’ve set up your project as described in Get Started with Analytics. Ad revenue measurement requires you to link your Firebase project to an Analytics account and to have the Android SDK v17.6.0 or iOS v6.34.0 and up in your app.

Implementation

To measure ad revenue, you must log ad_impression events, which contain details such as the ad platform, source, currency, and value. This guide shows you how to set up ad revenue measurement, depending on the platform you are using.

AdMob

If you are using the AdMob platform, link your AdMob app to Firebase and Analytics to enable automatic measurement of ad revenue. The Analytics SDK automatically logs the ad_impression event whenever your users see an ad impression.

Other ad monetization platforms

If you are using another ad monetization platform, such as MoPub or ironSource, you can track impression-level revenue data by manually logging ad_impression events, as shown in the examples below.

MoPub

Swift

Note: This Firebase product is not available on the macOS target.
func mopubAd(_ ad: MPMoPubAd, didTrackImpressionWith impressionData: MPImpressionData?) {
  if let impressionData = impressionData {
    Analytics.logEvent(
      AnalyticsEventAdImpression,
      parameters: [
        AnalyticsParameterAdPlatform: "MoPub",
        AnalyticsParameterAdUnitName: impressionData.adUnitName,
        AnalyticsParameterAdFormat: impressionData.adUnitFormat,
        AnalyticsParameterValue: impressionData.publisherRevenue,
        AnalyticsParameterCurrency: impressionData.currency,
        AnalyticsParameterAdSource: impressionData.networkName,
        "precision": impressionData.precision,
      ])
  }
}

Objective-C

Note: This Firebase product is not available on the macOS target.
- (void)mopubAd:(id)ad didTrackImpressionWithImpressionData:(MPImpressionData * _Nullable)impressionData
{

// Feed impression data into internal tools or send to third-party analytics
if (impressionData != nil)
{
    [FIRAnalytics logEventWithName:kFIREventAdImpression
                parameters:@{
                             kFIRParameterAdPlatform:@"MoPub",
                             kFIRParameterAdUnitName:impressionData.adUnitName,
                             kFIRParameterAdFormat:impressionData.adunitFormat,
                             kFIRParameterValue:impressionData.publisherRevenue,
                             kFIRParameterCurrency:impressionData.currency,
                             kFIRParameterAdSource:impressionData.networkName,
                             @"precision":impressionData.precision
                             }];
}

}

Kotlin+KTX

@Override
public void onImpression(@NonNull final String adUnitId, @Nullable final ImpressionData impressionData) {

  if (impressionData != null) {
    // Feed impression data into internal tools or send to third-party analytics
    FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(context);

    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION) {
      param(FirebaseAnalytics.Param.AD_PLATFORM, "MoPub")
      param(FirebaseAnalytics.Param.AD_SOURCE, impressionData.network_name)
      param(FirebaseAnalytics.Param.AD_FORMAT, impressionData.adunit_format)
      param(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.adunit_name)
      param(FirebaseAnalytics.Param.VALUE, impressionData.publisher_revenue)
      param(FirebaseAnalytics.Param.CURRENCY, impressionData.currency)
      param("precision", impressionData.precision)
    }
  }

}

Java

@Override
public void onImpression(@NonNull final String adUnitId, @Nullable final ImpressionData impressionData) {

  if (impressionData != null) {
    // Feed impression data into internal tools or send to third-party analytics
    FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(context);

    Bundle params = new Bundle();
    params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "MoPub");
    params.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.network_name);
    params.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.adunit_format);
    params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.adunit_name);
    params.putDouble(FirebaseAnalytics.Param.VALUE, impressionData.publisher_revenue);
    params.putString(FirebaseAnalytics.Param.CURRENCY, impressionData.currency);
    params.putString("precision", impressionData.precision);
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
  }

}

Unity

// REGISTER TO LISTEN TO THE EVENT FROM MOPUB SDK
private void OnEnable() {
    MoPubManager.OnImpressionTrackedEvent += OnImpressionTrackedEvent;
}

private void OnImpressionTrackedEvent(string adUnitId, MoPub.ImpressionData impressionData)
{
    // Feed impression data into internal tools or send to third-party analytics
    var myImpressionObject = JsonUtility.FromJson(impressionData.JsonRepresentation);
    var impressionParameters = new[] {
        new Firebase.Analytics.Parameter("ad_platform", "MoPub"),
        new Firebase.Analytics.Parameter("ad_source", myImpressionObject.network_name),
        new Firebase.Analytics.Parameter("ad_unit_name", myImpressionObject.adunit_name),
        new Firebase.Analytics.Parameter("ad_format", myImpressionObject.adunit_format),
        new Firebase.Analytics.Parameter("value", myImpressionObject.publisher_revenue),
        new Firebase.Analytics.Parameter("currency", myImpressionObject.currency),
        new Firebase.Analytics.Parameter("precision", myImpressionObject.precision)
    };
    Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", impressionParameters);
}

ironSource

Swift

Note: This Firebase product is not available on the macOS target.
func impressionDataDidSucceed(_ impressionData: ISImpressionData!) {
  Analytics.logEvent(
    AnalyticsEventAdImpression,
    parameters: [
      AnalyticsParameterAdPlatform: "ironSource",
      AnalyticsParameterAdSource: impressionData.ad_network ?? "No ad_network",
      AnalyticsParameterAdFormat: impressionData.ad_unit ?? "No ad_unit",
      AnalyticsParameterAdUnitName: impressionData.instance_name ?? "No instance_name",
      AnalyticsParameterCurrency: "USD",
      AnalyticsParameterValue: impressionData.revenue ?? 0,
    ])
}

Objective-C

Note: This Firebase product is not available on the macOS target.
- (void)impressionDataDidSucceed:(ISImpressionData *)impressionData {

[FIRAnalytics logEventWithName:kFIREventAdImpression
                    parameters:@{
                        kFIRParameterAdPlatform:@"ironSource",
                        kFIRParameterAdSource:impressionData.ad_network,
                        kFIRParameterAdFormat:impressionData.ad_unit,
                        kFIRParameterAdUnitName:impressionData.instance_name,
                        kFIRParameterCurrency:@"USD",
                        kFIRParameterValue:impressionData.revenue
                    }];

}

Kotlin+KTX

@Override
 public void onImpressionSuccess(ImpressionData impressionData) {
     // The onImpressionSuccess will be reported when the rewarded video and interstitial ad is opened.
     // For banners, the impression is reported on load success. Log.d(TAG, "onImpressionSuccess" + impressionData);
     if (impressionData != null) {
         firebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION) {
         param(FirebaseAnalytics.Param.AD_PLATFORM, "ironSource")
         param(FirebaseAnalytics.Param.AD_SOURCE, impressionData.adNetwork())
         param(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getAdUnit())
         param(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getAdUnit())
         param(FirebaseAnalytics.Param.CURRENCY, "USD")
         param(FirebaseAnalytics.Param.VALUE, impressionData.getRevenue())
     }
 }

Java

// Invoked when the ad was displayed successfully and the impression data was recorded
 @Override
 public void onImpressionSuccess(ImpressionData impressionData) {
     // The onImpressionSuccess will be reported when the rewarded video and interstitial ad is opened.
     // For banners, the impression is reported on load success. Log.d(TAG, "onImpressionSuccess" + impressionData);
     if (impressionData != null) {
         Bundle bundle = new Bundle();
         bundle.putString(FirebaseAnalytics.Param.AD_PLATFORM, "ironSource");
         bundle.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.adNetwork());
         bundle.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getAdUnit());
         bundle.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getAdUnit());
         bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
         bundle.putDouble(FirebaseAnalytics.Param.VALUE, impressionData.getRevenue());
         mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, bundle);
     }
 }

Unity

private void ImpressionSuccessEvent(IronSourceImpressionData impressionData) {

    if (impressionData != null) {
        Firebase.Analytics.Parameter[] AdParameters = {
          new Firebase.Analytics.Parameter("ad_platform", "ironSource"),
          new Firebase.Analytics.Parameter("ad_source", impressionData.adNetwork),
          new Firebase.Analytics.Parameter("ad_unit_name", impressionData.getAdUnit),
          new Firebase.Analytics.Parameter("ad_format", impressionData.getInstanceName),
          new Firebase.Analytics.Parameter("currency","USD"),
          new Firebase.Analytics.Parameter("value", impressionData.getRevenue)
        };
        Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", AdParameters);
    }
}

Next steps

Visit your Analytics dashboard in the Firebase console and in your linked Analytics property in the Analytics console. Ad revenue will be factored into metrics such as ARPU and LTV.