Unity Test Ad appearing in editor but not built project

Hello, I have been struggling to get a Unity banner ad working in my game. At first, I tried using the unity Ads Service from the Services tab. I downloaded unity in 2017, so it was using whatever version of the Ads package that was automatically downloaded then.

I tried to use Advertisement.Banner from the UnityEngine.Advertisements namespace. However, the version of Advertisements that was installed must have been older, because it didn’t have the Banner class.

I downloaded a newer version of the Advertisements package from the asset store (UnityMonetization 3.0.1). I understand that this package can clash with the version of Advertisements I already had, so I un-checked the ‘enable built-in ads extension’ box in the Ad Services tab. I also had test mode enabled, and I set up my ad Placement on my dashboard.

I thought I had got it working, because the test ad banner appeared when I ran in the editor. However, when I built the game to my device, the test ad did not appear.

Here are my logs:

Not sure what to make of this log output, I see the “Couldn’t send storage event to webapp” but I’m not sure if that is related to my project.

Here is my code (I just put everything in my main GameManager script but I have included only the relevant code from that script)

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Monetization;
using UnityEngine.Advertisements;

public class GameManager : MonoBehaviour {
   ...

    private string gameId = "3236722";
    private string placementId = "banner";
    public bool testMode = false;

    // Use this for initialization
    void Start () {
        Monetization.Initialize(gameId, testMode);
        StartCoroutine(ShowBannerWhenReady());
    ...

    }
    ...

    IEnumerator ShowBannerWhenReady()
    {
        while (!Monetization.IsReady(placementId))
        {
            yield return new WaitForSeconds(0.5f);
        }
        Advertisement.Banner.Show(placementId);
    }
}

Yeah, a lot of those log messages aren’t related to your issue and they’re expected.

There are a couple of possible improvements:

  1. There is no need to use Monetization namespace at all. This is only useful if you are using Personalized Placements.
  2. You can Load the banner and get a callback when it’s ready rather than use a coroutine.
  3. The Load method will also give you an error callback to let you know why the banner didn’t render.

I would recommend something like this:

public class GameManager : MonoBehaviour {
   ...
    private string gameId = "3236722";
    private string placementId = "banner";
    public bool testMode = false;
    // Use this for initialization
    void Start () {
        Advertisement.Initialize(gameId, testMode);
        LoadBanner(placementId);
    ...
    }
    public void LoadBanner(placementId)
    {
        if(!Advertisement.Banner.isLoaded)
        {
            BannerLoadOptions loadOptions = new BannerLoadOptions
            {
                loadCallback = OnBannerLoaded,
                errorCallback = OnBannerError
            };
            Advertisement.Banner.Load(placementId, loadOptions);
        }
    }
    void OnBannerLoaded()
    {
        Debug.Log("Banner Loaded");
        Advertisement.Banner.Show(placementId);
    }
    void OnBannerError(string error)
    {
        Debug.Log("Banner Error: " + error);
    }
}

That said, even if it is implemented correctly, we are not always able to offer banner ads at the moment. We are working to improve our inventory, so if you see a “Banner not available” or “no fill” error message, then that is likely the case.