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 iOS app.
Prerequisites
- Reach out to your account manager to get allowlisted for this feature.
- Import the Google Mobile Ads SDK 7.54.0 or higher.
- Complete the steps in [Get started](/admob/ios/quick-start.
- Before you can receive any paid event, you need to implement at least one ad format:
Implementing paid event handler
Each ad format has a paidEventHandler
property of type
GADPaidEventHandler
.
During the lifecycle of an ad event, the Google Mobile Ads SDK monitors
impression events and invokes the handler with an earned value.
@import GoogleMobileAds; @import UIKit; @interface ViewController () @property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)requestRewardedAd { __weak ViewController *weakSelf = self; GADRequest *request = [GADRequest request]; [GADRewardedAd loadWithAdUnitID:@"ad unit ID" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; self.rewardedAd.paidEventHandler = ^void(GADAdValue *_Nonnull value){ ViewController *strongSelf = weakSelf; // TODO: Send the paid event information to your preferred analytics // server directly within this callback. NSLog(@"Paid event of value %@ in currency %@ of precision %@ occurred for ad unit %@ from ad network adapter %@).", value.value, value.currencyCode, (long)value.precision, strongSelf.rewardedAd.adUnitID, strongSelf.rewardedAd.responseInfo.adNetworkClassName); }; ]}; }
Integrating LTV API in App Attribution Partners (AAP)
For complete details on forwarding ads revenue data to analytics platforms, refer to the partner's guide:
Partner SDK |
---|
Adjust |
AppsFlyer |
Singular |
Implementation best practices
- Set the handler 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.
- Send the paid event information to your preferred analytics server
immediately at the time the
paidEventHandler
method is called. This ensures you don't accidentally drop any callbacks and avoids data discrepancies.
GADAdValue
GADAdValue
is a class that represents the value earned per paid event,
including the value's currency code and its precision type encoded as below.
GADAdValuePrecision | Description |
---|---|
GADAdValuePrecisionUnknown
|
An ad value that's unknown. This gets returned when LTV pingback is enabled but there isn't enough data available. |
GADAdValuePrecisionEstimated
|
An ad value estimated from aggregated data. |
GADAdValuePrecisionPublisherProvided
|
A publisher provided ad value, such as manual CPMs in a mediation group. |
GADAdValuePrecisionPrecise
|
The precise value paid for this ad. |