On this page16 sections
  1. Prerequisites
  2. Connection With Previous Lectures
  3. Learning Objectives
  4. Lesson
  5. 1. The Steps
  6. 2. Test Safely With Real Ids
  7. 3. Policy Checklist
  8. 4. Before Release
  9. Code Examples
  10. Common Beginner Mistakes
  11. Best Practices
  12. Mini Challenge
  13. Practice Questions
  14. Practice Answers
  15. Key Takeaways
  16. Full Code (Copy-Paste Reference)

Lecture 010: Going Live: Real Ids & Policies

Category4: Going Live
Lecture010 of 010
Estimated video length20 min
TargetFlutter 3.44 · Dart 3.12 · google_mobile_ads 9
LevelBeginner
Source codeGitHub: urraan_admob_final

Everything so far used test ads. To earn, create your app in AdMob, create ad units, put the real ids in AdmobManager and follow the policies that keep your account safe.

Contents

Prerequisites · Connection · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Mini Challenge · Practice Questions · Answers · Takeaways · Full Code


Prerequisites

All previous lectures.


Connection With Previous Lectures

The demo is complete and tested. This last lecture is the checklist from "works on my phone" to "earns".


Learning Objectives

By the end of this lecture you will be able to:

  • Create an AdMob account, app and ad units
  • Replace the sample app ids and fill the real-id maps
  • Test with your own device safely
  • Follow the key policies

Lesson

1. The Steps

  1. Sign in at admob.google.com with your Google account.
  2. Apps → Add app. Choose Android or iOS and say whether it is published on a store.
  3. AdMob shows your app id (~). Replace the sample id in AndroidManifest.xml / Info.plist.
  4. Ad units → Add ad unit for each format. Copy each ad unit id (/).
  5. Paste them into _androidIds / _iosIds in AdmobManager.
  6. Set up Privacy & messaging (consent message) and Payments (address, bank).

2. Test Safely With Real Ids

Add your phone as a test device in the AdMob dashboard (Settings → Test devices) or with MobileAds.instance.updateRequestConfiguration(...) and the device id printed in the log. Then even real ids show test ads on that device.

3. Policy Checklist

  • Never tap your own ads or ask others to.
  • Do not place ads so users tap them by accident (banner next to buttons, overlays).
  • Do not show interstitials at app start, on exit, or during a task.
  • Describe a rewarded ad honestly before it plays.
  • Have a privacy policy and mention the ads in it.
  • Keep ad content appropriate for your audience; apps for children need special settings.

4. Before Release

CheckDone
App ids replaced (Android + iOS)☐
All ad unit ids filled in both maps☐
showTestAdsInDebug is fine for release (the release build ignores it)☐
Consent message published☐
Tested a release build on a test device☐

Code Examples

Example 1: Release Build

bash
flutter build appbundle --release

Install the release build and confirm ads load (as test ads on your test device) before uploading to the store.


Common Beginner Mistakes

1. Leaving the sample app id in a release: no revenue; AdMob cannot match the app.

2. Empty ad unit ids: nothing loads.

3. Testing with real ads without a test device: risks invalid traffic.

4. No privacy policy: stores and AdMob can reject the app.


Best Practices

  • Use separate ad units per placement to compare earnings
  • Add yourself as a test device before touching real ids
  • Re-read the AdMob policies before each major release

Mini Challenge

Make a checklist file in your own project with the table above and tick it before each release.


Practice Questions

  1. What replaces the sample app id?
  2. Where do ad unit ids go in code?
  3. How do you test real ids safely?
  4. Name two policy rules.

Practice Answers

  1. The app id from your AdMob dashboard.
  2. In _androidIds / _iosIds of AdmobManager.
  3. Register a test device.
  4. Never tap your own ads; no interstitials during a task.

Key Takeaways

  • Real ids come from the AdMob dashboard
  • Test device first, then real ids
  • Follow policies to keep the account safe

Full Code (Copy-Paste Reference)

The app itself is unchanged from Lecture 009 (all five ad screens, the dashboard, splash and main.dart: see Lectures 006–009's Full Code sections). The only file that changes for release is AdmobManager's real-id maps, plus the two platform app ids from Lecture 001.

lib/admob/admob_manager.dart: filled in for release

dart
import 'dart:io';

import 'package:flutter/foundation.dart';

class AdmobManager {
  // Flip to false once you've verified real ads on a registered test device,
  // if you want to double-check real ads even in a debug build.
  static const bool showTestAdsInDebug = true;

  static const _testIds = {
    'bannerAdaptive': 'ca-app-pub-3940256099942544/9214589741',
    'bannerFixed': 'ca-app-pub-3940256099942544/6300978111',
    'interstitial': 'ca-app-pub-3940256099942544/1033173712',
    'rewardedInterstitial': 'ca-app-pub-3940256099942544/5354046379',
    'rewarded': 'ca-app-pub-3940256099942544/5224354917',
    'native': 'ca-app-pub-3940256099942544/2247696110',
    'appOpen': 'ca-app-pub-3940256099942544/9257395921',
  };

  // Replace every '' below with the matching ad unit id from
  // admob.google.com → Apps → [your app] → Ad units.
  static const _androidIds = {
    'bannerAdaptive': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'bannerFixed': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'interstitial': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'rewardedInterstitial': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'rewarded': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'native': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'appOpen': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
  };

  static const _iosIds = {
    'bannerAdaptive': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'bannerFixed': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'interstitial': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'rewardedInterstitial': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'rewarded': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'native': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
    'appOpen': 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
  };

  static Map<String, String> get _ids {
    if (kDebugMode && showTestAdsInDebug) return _testIds;
    return Platform.isAndroid ? _androidIds : _iosIds;
  }

  static String get bannerAdaptiveId => _ids['bannerAdaptive'] ?? '';
  static String get bannerFixedId => _ids['bannerFixed'] ?? '';
  static String get interstitialId => _ids['interstitial'] ?? '';
  static String get rewardedInterstitialId =>
      _ids['rewardedInterstitial'] ?? '';
  static String get rewardedId => _ids['rewarded'] ?? '';
  static String get nativeId => _ids['native'] ?? '';
  static String get appOpenId => _ids['appOpen'] ?? '';
}

Platform app ids: replace the samples from Lecture 001

xml
<!-- android/app/src/main/AndroidManifest.xml -->
<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-YOUR_REAL_APP_ID~YOUR_SUFFIX"/>
xml
<!-- ios/Runner/Info.plist -->
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-YOUR_REAL_APP_ID~YOUR_SUFFIX</string>

Before shipping, register your own device as an AdMob test device (Settings → Test devices in the dashboard) so real ids still show safe test ads while you do a final check: then build and install a release build to confirm everything still loads:

bash
flutter build appbundle --release