1
votes

I have been trying since 2 days to figure out why on earth is admob just showing the TestAds! When i use testId it show test ads. When i use my admob banner id it becomes blank(no ads shown) Below ive attached my admob banner code.

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour
{

    public string BannerId;


    // Use this for initialization
    void Start()
    {
        //Request Ads
        RequestBanner();

    }

    private void RequestBanner()
    {
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
		string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
			string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
			string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the bottom of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
}

I tried to research on why it aint working but unfortunately there are very less unity related admob solutions available on the internet.

Google Mobile Ads Plugin v3.13.1
Unity 2017.4.0f1

Please help me out! Thanks!

2

2 Answers

1
votes
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour
{

    private string BannerId;


    // Use this for initialization
    void Awake()
    {
        //Request Ads
        RequestBanner();

    }

    private void RequestBanner()
    {
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
        string adUnitId = "You UNIT-ID HERE";
#elif UNITY_IPHONE
            string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
            string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the bottom of the screen.
        BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
}

Make sure you UNIT-ID is correct. Do not put your APP-ID instead of UNIT-ID.

0
votes

I was running into a similar problem, and it turns out that AdMob won't serve ads unless you have payment information set up. So make sure that is set up.

Also, when switching from using the test ads to actual ads, you need to make sure to change your app ID as well as your unit ID. It looks like you may only be changing your unit ID.

Somewhere else in your project you should have something like this:

using System.Collections;
using UnityEngine;
using GoogleMobileAds.Api;


public class AdInitializer : MonoBehaviour {

    public void Start()
    {
        #if UNITY_ANDROID
        string appId = "ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX";
        #elif UNITY_IPHONE
        string appId = "ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX";
        #else
        string appId = "unexpected_platform";
        #endif

        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize(appId);
        Debug.Log ("Initializing ads for app ID " + appId);
    }
}

Make sure this is using your app IDs and not the test app IDs.