> Documentation index: https://firebase.google.com/docs/analytics/llms.txt

Measuring your revenue sources helps you understand the lifetime value of your
users and grow your app business. This guide shows you how to set up ad revenue
measurement for your platform.

After you've set up ad revenue measurement, you can then do any of the
following:

- Analyze user actions that contribute to the ad revenue generated by your app.

- Run experiments using [Firebase A/B Testing](https://firebase.google.com/docs/ab-testing.md.txt) to find what
  features drive improvements in your app ad revenue, or personalize ad
  experiences using [Remote Config personalization](https://firebase.google.com/docs/remote-config/personalization.md.txt).

- Create
  [user audiences](https://support.google.com/analytics/answer/9267572)
  and [tailor user experiences](https://firebase.google.com/docs/remote-config/config-analytics.md.txt) using
  [Firebase Remote Config](https://firebase.google.com/docs/remote-config.md.txt) based on ad revenue levels.

## Before you begin

If you haven't already, make sure to complete the following tasks:

1. Set up your project and app as described in
   [Get Started with Analytics](https://firebase.google.com/docs/analytics/get-started.md.txt).

2. Make sure that you've [linked your Firebase project to a
   Google Analytics account.](https://support.google.com/firebase/answer/9289399#linkga)

3. Ensure that you've included in your app the Android SDK v17.6.0+ or
   the Apple platforms SDK v6.34.0+.

## Implementation

You can use Google Analytics to measure ad revenue generated from
displaying ads with monetization platforms, such as AdMob, AppLovin, and
ironSource. To measure ad revenue, you must log
[`ad_impression` events](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event.md.txt#public-static-final-string-ad_impression)
whenever your user sees an advertisement in your app. These events contain
details such as the ad platform, source, currency, and value.

### AdMob

If you are using the AdMob platform,
[link your AdMob app to Firebase and Analytics](http://support.google.com/firebase/answer/6387949)
to enable automatic measurement of ad revenue. The Firebase SDK for
Google Analytics automatically logs the `ad_impression` event whenever
your users see an ad impression.

### Other ad monetization platforms

Platforms such as AppLovin and ironSource provide impression-level revenue data
that you can then use to log Google Analytics
[`ad_impression`](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event.md.txt#public-static-final-string-ad_impression)
events.

The following sections show implementation examples for a few different ad
monetization platforms.

#### AppLovin

### Swift


**Note:** This Firebase product is not available on the watchOS target.

```swift
func didPayRevenue(_ impressionData: MAAd?) {
  if let impressionData = impressionData {
    Analytics.logEvent(
      AnalyticsEventAdImpression,
      parameters: [
        AnalyticsParameterAdPlatform: "AppLovin",
        AnalyticsParameterAdUnitName: impressionData.adUnitIdentifier,
        AnalyticsParameterAdFormat: impressionData.format,
        AnalyticsParameterValue: impressionData.revenue,
        AnalyticsParameterCurrency: "USD",  // All Applovin revenue is sent in USD
        AnalyticsParameterAdSource: impressionData.networkName,
      ])
  }
}
```

### Objective-C


**Note:** This Firebase product is not available on the watchOS target.

```objective-c
- (void)didPayRevenueForAd:(MAAd *)impressionData {
    [FIRAnalytics logEventWithName:kFIREventAdImpression
                    parameters: @{
                        kFIRParameterAdPlatform: @"AppLovin",
                        kFIRParameterAdSource: impressionData.networkName,
                        kFIRParameterAdFormat: impressionData.format,
                        kFIRParameterAdUnitName: impressionData.adUnitIdentifier,
                        kFIRParameterCurrency: @"USD", // All Applovin revenue is sent in USD
                        kFIRParameterValue: impressionData.revenue
                    }];
}
```

### Kotlin

```kotlin
override fun onAdRevenuePaid(impressionData: MaxAd?) {
    impressionData?.let {
        firebaseAnalytics = Firebase.analytics
        firebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION) {
            param(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin")
            param(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.adUnitId)
            param(FirebaseAnalytics.Param.AD_FORMAT, impressionData.format.label)
            param(FirebaseAnalytics.Param.AD_SOURCE, impressionData.networkName)
            param(FirebaseAnalytics.Param.VALUE, impressionData.revenue)
            param(FirebaseAnalytics.Param.CURRENCY, "USD") // All Applovin revenue is sent in USD
        }
    }
}
```

### Java

```java
@Override
public void onAdRevenuePaid(MaxAd impressionData) {

    double revenue = impressionData.getRevenue(); // In USD

    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    Bundle params = new Bundle();
    params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin");
    params.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.getNetworkName());
    params.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getFormat().getLabel());
    params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getAdUnitId());
    params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
    params.putString(FirebaseAnalytics.Param.CURRENCY, "USD"); // All Applovin revenue is sent in USD
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
}
```

### Unity

```c#
// Attach callbacks based on the ad format(s) you are using
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
private void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo impressionData)
{
double revenue = impressionData.Revenue;
var impressionParameters = new[] {
  new Firebase.Analytics.Parameter("ad_platform", "AppLovin"),
  new Firebase.Analytics.Parameter("ad_source", impressionData.NetworkName),
  new Firebase.Analytics.Parameter("ad_unit_name", impressionData.AdUnitIdentifier),
  new Firebase.Analytics.Parameter("ad_format", impressionData.AdFormat),
  new Firebase.Analytics.Parameter("value", revenue),
  new Firebase.Analytics.Parameter("currency", "USD"), // All AppLovin revenue is sent in USD
};
Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", impressionParameters);
}
```

#### ironSource

### Swift


**Note:** This Firebase product is not available on the watchOS target.

```swift
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 watchOS target.

```objective-c
- (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

```kotlin
override fun 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)
    firebaseAnalytics = Firebase.analytics
    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.adUnit)
        param(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.instanceName)
        param(FirebaseAnalytics.Param.CURRENCY, "USD")
        param(FirebaseAnalytics.Param.VALUE, impressionData.revenue)
    }
}
```

### Java

```java
@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);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    if (impressionData != null) {
        Bundle bundle = new Bundle();
        bundle.putString(FirebaseAnalytics.Param.AD_PLATFORM, "ironSource");
        bundle.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.getAdNetwork());
        bundle.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getAdUnit());
        bundle.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getInstanceName());
        bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
        bundle.putDouble(FirebaseAnalytics.Param.VALUE, impressionData.getRevenue());
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, bundle);
    }
}
```

### Unity

```c#
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.getInstanceName),
        new Firebase.Analytics.Parameter("ad_format", impressionData.getAdUnit),
        new Firebase.Analytics.Parameter("currency","USD"),
        new Firebase.Analytics.Parameter("value", impressionData.getRevenue)
      };
      Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", AdParameters);
  }
}
```

## Implementation considerations

To allow Google Ads to process your
[`ad_impression`](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/Firebase%0AAnalytics.Event#public-static-final-string-ad_impression), make sure to include
both the `currency` and the `value` parameters (described below). Both
parameters should be as accurate as possible to prevent over-valuing or under-
valuing users.

### Currency parameter

The `currency` parameter
([iOS+](https://firebase.google.com/docs/reference/swift/firebaseanalytics/api/reference/Constants.md.txt#/c:FIRParameterNames.h@kFIRParameterCurrency)
\| [Android](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param.md.txt#public-static-final-string-currency)
\| [Unity](https://firebase.google.com/docs/reference/unity/class/firebase/analytics/firebase-analytics.md.txt#class_firebase_1_1_analytics_1_1_firebase_analytics_1ae46e9b16a5145af4127990ee02cf2c74))
should be sent as a string in a three-letter
[ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes)
format (for example, `"USD"`). Some ad monetization platforms omit currency,
which may require you to hardcode the parameter.

### Value parameter

The `value` parameter
([iOS+](https://firebase.google.com/docs/reference/swift/firebaseanalytics/api/reference/Constants.md.txt#/c:FIRParameterNames.h@kFIRParameterValue)
\| [Android](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param.md.txt#public-static-final-string-value)
\| [Unity](https://firebase.google.com/docs/reference/unity/class/firebase/analytics/firebase-analytics.md.txt#class_firebase_1_1_analytics_1_1_firebase_analytics_1a9c83240ada0e8620e326bbbee48f6855))
should be sent using a dot as the decimal separator. You may need to transform
the values received from some platforms to fit the required format above. Some
platforms localize numerical formats and use commas as decimal separators. In
some cases, a platform may not send a value at all.

Additionally, the value should be a numerical type such as a double or long.
For example, `1000.01`, `0.001` and `1.00` are all
[valid](https://en.wikipedia.org/wiki/Decimal_separator)

## Validation

Google Analytics offers multiple features to validate your implementation
throughout the development cycle.

1. **DebugView**   

   When first testing your implementation, use
   [DebugView](https://firebase.google.com/docs/analytics/debugview.md.txt) to see your test `ad_impression` data
   in the console. When you select an `ad_impression` event, you can review the
   parameters that you're sending in the *Parameters* panel (in the right-side
   of the screen). This helps you confirm that the correct information is being
   processed.

2. **Realtime**   

   Once you have deployed your app, use the Google Analytics
   [Realtime report](https://support.google.com/analytics/answer/9271392)
   to confirm the implementation is working correctly. In the Realtime report,
   view the *Event count by Event name* card and select *ad_impression* to see
   the event and parameter details for the last 30 minutes.

3. **BigQuery**   

   Use [BigQuery export](https://firebase.google.com/docs/projects/bigquery-export.md.txt) to extract a
   sample of one or more days of `ad_impression` events. Use this extracted
   sample to look for issues, such as zero or not set values, and apply fixes
   to your code for any unhandled use cases.

## Next steps

Visit your Analytics dashboard in the Firebase console or in your linked
Analytics property in the Analytics console. Ad revenue is factored
into metrics, such as Average Revenue Per User (ARPU) and Lifetime
Value (LTV).