AdMob SDK Integration (Android)
Quick setup for AdMob ad monetization on Android with RevenueCat
This feature is currently in beta. To enable it, visit the Ads page in your RevenueCat dashboard to opt in.
The RevenueCat AdMob integration for Android provides helper methods that wrap standard AdMob ad loading calls. Use loadAndTrack methods to automatically track all ad events.
Installation
Add the AdMob integration module to your app's build.gradle:
dependencies {
implementation 'com.revenuecat.purchases:purchases-admob:8.0.0+'
}
This module depends on the RevenueCat Purchases SDK and Google Mobile Ads SDK.
Quick Start
1. Import the Module
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.admob.* // AdMob helper extensions
2. Access the AdTracker
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class) // Ad APIs are experimental
val adTracker = Purchases.sharedInstance.adTracker
3. Replace Load Calls with loadAndTrack
Replace standard AdMob load calls with loadAndTrack methods:
// Before
RewardedAd.load(context, adUnitId, adRequest, callback)
// After
adTracker.loadAndTrackRewardedAd(
context = context,
adUnitId = adUnitId,
adRequest = adRequest,
placement = "bonus_coins",
loadCallback = callback
)
Supported Ad Formats
The integration supports all major AdMob ad formats:
| Format | Method | Ad Type |
|---|---|---|
| Banner | loadAndTrackBannerAd() | AdView |
| Interstitial | loadAndTrackInterstitialAd() | InterstitialAd |
| Rewarded | loadAndTrackRewardedAd() | RewardedAd |
| Rewarded Interstitial | loadAndTrackRewardedInterstitialAd() | RewardedInterstitialAd |
| App Open | loadAndTrackAppOpenAd() | AppOpenAd |
| Native | loadAndTrack() on AdView | Native via AdLoader |
Implementation Examples
Banner Ads
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
@Composable
fun BannerAdView() {
AndroidView(
factory = { context ->
AdView(context).apply {
adUnitId = "ca-app-pub-3940256099942544/9214589741"
setAdSize(AdSize.BANNER)
// Load with tracking
Purchases.sharedInstance.adTracker.loadAndTrackBannerAd(
adView = this,
adRequest = AdRequest.Builder().build(),
placement = "home_banner"
)
}
}
)
}
Interstitial Ads
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
class MyActivity : AppCompatActivity() {
private var interstitialAd: InterstitialAd? = null
fun loadInterstitial() {
Purchases.sharedInstance.adTracker.loadAndTrackInterstitialAd(
context = this,
adUnitId = "ca-app-pub-3940256099942544/1033173712",
adRequest = AdRequest.Builder().build(),
placement = "level_complete",
loadCallback = object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) {
interstitialAd = ad
}
override fun onAdFailedToLoad(error: LoadAdError) {
interstitialAd = null
}
}
)
}
fun showInterstitial() {
interstitialAd?.show(this)
}
}
Rewarded Ads
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
fun loadRewardedAd(context: Context) {
Purchases.sharedInstance.adTracker.loadAndTrackRewardedAd(
context = context,
adUnitId = "ca-app-pub-3940256099942544/5224354917",
adRequest = AdRequest.Builder().build(),
placement = "bonus_coins",
loadCallback = object : RewardedAdLoadCallback() {
override fun onAdLoaded(ad: RewardedAd) {
// Ad loaded successfully
ad.show(activity) { reward ->
// User earned reward
grantCoins(reward.amount)
}
}
override fun onAdFailedToLoad(error: LoadAdError) {
// Handle error
}
}
)
}
Rewarded Interstitial Ads
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
fun loadRewardedInterstitialAd(context: Context) {
Purchases.sharedInstance.adTracker.loadAndTrackRewardedInterstitialAd(
context = context,
adUnitId = "ca-app-pub-3940256099942544/5354046379",
adRequest = AdRequest.Builder().build(),
placement = "between_levels",
loadCallback = object : RewardedInterstitialAdLoadCallback() {
override fun onAdLoaded(ad: RewardedInterstitialAd) {
ad.show(activity) { reward ->
// User earned reward
}
}
override fun onAdFailedToLoad(error: LoadAdError) {
// Handle error
}
}
)
}
App Open Ads
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
fun loadAppOpenAd(context: Context) {
Purchases.sharedInstance.adTracker.loadAndTrackAppOpenAd(
context = context,
adUnitId = "ca-app-pub-3940256099942544/9257395921",
adRequest = AdRequest.Builder().build(),
placement = "app_launch",
loadCallback = object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(ad: AppOpenAd) {
// Ad loaded successfully
}
override fun onAdFailedToLoad(error: LoadAdError) {
// Handle error
}
}
)
}
Placement Parameter
The placement parameter identifies where ads appear in your app and is used for reporting and segmentation in Ad Charts.
Use consistent, descriptive names like "home_banner" or "level_complete_interstitial". Avoid dynamic values or timestamps.
Events Tracked Automatically
The loadAndTrack methods automatically track:
- Ad Loaded - Ad successfully loads
- Ad Displayed - Ad impression is recorded
- Ad Opened - User clicks the ad
- Ad Revenue - Ad generates revenue (via AdMob's paid event)
- Ad Failed to Load - Ad fails to load
All events are captured from AdMob's callbacks with no additional code required.
Optional Parameters
All loadAndTrack methods support optional parameters:
adTracker.loadAndTrackInterstitialAd(
context = context,
adUnitId = adUnitId,
adRequest = adRequest,
placement = "level_complete", // Optional: for reporting
loadCallback = callback, // Optional: your load callback
fullScreenContentCallback = contentCallback, // Optional: for ad lifecycle
onPaidEventListener = paidListener // Optional: your paid event listener
)
RevenueCat wraps your callbacks to add tracking before forwarding events to your handlers.
Example Project
A complete working implementation is available in the RevenueCat Android SDK repository:
purchases-android/examples/admob-sample
The example includes all supported ad formats, Jetpack Compose integration, and best practices.
Important Notes
Experimental API
Ad monetization APIs are marked as @ExperimentalPreviewRevenueCatPurchasesAPI and require opt-in:
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
Delegate Handling
Pass delegates to loadAndTrack methods rather than assigning them afterward. Reassigning delegates after calling loadAndTrack will break event tracking.
// ✅ Correct
adTracker.loadAndTrackInterstitialAd(
fullScreenContentCallback = myDelegate
)
// ❌ Don't do this
ad.fullScreenContentCallback = myDelegate // Overwrites tracking
Requirements
- Minimum SDK:
purchases-android8.0.0+ - AdMob SDK: Google Mobile Ads SDK 22.0.0+
View Your Data
See the Ad Monetization overview for details on where your ad data appears in the dashboard.
Optional: Make Charts More Readable
By default, your ad charts will display ad unit IDs like ca-app-pub-3940256099942544/9214589741. To see human-readable names instead:
→ Connect your Google AdMob account to automatically sync ad unit names to RevenueCat. This enhances chart readability without requiring any code changes.
Troubleshooting
Testing Your Integration
Before troubleshooting, verify your events are being tracked:
- Run your app in debug mode
- Navigate to the Ads page in your RevenueCat dashboard
- Toggle on "Sandbox data"
- Trigger some ads in your app
- Check that events appear in the sandbox events table
Events from debug builds are automatically marked as sandbox. This lets you verify your integration without affecting production data.
Note on event timing: Ad events are not synced to the dashboard in real-time. The SDK batches and sends events periodically. If you've triggered several ads and don't see events immediately, try putting your app in the background and bringing it back to the foreground to trigger a sync. This is normal behavior and doesn't indicate an integration issue.
Events not appearing in Charts
- Verify you've opted in via the Ads page in your RevenueCat dashboard
- Check that you're using
loadAndTrackmethods (not standard AdMob methods) - Ensure
placementparameter is provided - Verify ads are actually loading and showing (check AdMob callbacks)
- Use the sandbox data view (above) to confirm events are being received
Compilation errors
Make sure you've added the @OptIn annotation:
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
Next Steps
- Review the example project
- View your ad data in Ad Charts