Impression-level ad revenue

Stay organized with collections Save and categorize content based on your preferences.

When an impression occurs, the Google Mobile Ads SDK provides ad revenue data associated with that impression. You can use the data to calculate a user's lifetime value, or forward the data downstream to other relevant systems.

This guide is intended to help you implement the impression-level ad revenue data capture in your Unity project.

Prerequisites

Implementing a paid event handler

Each ad format has an OnPaidEvent event. During the lifecycle of an ad event, the Google Mobile Ads SDK monitors impression events and invokes the handler with an earned value.

The code below demonstrates how to handle paid events for a rewarded ad:


RewardedAd rewardedAd;

private void RequestRewardedAd()
{
   rewardedAd = new RewardedAd("ad unit ID");
   
   rewardedAd.OnPaidEvent += this.HandleAdPaidEvent;
   
   AdRequest adRequest = new AdRequest.Builder().Build();
   rewardedAd.LoadAd(adRequest);
}


public void HandleAdPaidEvent(object sender, AdValueEventArgs args)
{
    // TODO: Send the impression-level ad revenue information to your
    // preferred analytics server directly within this callback.

    AdValue adValue = args.AdValue;
    long valueMicros = adValue.Value;
    string currencyCode = adValue.CurrencyCode;
    PrecisionType precision = adValue.Precision;

    ResponseInfo responseInfo = rewardedAd.GetResponseInfo();
    string responseId = responseInfo.GetResponseId();

    AdapterResponseInfo loadedAdapterResponseInfo = responseInfo.GetLoadedAdapterResponseInfo();
    string adSourceId = loadedAdapterResponseInfo.AdSourceId;
    string adSourceInstanceId = loadedAdapterResponseInfo.AdSourceInstanceId;
    string adSourceInstanceName = loadedAdapterResponseInfo.AdSourceInstanceName;
    string adSourceName = loadedAdapterResponseInfo.AdSourceName;
    string adapterClassName = loadedAdapterResponseInfo.AdapterClassName;
    long latencyMillis = loadedAdapterResponseInfo.LatencyMillis;
    Dictionary<string, string> credentials = loadedAdapterResponseInfo.AdUnitMapping;

    Dictionary<string, string> extras = responseInfo.GetResponseExtras();
    string mediationGroupName = extras["mediation_group_name"];
    string mediationABTestName = extras["mediation_ab_test_name"];
    string mediationABTestVariant = extras["mediation_ab_test_variant"];
}

For more information on the winning ad source, see retrieving Information about the ad response.

Integrating with App Attribution Partners (AAP)

For complete details on forwarding ad revenue data to analytics platforms, refer to the partner's guide:

Partner SDK
Adjust
AppsFlyer
Singular
Tenjin

Implementation best practices

  • Set the OnPaidEvent event immediately once you create or get access to the ad object, and definitely before showing the ad. This ensures that you don't miss any callbacks.
  • Send the impression-level ad revenue information to your preferred analytics server immediately in your OnPaidEvent handler. This ensures that you don't accidentally drop any callbacks and avoids data discrepancies.

AdValue

AdValue is a class that represents the monetary value earned for an ad, including the value's currency code and its precision type encoded as below.

AdValue.PrecisionType Description
Unknown An ad value that's unknown. This gets returned when LTV pingback is enabled but there isn't enough data available.
Estimated An ad value estimated from aggregated data.
PublisherProvided A publisher provided ad value, such as manual CPMs in a mediation group.
Precise The precise value of this ad.

In case of mediation, AdMob tries to provide an ESTIMATEDvalue for ad sources that are optimized. For non-optimized ad sources, or in cases where there aren't enough aggregated data to report a meaningful estimation, the PUBLISHER_PROVIDED value is returned.