Request but no impresion

Hello,

I have implemented Mediation(Packages installed : “Ads Mediation” V1.0.0 and “Advertissement with Mediation” V1.0.5) for Ads in my game(Android).
But I have a problem: It works in the editor but not in the game build.

My app ID appears correctly in the Unity Mediation settings. Everything is ok in Unity DashBoard
And in the monetization tab, I see that there are requests but no impressions.

I use the Unity Mediation Code generator and made some little modification :

Banner Ad Script

using System;
using System.Threading.Tasks;
using Unity.Services.Core;
using Unity.Services.Mediation;
using UnityEngine;

public class BannerAdDisplay : MonoBehaviour, IDisposable
{
    IBannerAd ad;
    string adUnitId = "Banner_Android";
    string gameId = "4493651";

    public void Start()
    {
        //LetBeginBanner();
    }

    public void LetBeginBanner()
    {
        InitServices();
    }
    public async Task InitServices()
    {
        Debug.Log("Test initservice");
        try
        {
            InitializationOptions initializationOptions = new InitializationOptions();
            initializationOptions.SetGameId(gameId);
            await UnityServices.InitializeAsync(initializationOptions);

            InitializationComplete();
        }
        catch (Exception e)
        {
            InitializationFailed(e);
        }
    }

    public void SetupAd()
    {
        Debug.Log("Test SetupAd");
        //Create
        ad = MediationService.Instance.CreateBannerAd(
            adUnitId,
            BannerAdPredefinedSize.Banner.ToBannerAdSize(),
            BannerAdAnchor.BottomCenter,
            Vector2.zero);

        //Subscribe to events
        ad.OnRefreshed += AdRefreshed;
        ad.OnClicked += AdClicked;
        ad.OnLoaded += AdLoaded;
        ad.OnFailedLoad += AdFailedLoad;

        // Impression Event
        MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    }

    public void Dispose() => ad?.Dispose();


    void InitializationComplete()
    {
        Debug.Log("Test init complete");
        SetupAd();
        LoadAd();
    }

    async Task LoadAd()
    {
        Debug.Log("Test LoadAd");
        try
        {
            await ad.LoadAsync();
        }
        catch (LoadFailedException)
        {
            // We will handle the failure in the OnFailedLoad callback
        }
    }

    void InitializationFailed(Exception e)
    {
        Debug.Log("Test init failed");
        Debug.Log("Initialization Failed: " + e.Message);
    }

    void AdLoaded(object sender, EventArgs e)
    {
        Debug.Log("Test AdLoaded");
        Debug.Log("Ad loaded");
    }

    void AdFailedLoad(object sender, LoadErrorEventArgs e)
    {
        Debug.Log("Test AdFailedLoad");
        Debug.Log("Failed to load ad");
        Debug.Log(e.Message);
    }

    void AdRefreshed(object sender, LoadErrorEventArgs e)
    {
        Debug.Log("Refreshed ad");
        //Debug.Log(e.Message);
    }

    void AdClicked(object sender, EventArgs e)
    {
        Debug.Log("Ad has been clicked");
        // Execute logic after an ad has been clicked.
    }

    void ImpressionEvent(object sender, ImpressionEventArgs args)
    {
        var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
        Debug.Log("Impression event from ad unit id " + args.AdUnitId + " " + impressionData);
    }

}

Reward Ad Script

using System;
using System.Threading.Tasks;
using Unity.Services.Core;
using Unity.Services.Mediation;
using UnityEngine;


public class AdDisplay : MonoBehaviour, IDisposable
{
    IRewardedAd ad;
    string adUnitId = "supportAd";
    string gameId = "4493651";
    int oneMoreLife;
    bool haveBeenSeen = false;
    //public GameObject panel;

    public void LetsBegin()
    {
        InitServices();
        haveBeenSeen = false;
    }
    public async Task InitServices()
    {
        Debug.Log("Test InitService !");
        try
        {
            InitializationOptions initializationOptions = new InitializationOptions();
            initializationOptions.SetGameId(gameId);
            await UnityServices.InitializeAsync(initializationOptions);

            InitializationComplete();
        }
        catch (Exception e)
        {
            InitializationFailed(e);
        }
    }

    public void SetupAd()
    {
        Debug.Log("Test Setup !");
        //Create
        ad = MediationService.Instance.CreateRewardedAd(adUnitId);

        //Subscribe to events
        ad.OnClosed += AdClosed;
        ad.OnClicked += AdClicked;
        ad.OnLoaded += AdLoaded;
        ad.OnFailedLoad += AdFailedLoad;
        ad.OnUserRewarded += UserRewarded;

        // Impression Event
        MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    }

    public void Dispose() => ad?.Dispose();


    public async void ShowAd()
    {
        Debug.Log("Test ShowAd !");
    
        if (ad.AdState == AdState.Loaded)
        {
            try
            {
                RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
                showOptions.AutoReload = true;
                await ad.ShowAsync(showOptions);
                AdShown();
            }
            catch (ShowFailedException e)
            {
                AdFailedShow(e);
            }
        }

    }

    public void InitializationComplete()
    {
        Debug.Log("Test InitilizationComplete !");
    
        SetupAd();
        LoadAd();
    }

    async Task LoadAd()
    {
        Debug.Log("Test LoadAd !");
        try
        {
            await ad.LoadAsync();
        }
        catch (LoadFailedException)
        {
            // We will handle the failure in the OnFailedLoad callback
        }
    }

    void InitializationFailed(Exception e)
    {
        Debug.Log("Initialization Failed: " + e.Message);
    }

    void AdLoaded(object sender, EventArgs e)
    {
        Debug.Log("Ad loaded");
        if(!haveBeenSeen)
        ShowAd();
    }

    void AdFailedLoad(object sender, LoadErrorEventArgs e)
    {
        Debug.Log("Failed to load ad");
        Debug.Log(e.Message);
    }

    public void AdShown()
    {
        Debug.Log("Ad shown!");
        int countNumerOfPart = 0;
        PlayerPrefs.SetInt("countNumerOfPart", countNumerOfPart);
        oneMoreLife = 1;
        PlayerPrefs.SetInt("oneMoreLife", oneMoreLife);
        // Give coins etc.
        //if (panel != null)
        //{
            //panel.SetActive(false);
        //}
        //adStarted = false;
        Time.timeScale = 1;
    
    }

    void AdClosed(object sender, EventArgs e)
    {
        Debug.Log("Ad has closed");
        haveBeenSeen = true;
        // Execute logic after an ad has been closed.
    }

    void AdClicked(object sender, EventArgs e)
    {
        Debug.Log("Ad has been clicked");
        // Execute logic after an ad has been clicked.
    }

    void AdFailedShow(ShowFailedException e)
    {
        Debug.Log("Test AdFailedShow !");
        Debug.Log(e.Message);
    }

    void ImpressionEvent(object sender, ImpressionEventArgs args)
    {
        var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
        Debug.Log("Impression event from ad unit id " + args.AdUnitId + " " + impressionData);
    }

    void UserRewarded(object sender, RewardEventArgs e)
    {
        Debug.Log($"Received reward: type:{e.Type}; amount:{e.Amount}");
    }
}

The function “LetsBegin()” is called when player press a button to obtain reward

EDIT : and Here it is the logCat :
Error logger Initialization has failed due to: Request to https://mediation-instantiation.prd.mz.internal.unity3d.com/v1/initialize failed due to java.io.IOException: Instantiation Service initialization request failed with http status code 404 and server response: game init not found for game id: 4493651

I have a second question, in editor when, on my menu scene the banner ad is displayed but then I click on button to load another scene but the banner ad is still dsiplayed. I try the function Dispose to make it disappear but it’s not working

Could you please help me to know why ads are not displaying in build and how to make the banner ad disappear in another scene than the Menu one

Valentin Honoré

Hello,

No one can help me ?

This seems to indicate you are attempting to use Unity Mediation, while your dashboard is setup to use LevelPlay.
We recommend you use “Ads Mediation” which is LevelPlay.

Hello @jcGrenier

First, thanks for your time
What have I have to choose here so :
I can choose Level Play, adsmob, applovin, other or self mediated
I specify that it is Level Play which was checked until today

This is the correct option, but you also need the Level play package, com.unity.services.levelplay (Ads Mediation).
The error you mentioned is from the Unity Mediation package, which is being sunset in favor of LevelPlay.

Hope this helps :slight_smile:

Sorry for the late reply,

But yes I’m already using Ads Mediation :

But that isn’t working …

No worries for the delay, we also tend to answer these whenever we have some spare time, so delays do occur. :slight_smile:

Could you elaborate on what you mean by not working? What does your integration look like, and what kind of error are you seeing?

I have no errors message. When players die, a menu is displaying :
1°) finish the game
2°) Use a “heart” to revive when and where they die
3°) See an add to revive when and where they die

But when pressing the Add button, nothing play. In Editor, when pressing the button an “test” add is playing. But in build, nothing play and no errors message (I see that the button detecting the press because, it changes color

Vidéo :

I would need to see the device logs and possibly the source code to offer more assistance.

Source code is given in first comment.
For the device logs, I’ll do it as soon as possible

Here is the logcat :

that come from line 113 to line 117 of the script reward ad

[*]void AdFailedLoad(object sender, LoadErrorEventArgs e)
[*]    {
[*]        Debug.Log("Failed to load ad");
[*]        Debug.Log(e.Message);
[*]    }

And for the banner AD, The logcat is :

this lines come from line 94 to line 99 of banner ad script

void AdFailedLoad(object sender, LoadErrorEventArgs e)
    {
        Debug.Log("Test AdFailedLoad");
        Debug.Log("Failed to load ad");
        Debug.Log(e.Message);
    }

The scripts are in first comment

Can anyone solved the “Failed To Load …” issue ?

What I see from your logs is that you have an invalid format, that would mean you are trying to load an interstitial but setup a rewarded, or vice-versa for example.

Oh ! Ok I’ll look what I’ve missed about that format.

And what about the Banner ad issue so ? It isn’t link to format issue

This is from the log you posted regarding the banner:
02-18 10:40:16.263 28176 28198 I Unity : Exception raised while retrieving the Ad Unit Configuration: com.unity3d.mediation.k0: Requested Ad Unit has incorrect format.

For the Rewarded/Interstitial (or vice-versa) “invalid format”:
I’ve changed the Ad format in UnityDash board from “Interstitial” To “Rewarded” but no change.
Same device log

For the Banner AD flagged as incorrect format, I don’t understand why it is an incorrect format ? Oo

Could you please explain me why ?

Regards,

Valentin

It could be for example that you create a banner, but pass an interstitial ad unit id.
Although I have not tried this, I assume it could also be caused by one of the line items linking to a placement on an ad network, where the provided placement is not a banner.

So i’ve checked and NO this isn’t the solution
For the banner ad script I pass a banner ad unit ID and for the interstitial ad script I pass a interstial ad unit ID.

I really don’t know what to do anymore…

Unity Mediation has been deprecated. For more information, see: Important update about Unity Mediation