Admob Unity Banner Ads Not Showing

Admob Unity Banner Ads Not Showing

So, you've followed Google's Admob Unity documentation to a T but for some reason the banner ads are simply not showing.

Nope, it's not Google. It's you. Well, no. The documentation skips this part, so it's easy for people to miss this.

If you are like me, there are probably 2 reasons why Admob banner ads wouldn't show up:

1. You did not call BannerView.Show()

Yes, if you've followed the documentation, you probably didn't call BannerView.Show(). They forgot to tell you this. 

You need to call .Show() after the banner is loaded.

2. You called BannerView.Show() before Banner View is loaded.

Yep, this is annoying, but .Show() needs to be called after the bannerview is loaded.

The best way to ensure the BannerView is loaded is by calling BannerView.Show() in the BannerView.OnAdLoaded event.

Bonus

And what post would be complete without a code sample?

Just copy this code into a Script and attach it to a GameObject. Your Unity Admob banner ads will now start showing up. Just modify the adUnitId and other stuffs to whatever you want. Hurray!

 

using GoogleMobileAds.Api;

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class AdmobScript : MonoBehaviour

{



    private BannerView _bannerView;



    // Start is called before the first frame update

    void Start()

    {



        string appId = "";



#if UNITY_ANDROID

            appId = "ca-app-pub-3940256099942544~3347511713";

#elif UNITY_IPHONE

            appId = "ca-app-pub-3940256099942544~1458002511";

#else

        appId = "unexpected_platform";

#endif



        // Initialize the Google Mobile Ads SDK.

        MobileAds.Initialize(appId);



        RequestBanner();

    }



    private void RequestBanner()

    {

#if UNITY_ANDROID

            string adUnitId = "ca-app-pub-3940256099942544/6300978111";

#elif UNITY_IPHONE

            string adUnitId = "ca-app-pub-3940256099942544/2934735716";

#else

        string adUnitId = "unexpected_platform";

#endif



        // Create a 320x50 banner at the top of the screen.

        _bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);



        _bannerView.OnAdLoaded += HandleOnAdLoaded;



        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();







        // Load the banner with the request.

        _bannerView.LoadAd(request);





    }



    // Update is called once per frame

    void Update()

    {

        

    }



    public void HandleOnAdLoaded(object sender, EventArgs args)

    {

        _bannerView.Show();

    }



}