GAM setup flutter

Setting up Google Ad Manager (GAM) for a Flutter app involves integrating the GAM SDK into your Flutter project, creating ad units, setting up line items and creatives, and displaying ads within your app. Here's a step-by-step guide to help you set up GAM for Flutter:

Step 1: Create a Google Ad Manager Account

If you don't have a Google Ad Manager account, you'll need to create one by visiting https://admanager.google.com and signing up.

Step 2: Set Up an Application in Google Ad Manager

  1. Log in to your Google Ad Manager account.
  2. Click on "Inventory" in the left sidebar.
  3. Under "Ad units," click "Ad units."
  4. Click the "+ New ad unit" button.
  5. Fill in the ad unit details, including the name, ad type (e.g., banner, interstitial), size, and targeting options.
  6. Save the ad unit and take note of the ad unit ID.

Step 3: Integrate the GAM SDK into Your Flutter App

  1. Add the google_mobile_ads package to your pubspec.yaml file:
    dependencies:
        flutter:
            sdk: flutter
        google_mobile_ads: ^latest_version
  2. Run flutter pub get to install the package.

Step 4: Initialize the GAM SDK in Your App

  1. Import the google_mobile_ads package in your Dart file:
    import 'package:google_mobile_ads/google_mobile_ads.dart';
  2. Initialize the GAM SDK by adding the following code in your main function or wherever you initialize your Flutter app:
    WidgetsFlutterBinding.ensureInitialized();
    MobileAds.instance.initialize();

Step 5: Request and Display Ads

  1. Create a banner or interstitial ad widget in your Flutter app
    AdWidget(
        ad: BannerAd(
            size: AdSize.banner,
            adUnitId: 'YOUR_AD_UNIT_ID',
            request: AdRequest(),
            listener: BannerAdListener(),
        ),
    )
  2. Replace 'YOUR_AD_UNIT_ID' with the actual ad unit ID you obtained from GAM.

Additional Steps

  • Customize the ad appearance and behavior using the provided ad widget properties and listeners.
  • For interstitial ads, use the InterstitialAd class to create and display interstitial ads with appropriate listeners.
  • Implement ad event listeners to handle ad lifecycle events, such as ad loaded, ad failed to load, ad clicked, etc.

Please refer to the Google Mobile Ads Flutter plugin documentation for more detailed information, guides, and code examples on setting up Google Ad Manager with Flutter. You can also check our github example.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.