Skip to main content

purchases_admob_flutter 11.0.4 copy "purchases_admob_flutter: ^11.0.4" to clipboard
purchases_admob_flutter: ^11.0.4 copied to clipboard

RevenueCat adapter for the google_mobile_ads plugin: automatic ad tracking and rewarded-ad reward verification.

RevenueCat

pub package

purchases_admob_flutter #

purchases_admob_flutter connects the google_mobile_ads plugin to RevenueCat's ad tracking and reward verification. Load your ads through the adapter and it reports loaded, failed-to-load, displayed, opened, revenue and earned-reward events for you; rewarded ads can additionally have their rewards verified server-side. See the AdMob integration docs for the full picture.

Installation #

Add purchases_flutter, google_mobile_ads and purchases_admob_flutter as dependencies in your pubspec.yaml. Configure Purchases and initialize MobileAds as you normally would; the adapter only tracks while Purchases is configured.

Tracking full-screen ads #

Replace InterstitialAd.load(...) (and the rewarded, rewarded interstitial and app open equivalents) with the matching RevenueCatAdMob.loadAndTrack... call. The callbacks are the same ones you already use; placement is a free-form label for where the ad is shown.

await RevenueCatAdMob.loadAndTrackInterstitialAd(
  adUnitId: adUnitId,
  request: const AdRequest(),
  placement: 'level_complete',
  adLoadCallback: InterstitialAdLoadCallback(
    onAdLoaded: (ad) {
      ad.fullScreenContentCallback = FullScreenContentCallback(
        onAdDismissedFullScreenContent: (ad) => ad.dispose(),
      );
      _interstitial = ad;
    },
    onAdFailedToLoad: (error) => debugPrint('$error'),
  ),
);

// Later. The placement given here overrides the load-time one for this impression.
await _interstitial.showAndTrack(placement: 'level_complete_retry');

Setting fullScreenContentCallback or onPaidEvent inside onAdLoaded is fine: the adapter wraps whatever you set there. If you assign fullScreenContentCallback later, use setTrackingFullScreenContentCallback(...) instead so tracking survives.

Tracking banner and native ads #

Banner and native ads take their listener at construction time, so wrap it:

final banner = RevenueCatAdMob.createBannerAd(
  adUnitId: adUnitId,
  size: AdSize.banner,
  request: const AdRequest(),
  placement: 'home_bottom',
  listener: BannerAdListener(onAdLoaded: (ad) => setState(() {})),
)..load();

final native = NativeAd(
  adUnitId: adUnitId,
  request: const AdRequest(),
  nativeTemplateStyle: NativeTemplateStyle(templateType: TemplateType.medium),
  listener: RevenueCatAdMob.trackingNativeAdListener(placement: 'feed'),
)..load();

Reward verification #

For RewardedAd and RewardedInterstitialAd, call enableRewardVerification() once the ad has loaded and show it with showWithRewardVerification(...). The adapter attaches a RevenueCat token to AdMob's server-side verification options and polls RevenueCat for the verified reward when the user earns it.

RevenueCatAdMob.loadAndTrackRewardedAd(
  adUnitId: adUnitId,
  request: const AdRequest(),
  placement: 'extra_life',
  rewardedAdLoadCallback: RewardedAdLoadCallback(
    onAdLoaded: (ad) async {
      await ad.enableRewardVerification();
      _rewarded = ad;
    },
    onAdFailedToLoad: (error) => debugPrint('$error'),
  ),
);

await _rewarded.showWithRewardVerification(
  onRewardVerificationStarted: () => showSpinner(),
  onRewardVerificationCompleted: (result) {
    if (result.failed) return showError();
    grant(result.reward);
  },
);

The ad unit's server-side verification URL must point at RevenueCat and a reward must be configured for it in the RevenueCat dashboard; see the rewards docs.

Requirements #

  • iOS 15.0+ (ad tracking is unavailable below that; calls are ignored with a warning)
  • google_mobile_ads 8.x
  • purchases_flutter 10.17.0+
1
likes
0
points
1.52k
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

RevenueCat adapter for the google_mobile_ads plugin: automatic ad tracking and rewarded-ad reward verification.

Homepage
View/report issues

License

unknown (license)

Dependencies

flutter, google_mobile_ads, purchases_flutter

More

Packages that depend on purchases_admob_flutter