loadAndTrackAd

fun AdView.loadAndTrackAd(adRequest: AdRequest, placement: String? = null, adListener: AdListener? = null, onPaidEventListener: OnPaidEventListener? = null)

Sets up RevenueCat ad-event tracking for this AdView and loads the ad.

This works for both programmatically-created and XML-declared AdViews. When the AdView is declared in XML with app:adUnitId and app:adSize, those attributes are read automatically — just call this method after inflation.

Wraps the adListener (or the one already set on this AdView) with a TrackingAdListener that automatically tracks loaded, displayed, opened, and failed-to-load events. Revenue is tracked via OnPaidEventListener.

If an AdListener or OnPaidEventListener is already set on this AdView before calling this method, it will be preserved and called after the RevenueCat tracking calls. An explicit adListener parameter takes precedence over a previously set listener.

Important: Do not reassign AdView.adListener or AdView.onPaidEventListener after calling this method, as doing so will replace the tracking wrappers and break RevenueCat event tracking.

For Java callers, prefer RCAdMob.loadAndTrackBannerAd which provides the same functionality as a static method.

Parameters

adRequest

The AdRequest to use.

placement

A placement identifier (e.g., "home_screen_banner").

adListener

Optional AdListener to receive ad lifecycle events. If null and an AdListener is already set on this AdView, the existing listener will be used as the delegate. RevenueCat tracking is injected transparently before each delegate call.

onPaidEventListener

Optional OnPaidEventListener to receive paid events. RevenueCat revenue tracking is called first, then forwarded to this listener. If null and an OnPaidEventListener is already set on this AdView, the existing listener will be used as the delegate.