Life Time Value (LTV)

When an impression occurs, the Google Mobile Ads SDK calls the paid event handler with its associated revenue data. By implementing this handler, you can use the data to calculate a user's life time value, or forward the data downstream to other relevant systems.

This guide is intended to help you implement LTV data capture in your Android app.

Prerequisites

Implementing paid event handler

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

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

import com.google.android.gms.ads.rewarded.RewardedAd;

public class MainActivity extends Activity {
  private RewardedAd mRewardedAd;
  private final String TAG = "MainActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    AdRequest adRequest = new AdRequest.Builder().build();

    RewardedAd.load(this, "ad unit ID",
      adRequest, new RewardedAdLoadCallback(){
        @Override
        public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
          mRewardedAd = rewardedAd;
          // Set paid event listener
          mRewardedAd.setOnPaidEventListener(new OnPaidEventListener() {
            @Override
            public void onPaidEvent(AdValue adValue) {
              // TODO: Send the paid event information to your preferred
              // analytics server directly within this callback.
              Log.d("MyApp", String.format(
                "Paid event of value %d microcents in currency %s of precision %s%n occurred for ad unit %s from ad network %s.",
                adValue.getValueMicros(),
                adValue.getCurrencyCode(),
                adValue.getPrecisionType(),
                mRewardedAd.getAdUnitId(),
                mRewardedAd.getResponseInfo().getMediationAdapterClassName()));
            }
          });
        }
    });
  }
}

Implementation best practices

  1. Set the listener immediately once you create or get access to the ad object, and definitely before showing the ad. This ensures you don't miss any paid event callbacks.
  2. Send the paid event information to your preferred analytics server immediately at the time the onPaidEvent() method is called. This ensures you don't accidentally drop any callbacks and avoids data discrepancies.

AdValue

AdValue is a class that represents the value earned per paid event, including the value's currency code and its precision type encoded as below.

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.
PUBLISHER_PROVIDED A publisher provided ad value, such as manual CPMs in a mediation group.
PRECISE The precise value paid for this ad.