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

admob in unity only shows test ads but not real ones

Discussion in 'Unity Ads & User Acquisition' started by hamzalahlou, Feb 12, 2019.

  1. hamzalahlou

    hamzalahlou

    Joined:
    Feb 4, 2019
    Posts:
    1
    i am using the default script given by unity

    here is my script

    using System;
    using UnityEngine;
    using GoogleMobileAds.Api;

    // Example script showing how to invoke the Google Mobile Ads Unity plugin.
    public class GoogleMobileAdsDemoScript : MonoBehaviour
    {
    private BannerView bannerView;
    private InterstitialAd interstitial;
    private RewardBasedVideoAd rewardBasedVideo;
    private float deltaTime = 0.0f;
    private static string outputMessage = string.Empty;

    public static string OutputMessage
    {
    set { outputMessage = value; }
    }

    public void Start()
    {

    #if UNITY_ANDROID
    string appId = "ca-app-pub-7331080538239612~4266231032";
    #elif UNITY_IPHONE
    string appId = "ca-app-pub-3940256099942544~1458002511";
    #else
    string appId = "unexpected_platform";
    #endif

    MobileAds.SetiOSAppPauseOnBackground(true);

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

    // Get singleton reward based video ad reference.
    this.rewardBasedVideo = RewardBasedVideoAd.Instance;

    // RewardBasedVideoAd is a singleton, so handlers should only be registered once.
    this.rewardBasedVideo_OnAdLoaded += this.HandleRewardBasedVideoLoaded;
    this.rewardBasedVideo_OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
    this.rewardBasedVideo_OnAdOpening += this.HandleRewardBasedVideoOpened;
    this.rewardBasedVideo_OnAdStarted += this.HandleRewardBasedVideoStarted;
    this.rewardBasedVideo_OnAdRewarded += this.HandleRewardBasedVideoRewarded;
    this.rewardBasedVideo_OnAdClosed += this.HandleRewardBasedVideoClosed;
    this.rewardBasedVideo_OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
    }

    public void Update()
    {
    // Calculate simple moving average for time to render screen. 0.1 factor used as smoothing
    // value.
    this.deltaTime += (Time.deltaTime - this.deltaTime) * 0.1f;
    }

    public void OnGUI()
    {
    GUIStyle style = new GUIStyle();

    Rect rect = new Rect(0, 0, Screen.width, Screen.height);
    style.alignment = TextAnchor.LowerRight;
    style.fontSize = (int)(Screen.height * 0.06);
    style.normal.textColor = new Color(0.0f, 0.0f, 0.5f, 1.0f);
    float fps = 1.0f / this.deltaTime;
    string text = string.Format("{0:0.} fps", fps);
    GUI.Label(rect, text, style);

    // Puts some basic buttons onto the screen.
    GUI.skin.button.fontSize = (int)(0.035f * Screen.width);
    float buttonWidth = 0.35f * Screen.width;
    float buttonHeight = 0.15f * Screen.height;
    float columnOnePosition = 0.1f * Screen.width;
    float columnTwoPosition = 0.55f * Screen.width;

    Rect requestBannerRect = new Rect(
    columnOnePosition,
    0.05f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(requestBannerRect, "Request\nBanner"))
    {
    this.RequestBanner();
    }

    Rect destroyBannerRect = new Rect(
    columnOnePosition,
    0.225f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(destroyBannerRect, "Destroy\nBanner"))
    {
    this.bannerView.Destroy();
    }

    Rect requestInterstitialRect = new Rect(
    columnOnePosition,
    0.4f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(requestInterstitialRect, "Request\nInterstitial"))
    {
    this.RequestInterstitial();
    }

    Rect showInterstitialRect = new Rect(
    columnOnePosition,
    0.575f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(showInterstitialRect, "Show\nInterstitial"))
    {
    this.ShowInterstitial();
    }

    Rect destroyInterstitialRect = new Rect(
    columnOnePosition,
    0.75f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(destroyInterstitialRect, "Destroy\nInterstitial"))
    {
    this.interstitial.Destroy();
    }

    Rect requestRewardedRect = new Rect(
    columnTwoPosition,
    0.05f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(requestRewardedRect, "Request\nRewarded Video"))
    {
    this.RequestRewardBasedVideo();
    }

    Rect showRewardedRect = new Rect(
    columnTwoPosition,
    0.225f * Screen.height,
    buttonWidth,
    buttonHeight);
    if (GUI.Button(showRewardedRect, "Show\nRewarded Video"))
    {
    this.ShowRewardBasedVideo();
    }

    Rect textOutputRect = new Rect(
    columnTwoPosition,
    0.925f * Screen.height,
    buttonWidth,
    0.05f * Screen.height);
    GUI.Label(textOutputRect, outputMessage);
    }

    // Returns an ad request with custom ad targeting.
    private AdRequest CreateAdRequest()
    {
    return new AdRequest.Builder()

    .AddKeyword("game")
    .SetGender(Gender.Male)
    .SetBirthday(new DateTime(1985, 1, 1))
    .TagForChildDirectedTreatment(false)
    .AddExtra("color_bg", "9B30FF")
    .Build();
    }

    private void RequestBanner()
    {
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-7331080538239612/7895975540";
    #elif UNITY_IPHONE
    string adUnitId = "ca-app-pub-3940256099942544/2934735716";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Clean up banner ad before creating a new one.
    if (this.bannerView != null)
    {
    this.bannerView.Destroy();
    }

    // Create a 320x50 banner at the top of the screen.
    this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);

    // Register for ad events.
    this.bannerView.OnAdLoaded += this.HandleAdLoaded;
    this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
    this.bannerView.OnAdOpening += this.HandleAdOpened;
    this.bannerView.OnAdClosed += this.HandleAdClosed;
    this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;

    // Load a banner ad.
    this.bannerView.LoadAd(this.CreateAdRequest());
    }

    private void RequestInterstitial()
    {
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-7331080538239612/5269812208";
    #elif UNITY_IPHONE
    string adUnitId = "ca-app-pub-3940256099942544/4411468910";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Clean up interstitial ad before creating a new one.
    if (this.interstitial != null)
    {
    this.interstitial.Destroy();
    }

    // Create an interstitial.
    this.interstitial = new InterstitialAd(adUnitId);

    // Register for ad events.
    this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded;
    this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad;
    this.interstitial.OnAdOpening += this.HandleInterstitialOpened;
    this.interstitial.OnAdClosed += this.HandleInterstitialClosed;
    this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication;

    // Load an interstitial ad.
    this.interstitial.LoadAd(this.CreateAdRequest());
    }

    private void RequestRewardBasedVideo()
    {
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-7331080538239612/4107099301";
    #elif UNITY_IPHONE
    string adUnitId = "ca-app-pub-3940256099942544/1712485313";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    this.rewardBasedVideo.LoadAd(this.CreateAdRequest(), adUnitId);
    }

    private void ShowInterstitial()
    {
    if (this.interstitial.IsLoaded())
    {
    this.interstitial.Show();
    }
    else
    {
    MonoBehaviour.print("Interstitial is not ready yet");
    }
    }

    private void ShowRewardBasedVideo()
    {
    if (this.rewardBasedVideo.IsLoaded())
    {
    this.rewardBasedVideo.Show();
    }
    else
    {
    MonoBehaviour.print("Reward based video ad is not ready yet");
    }
    }

    #region Banner callback handlers

    public void HandleAdLoaded(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleAdLoaded event received");
    }

    public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    MonoBehaviour.print("HandleFailedToReceiveAd event received with message: " + args.Message);
    }

    public void HandleAdOpened(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleAdOpened event received");
    }

    public void HandleAdClosed(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleAdClosed event received");
    }

    public void HandleAdLeftApplication(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleAdLeftApplication event received");
    }

    #endregion

    #region Interstitial callback handlers

    public void HandleInterstitialLoaded(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleInterstitialLoaded event received");
    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    MonoBehaviour.print(
    "HandleInterstitialFailedToLoad event received with message: " + args.Message);
    }

    public void HandleInterstitialOpened(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleInterstitialOpened event received");
    }

    public void HandleInterstitialClosed(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleInterstitialClosed event received");
    }

    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleInterstitialLeftApplication event received");
    }

    #endregion

    #region RewardBasedVideo callback handlers

    public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
    }

    public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    MonoBehaviour.print(
    "HandleRewardBasedVideoFailedToLoad event received with message: " + args.Message);
    }

    public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
    }

    public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
    }

    public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
    }

    public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
    string type = args.Type;
    double amount = args.Amount;
    MonoBehaviour.print(
    "HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
    }

    public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
    }

    #endregion
    }
     

    Attached Files:

  2. surbhishukla38

    surbhishukla38

    Joined:
    Mar 11, 2019
    Posts:
    4
    I am facing similar issue and i am also using the same script that i downloaded from github ..

    Things were working perfectly before .but on my new game its no more showings real ads..however shows in editor



    If you resolved the issue then plz inform me....
     
  3. Phoenix116

    Phoenix116

    Joined:
    Jun 30, 2016
    Posts:
    39
  4. unity_YpnYiWvZ0GXMQA

    unity_YpnYiWvZ0GXMQA

    Joined:
    Apr 23, 2019
    Posts:
    1
    I am facing similar issue. Test ads works as they should but when i place real numbers (APP ID etc) ads not showing. Did you solve the problem ?
     
  5. Paracetamlol

    Paracetamlol

    Joined:
    Sep 25, 2019
    Posts:
    3
    problem solved ?
     
  6. jmansa

    jmansa

    Joined:
    Apr 13, 2012
    Posts:
    75
    Have the same issue... The app already in app-store and working with reals ads, but am about to make an update, but only seeng test ads?!?!? any idea anyone?
     
  7. intelviji

    intelviji

    Joined:
    Mar 31, 2020
    Posts:
    1
    I am also having the same issue. Anyone resolved it? Test ID is showing but real ID is not showing.
     
  8. Knipsch

    Knipsch

    Joined:
    Sep 12, 2018
    Posts:
    7
    I'm also having the same issue. Hopefully it gets resolved soon!
     
  9. yogummben

    yogummben

    Joined:
    Mar 10, 2020
    Posts:
    6
    I'm also having the same issue. omg
     
  10. Knipsch

    Knipsch

    Joined:
    Sep 12, 2018
    Posts:
    7
    In my case, it was because there was an ad ID mismatch in the AdMob console. I did get it resolved once I went through that and made sure everything was correct.
     
  11. PXTurtle

    PXTurtle

    Joined:
    Aug 4, 2021
    Posts:
    1
    Same issue here
     
  12. Unity-Boon

    Unity-Boon

    Unity Technologies

    Joined:
    Jan 18, 2017
    Posts:
    135
    Can you check your project dashboard, and make sure it is not configured for Test Ads under the Monetization project settings?

    https://dashboard.unity3d.com/