Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question can't see the test ads on Android

Discussion in 'Unity Mediation' started by JinT_Hwang, Oct 21, 2022.

  1. JinT_Hwang

    JinT_Hwang

    Joined:
    Mar 31, 2017
    Posts:
    2
    Hello everyone, I have a problem.

    I am using unity2021.3.11f1c2, and Mediation version is 1.0.4.

    I enabled test mode on dashboard, and I can see the test ads in the editor, but I can't see the test ads on Android phone, I printed the relevant logs and found that Android can initialize, but the Load failed, prompting no line item filled.

    I'm using Interstitial ads, and I haven't added a Store ID yet because my Google Store hasn't been approved yet.

    I thought it was because the keywords "await", "async" were not supported in Android, but after switching to Coroutine, I still can't see the test ads.

    The strangest thing is that the game I submitted to Google for review, I see real ads in Google's auto-test screenshot.

    This is the code I am currently using, and I believe I have written it correctly.And I make sure the Android game id and unit id in my code is the same as the dashboard.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Services.Core;
    5. using Unity.Services.Mediation;
    6. using System;
    7.  
    8. public class AdvertisementsManager : MonoBehaviour
    9. {
    10.     private readonly string gameId = "xxxxxxx";
    11.     private readonly string adUnitId = "Resurrection";
    12.  
    13.     public static AdvertisementsManager Instance;
    14.  
    15.     private IInterstitialAd interstitialAd;
    16.  
    17.     private WaitForSeconds waitTime = new(1);
    18.  
    19.     private bool isInitialized;
    20.     private void Awake()
    21.     {
    22.         if (Instance == null)
    23.         {
    24.             Instance = this;
    25.         }
    26.         else
    27.         {
    28.             Destroy(gameObject);
    29.         }
    30.     }
    31.  
    32.     void Start()
    33.     {
    34.         DontDestroyOnLoad(gameObject);
    35.  
    36.         StartCoroutine(InitAd());
    37.         StartCoroutine(KeepCheckLoading());
    38.     }
    39.  
    40.     private IEnumerator InitAd()
    41.     {
    42.         InitializationOptions options = new();
    43.         options.SetGameId(gameId);
    44.         UnityServices.InitializeAsync(options);
    45.  
    46.         while (UnityServices.State != ServicesInitializationState.Initialized)
    47.         {
    48.             yield return waitTime;
    49.         }
    50.  
    51.         interstitialAd = MediationService.Instance.CreateInterstitialAd(adUnitId);
    52.  
    53.         interstitialAd.OnLoaded += InterstitialAd_OnLoaded;
    54.         interstitialAd.OnFailedLoad += InterstitialAd_OnFailedLoad;
    55.         interstitialAd.OnShowed += InterstitialAd_OnShowed;
    56.         interstitialAd.OnFailedShow += InterstitialAd_OnFailedShow;
    57.         interstitialAd.OnClosed += InterstitialAd_OnClosed;
    58.  
    59.         print("Initialized");
    60.         isInitialized = true;
    61.     }
    62.  
    63.     private IEnumerator KeepCheckLoading()
    64.     {
    65.         while (true)
    66.         {
    67.             yield return waitTime;
    68.  
    69.             if (!isInitialized)
    70.                 continue;
    71.  
    72.             if (interstitialAd.AdState == AdState.Unloaded)
    73.             {
    74.                 LoadAd();
    75.             }
    76.         }
    77.     }
    78.  
    79.     public void LoadAd()
    80.     {
    81.         interstitialAd.LoadAsync();
    82.     }
    83.  
    84.     public void ShowAd()
    85.     {
    86.         if (interstitialAd.AdState == AdState.Loaded)
    87.             interstitialAd.ShowAsync();
    88.     }
    89.  
    90.     private void InterstitialAd_OnLoaded(object sender, EventArgs e)
    91.     {
    92.         print("Loaded");
    93.     }
    94.     private void InterstitialAd_OnShowed(object sender, EventArgs e)
    95.     {
    96.         print("Showed");
    97.     }
    98.     private void InterstitialAd_OnClosed(object sender, EventArgs e)
    99.     {
    100.         print("Closed");
    101.         if (BaseGameManager.Instance)
    102.             BaseGameManager.Instance.CloseGameLostPage();
    103.  
    104.         LoadAd();
    105.     }
    106.  
    107.     private void InterstitialAd_OnFailedLoad(object sender, LoadErrorEventArgs e)
    108.     {
    109.         print("OnFailedLoad:" + e.Message);
    110.     }
    111.  
    112.     private void InterstitialAd_OnFailedShow(object sender, ShowErrorEventArgs e)
    113.     {
    114.         print("OnFailedShow:" + e.Message);
    115.     }
    116. }
    117.  
     

    Attached Files:

    Last edited: Oct 21, 2022
  2. JinT_Hwang

    JinT_Hwang

    Joined:
    Mar 31, 2017
    Posts:
    2
    Also I'm in China, and I know I can't access Google directly, so I started vpn before opening the game, but I still can't see the test ads. And my phone has the google store.
    Any help would be greatly appreciated.
     
  3. DeclanMcPartlin

    DeclanMcPartlin

    Unity Technologies

    Joined:
    Nov 19, 2020
    Posts:
    146
    There's no need for Coroutines. This code is C#, it is later compiled in a way to run on Android (I won't get into specifics here, just know that as long as you are writing legit C# code, you'll be fine).

    Could you confirm with ad network you are testing specifically? If it is Unity Ads, we are currently experiencing issues with the test ads feature, I'll keep you posted once it is fixed. Include another ad network, like Admob to confirm you can see ads in the meantime. Apologies for the inconvenience, thanks for reaching out!