Learn/Monetization/AdMob & In-App Purchases

AdMob & In-App Purchases

Monetize your app with ads and one-time purchases

7 min~5 min read+45 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Monetization Mix Strategy
  2. 2. This Lesson In Simple Words
  3. 3. Your level focus
  4. 4. One practical habit
  5. 5. Deep Understanding Guide
  6. 6. Why this lesson matters
  7. 7. Study flow for better retention
  8. 8. Architecture Lens

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

AdMob & In-App Purchases

Make money from your app with Google AdMob for ads and In-App Purchases for one-time or recurring payments. These are the two most common monetization strategies for mobile apps, and understanding both options allows you to choose the right revenue model for your audience and app category.

dart
1// ── ADMOB ──
2// pubspec.yaml: google_mobile_ads: ^4.0.0
3import 'package:google_mobile_ads/google_mobile_ads.dart';
4
5// Initialize in main
6void main() async {
7 WidgetsFlutterBinding.ensureInitialized();
8 await MobileAds.instance.initialize();
9 runApp(const MyApp());
10}
11
12// ── Banner Ad ──
13class BannerAdWidget extends StatefulWidget { ... }
14class _BannerAdWidgetState extends State<BannerAdWidget> {
15 BannerAd? _bannerAd;
16
17 @override
18 void initState() {
19 super.initState();
20 _bannerAd = BannerAd(
21 adUnitId: 'ca-app-pub-xxxxx/xxxxx', // your ad unit ID
22 size: AdSize.banner,
23 request: const AdRequest(),
24 listener: BannerAdListener(
25 onAdLoaded: (_) => setState(() {}),
26 onAdFailedToLoad: (ad, error) => ad.dispose(),
27 ),
28 )..load();
29 }
30
31 @override
32 Widget build(BuildContext context) {
33 if (_bannerAd == null) return const SizedBox.shrink();
34 return SizedBox(
35 height: _bannerAd!.size.height.toDouble(),
36 child: AdWidget(ad: _bannerAd!),
37 );
38 }
39
40 @override
41 void dispose() {
42 _bannerAd?.dispose();
43 super.dispose();
44 }
45}
46
47// ── Interstitial Ad ──
48InterstitialAd? _interstitialAd;
49
50void loadInterstitial() {
51 InterstitialAd.load(
52 adUnitId: 'ca-app-pub-xxxxx/xxxxx',
53 request: const AdRequest(),
54 adLoadCallback: InterstitialAdLoadCallback(
55 onAdLoaded: (ad) => _interstitialAd = ad,
56 onAdFailedToLoad: (error) => print('Failed: $error'),
57 ),
58 );
59}
60
61void showInterstitial() {
62 _interstitialAd?.show();
63 _interstitialAd = null;
64 loadInterstitial(); // preload next
65}
dart
1// ── IN-APP PURCHASES ──
2// pubspec.yaml: in_app_purchase: ^3.1.0
3import 'package:in_app_purchase/in_app_purchase.dart';
4
5final iap = InAppPurchase.instance;
6
7// Check availability
8final available = await iap.isAvailable();
9
10// Get products
11const productIds = {'premium_monthly', 'remove_ads'};
12final response = await iap.queryProductDetails(productIds);
13final products = response.productDetails;
14
15// Buy a product
16iap.buyNonConsumable(purchaseParam: PurchaseParam(productDetails: product));
17
18// Listen for purchase updates
19iap.purchaseStream.listen((purchases) {
20 for (final purchase in purchases) {
21 if (purchase.status == PurchaseStatus.purchased) {
22 // ✅ Unlock feature, verify receipt on server
23 await iap.completePurchase(purchase);
24 } else if (purchase.status == PurchaseStatus.error) {
25 // ❌ Handle error
26 }
27 }
28});

Test Ads Only

⚠️ Test Ads Only

Never use real ad unit IDs during development. Use the official Google test IDs instead. - Banner test ID: ca-app-pub-3940256099942544/6300978111 - Interstitial test ID: ca-app-pub-3940256099942544/1033173712 Using real ads in test builds can get your AdMob account banned!

Monetization Mix Strategy

Ads and purchases should complement each other rather than compete:

  • Free tier monetizes through low-friction ad placements.
  • Premium purchase removes ads and unlocks additional value.
  • Rewarded ads support users who cannot pay but want feature access.
  • Frequency caps protect retention from ad fatigue.

Balanced monetization improves revenue without sacrificing long-term engagement.

Ads And IAP Checklist

  • Ad placement does not block core task completion.
  • Purchases are acknowledged and restored correctly across reinstalls.
  • Monetization events are tracked for funnel analysis.
  • Regional pricing and store availability are validated.
  • Failure states for ad load and purchase errors are user-friendly.

This Lesson In Simple Words

Monetize your app with ads and one time purchases. Monetization features help apps earn revenue while preserving user trust and value.

Your level focus

Operate with production and interview-level clarity.

One practical habit

Show value first, then present clear and honest upgrade options.

Deep Understanding Guide

Why this lesson matters

Bad monetization UX increases churn even when app features are strong.

Study flow for better retention

  1. Tie each concept to scale, failure handling, and delivery strategy.
  2. Measure conversion with context: retention, cancellation reasons, and user feedback.
  3. If you can defend trade-offs under constraints, your understanding is strong.

Common Mistakes To Avoid

  • Showing aggressive paywalls before users see core product value.
  • Hiding pricing details or renewal rules in unclear text.
  • Not handling purchase restore flows and failed transaction paths.
  • Ignoring analytics on subscription funnel drop-off points.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build a transparent paywall with clear benefits and billing notes.
  • Implement purchase success, pending, failure, and restore states.
  • Track conversion and cancellation events with structured analytics.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "What must you call before using AdMob ads?".

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Architecture Lens

Monetization code should stay modular to avoid coupling revenue logic with core UI flows.

As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.

Lesson Completion Checklist

  • I can explain "AdMob & In-App Purchases" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Showing aggressive paywalls before users see core product value.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

What must you call before using AdMob ads?

MobileAds.instance.initialize() must be called in main() before showing any ads.

What is the difference between consumable and non-consumable IAP?

Consumable (coins, gems) can be bought repeatedly. Non-consumable (remove ads, premium) is a one-time purchase.

Why must you call completePurchase() after a successful IAP?

completePurchase() acknowledges to Google Play/App Store that the purchase was delivered. Missing this can cause refunds.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue