loadAndTrackBannerAd

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

Sets up RevenueCat ad-event tracking for the given 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 the AdView) with a tracking listener 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 the 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.

Parameters

adView

The AdView to track and load.

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.

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.