Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Request but no impresion

Discussion in 'Unity Mediation' started by Valentinhon, Jan 26, 2023.

  1. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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.
    upload_2023-1-26_9-50-55.png

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

    Banner Ad Script

    Code (CSharp):
    1. using System;
    2. using System.Threading.Tasks;
    3. using Unity.Services.Core;
    4. using Unity.Services.Mediation;
    5. using UnityEngine;
    6.  
    7. public class BannerAdDisplay : MonoBehaviour, IDisposable
    8. {
    9.     IBannerAd ad;
    10.     string adUnitId = "Banner_Android";
    11.     string gameId = "4493651";
    12.  
    13.     public void Start()
    14.     {
    15.         //LetBeginBanner();
    16.     }
    17.  
    18.     public void LetBeginBanner()
    19.     {
    20.         InitServices();
    21.     }
    22.     public async Task InitServices()
    23.     {
    24.         Debug.Log("Test initservice");
    25.         try
    26.         {
    27.             InitializationOptions initializationOptions = new InitializationOptions();
    28.             initializationOptions.SetGameId(gameId);
    29.             await UnityServices.InitializeAsync(initializationOptions);
    30.  
    31.             InitializationComplete();
    32.         }
    33.         catch (Exception e)
    34.         {
    35.             InitializationFailed(e);
    36.         }
    37.     }
    38.  
    39.     public void SetupAd()
    40.     {
    41.         Debug.Log("Test SetupAd");
    42.         //Create
    43.         ad = MediationService.Instance.CreateBannerAd(
    44.             adUnitId,
    45.             BannerAdPredefinedSize.Banner.ToBannerAdSize(),
    46.             BannerAdAnchor.BottomCenter,
    47.             Vector2.zero);
    48.  
    49.         //Subscribe to events
    50.         ad.OnRefreshed += AdRefreshed;
    51.         ad.OnClicked += AdClicked;
    52.         ad.OnLoaded += AdLoaded;
    53.         ad.OnFailedLoad += AdFailedLoad;
    54.  
    55.         // Impression Event
    56.         MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    57.     }
    58.  
    59.     public void Dispose() => ad?.Dispose();
    60.  
    61.  
    62.     void InitializationComplete()
    63.     {
    64.         Debug.Log("Test init complete");
    65.         SetupAd();
    66.         LoadAd();
    67.     }
    68.  
    69.     async Task LoadAd()
    70.     {
    71.         Debug.Log("Test LoadAd");
    72.         try
    73.         {
    74.             await ad.LoadAsync();
    75.         }
    76.         catch (LoadFailedException)
    77.         {
    78.             // We will handle the failure in the OnFailedLoad callback
    79.         }
    80.     }
    81.  
    82.     void InitializationFailed(Exception e)
    83.     {
    84.         Debug.Log("Test init failed");
    85.         Debug.Log("Initialization Failed: " + e.Message);
    86.     }
    87.  
    88.     void AdLoaded(object sender, EventArgs e)
    89.     {
    90.         Debug.Log("Test AdLoaded");
    91.         Debug.Log("Ad loaded");
    92.     }
    93.  
    94.     void AdFailedLoad(object sender, LoadErrorEventArgs e)
    95.     {
    96.         Debug.Log("Test AdFailedLoad");
    97.         Debug.Log("Failed to load ad");
    98.         Debug.Log(e.Message);
    99.     }
    100.  
    101.     void AdRefreshed(object sender, LoadErrorEventArgs e)
    102.     {
    103.         Debug.Log("Refreshed ad");
    104.         //Debug.Log(e.Message);
    105.     }
    106.  
    107.     void AdClicked(object sender, EventArgs e)
    108.     {
    109.         Debug.Log("Ad has been clicked");
    110.         // Execute logic after an ad has been clicked.
    111.     }
    112.  
    113.     void ImpressionEvent(object sender, ImpressionEventArgs args)
    114.     {
    115.         var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
    116.         Debug.Log("Impression event from ad unit id " + args.AdUnitId + " " + impressionData);
    117.     }
    118.  
    119. }
    Reward Ad Script

    Code (CSharp):
    1. using System;
    2. using System.Threading.Tasks;
    3. using Unity.Services.Core;
    4. using Unity.Services.Mediation;
    5. using UnityEngine;
    6.  
    7.  
    8. public class AdDisplay : MonoBehaviour, IDisposable
    9. {
    10.     IRewardedAd ad;
    11.     string adUnitId = "supportAd";
    12.     string gameId = "4493651";
    13.     int oneMoreLife;
    14.     bool haveBeenSeen = false;
    15.     //public GameObject panel;
    16.  
    17.     public void LetsBegin()
    18.     {
    19.         InitServices();
    20.         haveBeenSeen = false;
    21.     }
    22.     public async Task InitServices()
    23.     {
    24.         Debug.Log("Test InitService !");
    25.         try
    26.         {
    27.             InitializationOptions initializationOptions = new InitializationOptions();
    28.             initializationOptions.SetGameId(gameId);
    29.             await UnityServices.InitializeAsync(initializationOptions);
    30.  
    31.             InitializationComplete();
    32.         }
    33.         catch (Exception e)
    34.         {
    35.             InitializationFailed(e);
    36.         }
    37.     }
    38.  
    39.     public void SetupAd()
    40.     {
    41.         Debug.Log("Test Setup !");
    42.         //Create
    43.         ad = MediationService.Instance.CreateRewardedAd(adUnitId);
    44.  
    45.         //Subscribe to events
    46.         ad.OnClosed += AdClosed;
    47.         ad.OnClicked += AdClicked;
    48.         ad.OnLoaded += AdLoaded;
    49.         ad.OnFailedLoad += AdFailedLoad;
    50.         ad.OnUserRewarded += UserRewarded;
    51.  
    52.         // Impression Event
    53.         MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    54.     }
    55.  
    56.     public void Dispose() => ad?.Dispose();
    57.  
    58.  
    59.     public async void ShowAd()
    60.     {
    61.         Debug.Log("Test ShowAd !");
    62.    
    63.         if (ad.AdState == AdState.Loaded)
    64.         {
    65.             try
    66.             {
    67.                 RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
    68.                 showOptions.AutoReload = true;
    69.                 await ad.ShowAsync(showOptions);
    70.                 AdShown();
    71.             }
    72.             catch (ShowFailedException e)
    73.             {
    74.                 AdFailedShow(e);
    75.             }
    76.         }
    77.  
    78.     }
    79.  
    80.     public void InitializationComplete()
    81.     {
    82.         Debug.Log("Test InitilizationComplete !");
    83.    
    84.         SetupAd();
    85.         LoadAd();
    86.     }
    87.  
    88.     async Task LoadAd()
    89.     {
    90.         Debug.Log("Test LoadAd !");
    91.         try
    92.         {
    93.             await ad.LoadAsync();
    94.         }
    95.         catch (LoadFailedException)
    96.         {
    97.             // We will handle the failure in the OnFailedLoad callback
    98.         }
    99.     }
    100.  
    101.     void InitializationFailed(Exception e)
    102.     {
    103.         Debug.Log("Initialization Failed: " + e.Message);
    104.     }
    105.  
    106.     void AdLoaded(object sender, EventArgs e)
    107.     {
    108.         Debug.Log("Ad loaded");
    109.         if(!haveBeenSeen)
    110.         ShowAd();
    111.     }
    112.  
    113.     void AdFailedLoad(object sender, LoadErrorEventArgs e)
    114.     {
    115.         Debug.Log("Failed to load ad");
    116.         Debug.Log(e.Message);
    117.     }
    118.  
    119.     public void AdShown()
    120.     {
    121.         Debug.Log("Ad shown!");
    122.         int countNumerOfPart = 0;
    123.         PlayerPrefs.SetInt("countNumerOfPart", countNumerOfPart);
    124.         oneMoreLife = 1;
    125.         PlayerPrefs.SetInt("oneMoreLife", oneMoreLife);
    126.         // Give coins etc.
    127.         //if (panel != null)
    128.         //{
    129.             //panel.SetActive(false);
    130.         //}
    131.         //adStarted = false;
    132.         Time.timeScale = 1;
    133.    
    134.     }
    135.  
    136.     void AdClosed(object sender, EventArgs e)
    137.     {
    138.         Debug.Log("Ad has closed");
    139.         haveBeenSeen = true;
    140.         // Execute logic after an ad has been closed.
    141.     }
    142.  
    143.     void AdClicked(object sender, EventArgs e)
    144.     {
    145.         Debug.Log("Ad has been clicked");
    146.         // Execute logic after an ad has been clicked.
    147.     }
    148.  
    149.     void AdFailedShow(ShowFailedException e)
    150.     {
    151.         Debug.Log("Test AdFailedShow !");
    152.         Debug.Log(e.Message);
    153.     }
    154.  
    155.     void ImpressionEvent(object sender, ImpressionEventArgs args)
    156.     {
    157.         var impressionData = args.ImpressionData != null ? JsonUtility.ToJson(args.ImpressionData, true) : "null";
    158.         Debug.Log("Impression event from ad unit id " + args.AdUnitId + " " + impressionData);
    159.     }
    160.  
    161.     void UserRewarded(object sender, RewardEventArgs e)
    162.     {
    163.         Debug.Log($"Received reward: type:{e.Type}; amount:{e.Amount}");
    164.     }
    165. }
    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é
     
    Last edited: Jan 26, 2023
  2. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    Hello,

    No one can help me ?
     
  3. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    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.
     
  4. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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
     

    Attached Files:

  5. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    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 :)
     
  6. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    Sorry for the late reply,

    But yes I'm already using Ads Mediation :
    upload_2023-2-11_12-27-29.png

    But that isn't working ...
     
    Last edited: Feb 11, 2023
  7. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    No worries for the delay, we also tend to answer these whenever we have some spare time, so delays do occur. :)

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

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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 :
    https://drive.proton.me/urls/QJJEW8RBQG#unyuPsDKUMUv
     
  9. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    I would need to see the device logs and possibly the source code to offer more assistance.
     
  10. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    Source code is given in first comment.
    For the device logs, I'll do it as soon as possible
     
  11. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    Here is the logcat :
    that come from line 113 to line 117 of the script reward ad

    Code (csharp):
    1.  
    2.  
    3. [*]void AdFailedLoad(object sender, LoadErrorEventArgs e)
    4. [*]    {
    5. [*]        Debug.Log("Failed to load ad");
    6. [*]        Debug.Log(e.Message);
    7. [*]    }
    8.  

    And for the banner AD, The logcat is :
    this lines come from line 94 to line 99 of banner ad script
    Code (CSharp):
    1. void AdFailedLoad(object sender, LoadErrorEventArgs e)
    2.     {
    3.         Debug.Log("Test AdFailedLoad");
    4.         Debug.Log("Failed to load ad");
    5.         Debug.Log(e.Message);
    6.     }


    The scripts are in first comment
     
    Last edited: Feb 20, 2023
  12. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    Can anyone solved the "Failed To Load ..." issue ?
     
  13. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    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.
     
  14. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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
     
  15. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    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.
     
  16. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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


    upload_2023-3-3_15-5-7.png
     
  17. jcGrenier

    jcGrenier

    Unity Technologies

    Joined:
    Feb 23, 2021
    Posts:
    145
    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.
     
  18. Valentinhon

    Valentinhon

    Joined:
    Oct 20, 2019
    Posts:
    76
    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...