GAM setup - android

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

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 Android App

Add the GAM SDK to your app's build.gradle file. Open the app-level build.gradle file and add the following dependencies:

implementation 'com.google.android.gms:play-services-ads:20.3.0' // Replace with the latest version

Then, sync your project to download the SDK.

Step 4: Initialize the GAM SDK in your app

In your app's main application class, import the GAM SDK:

import com.google.android.gms.ads.MobileAds;

In the onCreate() method of your application class, initialize the GAM SDK with your Ad Manager app ID:

MobileAds.initialize(this, "YOUR_APP_ID"); // Replace with your Ad Manager app ID

Step 5: Request and Display Ads

In the activity or fragment where you want to display ads, import the GAM SDK:

import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;

In your XML layout file, add an AdView element:

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="YOUR_AD_UNIT_ID" />

In your activity or fragment, find the AdView and load an ad:

AdView adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

That's it! You've successfully integrated the GAM SDK into your Android app and set up an ad unit. Remember to replace "YOUR_APP_ID" with your Ad Manager app ID and "YOUR_AD_UNIT_ID" with the actual ad unit ID you obtained from GAM.

Additional Steps

  • For interstitial ads, create an InterstitialAd instance and load an interstitial ad using an ad request.
  • 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 Ad Manager Android SDK documentation for more detailed information, guides, and code examples. 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.