Search Unity

Admob ads not displaying

Discussion in 'Scripting' started by Reymus, May 12, 2015.

  1. Reymus

    Reymus

    Joined:
    Apr 27, 2015
    Posts:
    44
    Hi all.

    In my android/iphone game, I'm trying to display admob ads. I followed the tutorial here: http://wewritecode.com/2014/04/13/setting-admob-android-ios-unity/

    When I run the code in Unity, I get the following in the console:

    Created DummyClient
    Dummy CreateBannerView
    Dummy LoadAd

    As far as I can tell, that suggests it's working properly, but no ads actually display in the game window. When I compile it to run on Android, it runs fine, but still no ads display.

    I've attached the ad script to my camera controller, as the tutorial said I should, and my code is as follows:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using GoogleMobileAds;
    4. using GoogleMobileAds.Api;
    5.  
    6. // Example script showing how to invoke the Google Mobile Ads Unity plugin.
    7. public class GoogleMobileAdsDemoScript : MonoBehaviour
    8. {
    9.  
    10.     private BannerView bannerView;
    11.     private InterstitialAd interstitial;
    12.  
    13.    
    14.  
    15.     private void Start()
    16.     {
    17.         Debug.Log ("Starting Ads Plugin");
    18.         #if UNITY_EDITOR
    19.             string adUnitId = "unused";
    20.         #elif UNITY_ANDROID
    21.             string adUnitId = "ca-app-pub-1585816329662741/6947689119";
    22.         #elif UNITY_IPHONE
    23.         string adUnitId = "ca-app-pub-1585816329662741/9621953912";
    24.         #else
    25.             string adUnitId = "unexpected_platform";
    26.         #endif
    27.  
    28.         // Create a 320x50 banner at the bottom of the screen.
    29.         bannerView = new BannerView("ca-app-pub-1585816329662741/6947689119", AdSize.SmartBanner, AdPosition.Bottom);
    30.  
    31.  
    32.         // Register for ad events.
    33.         bannerView.AdLoaded += HandleAdLoaded;
    34.         bannerView.AdFailedToLoad += HandleAdFailedToLoad;
    35.         bannerView.AdOpened += HandleAdOpened;
    36.         bannerView.AdClosing += HandleAdClosing;
    37.         bannerView.AdClosed += HandleAdClosed;
    38.         bannerView.AdLeftApplication += HandleAdLeftApplication;
    39.  
    40.         // Load a banner ad.
    41.         bannerView.LoadAd(createAdRequest());
    42.  
    43.  
    44.     }
    45.  
    46.     private void RequestInterstitial()
    47.     {
    48.         #if UNITY_EDITOR
    49.             string adUnitId = "unused";
    50.         #elif UNITY_ANDROID
    51.             string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";
    52.         #elif UNITY_IPHONE
    53.             string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
    54.         #else
    55.             string adUnitId = "unexpected_platform";
    56.         #endif
    57.  
    58.         // Create an interstitial.
    59.         interstitial = new InterstitialAd(adUnitId);
    60.         // Register for ad events.
    61.         interstitial.AdLoaded += HandleInterstitialLoaded;
    62.         interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
    63.         interstitial.AdOpened += HandleInterstitialOpened;
    64.         interstitial.AdClosing += HandleInterstitialClosing;
    65.         interstitial.AdClosed += HandleInterstitialClosed;
    66.         interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
    67.         // Load an interstitial ad.
    68.         interstitial.LoadAd(createAdRequest());
    69.     }
    70.  
    71.     // Returns an ad request with custom ad targeting.
    72.     private AdRequest createAdRequest()
    73.     {
    74.         Debug.Log ("Creating Ad Request");
    75.         return new AdRequest.Builder()
    76.                 .AddTestDevice(AdRequest.TestDeviceSimulator)
    77.                 .Build();
    78.  
    79.     }
    80.  
    81.     private void ShowInterstitial()
    82.     {
    83.         if (interstitial.IsLoaded())
    84.         {
    85.             interstitial.Show();
    86.         }
    87.         else
    88.         {
    89.             print("Interstitial is not ready yet.");
    90.         }
    91.     }
    92.  
    93.     #region Banner callback handlers
    94.  
    95.     public void HandleAdLoaded(object sender, EventArgs args)
    96.     {
    97.         print("HandleAdLoaded event received.");
    98.     }
    99.  
    100.     public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    101.     {
    102.         print("HandleFailedToReceiveAd event received with message: " + args.Message);
    103.     }
    104.  
    105.     public void HandleAdOpened(object sender, EventArgs args)
    106.     {
    107.         print("HandleAdOpened event received");
    108.     }
    109.  
    110.     void HandleAdClosing(object sender, EventArgs args)
    111.     {
    112.         print("HandleAdClosing event received");
    113.     }
    114.  
    115.     public void HandleAdClosed(object sender, EventArgs args)
    116.     {
    117.         print("HandleAdClosed event received");
    118.     }
    119.  
    120.     public void HandleAdLeftApplication(object sender, EventArgs args)
    121.     {
    122.         print("HandleAdLeftApplication event received");
    123.     }
    124.  
    125.     #endregion
    126.  
    127.     #region Interstitial callback handlers
    128.  
    129.     public void HandleInterstitialLoaded(object sender, EventArgs args)
    130.     {
    131.         print("HandleInterstitialLoaded event received.");
    132.     }
    133.  
    134.     public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    135.     {
    136.         print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
    137.     }
    138.  
    139.     public void HandleInterstitialOpened(object sender, EventArgs args)
    140.     {
    141.         print("HandleInterstitialOpened event received");
    142.     }
    143.  
    144.     void HandleInterstitialClosing(object sender, EventArgs args)
    145.     {
    146.         print("HandleInterstitialClosing event received");
    147.     }
    148.  
    149.     public void HandleInterstitialClosed(object sender, EventArgs args)
    150.     {
    151.         print("HandleInterstitialClosed event received");
    152.     }
    153.  
    154.     public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    155.     {
    156.         print("HandleInterstitialLeftApplication event received");
    157.     }
    158.  
    159.     #endregion
    160. }
    161.  
    So, what am I doing wrong?
     
  2. 5vStudios

    5vStudios

    Joined:
    May 9, 2015
    Posts:
    106
    have you tested it on an actual android device ?

    from the log above i assume you ran it in the editor
     
  3. Reymus

    Reymus

    Joined:
    Apr 27, 2015
    Posts:
    44
    I ran it in the editor, as well as on an Android emulator, two Samsung Note 4's, and a couple of Android phones. The ads work on none of them.
     
  4. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    I would suggest using VNTIS's admob plugin.

    You can get it from here.
     
  5. Reymus

    Reymus

    Joined:
    Apr 27, 2015
    Posts:
    44
    The admob plugin by VNTIS apparently only works for Android, and not for iPhone. We're releasing for both systems.

    I suppose I can use that plugin for a month or so while we're finalizing the company setup so we can get our iOS dev license, but we will need a complete solution to the problem by then...
     
    anycolourulike likes this.
  6. Reymus

    Reymus

    Joined:
    Apr 27, 2015
    Posts:
    44
    Checked out the VNTIS's AdMob plugin. It seemed to have the same issue. I'm not sure what's going on there....

    The ads just don't display.
     
    anycolourulike likes this.
  7. atotheroh

    atotheroh

    Joined:
    Jun 21, 2015
    Posts:
    4
    Hate to resurrect an old thread, but I am having the exact same issue.

    I have scoured information online trying to solve this and nothing works. I have tried every combination of manifest.xml arrangements I can think of and nothing will make ads show on my devices. They appear to load fine in the Unity player though, by the same logic you used ("Dummy show interstitial", etc.).

    Did you ever find a solution to this?
     
    anycolourulike and Moriot like this.
  8. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    Same problem here, ads work fine on older versions but do not appear on ios 9 =/
     
    anycolourulike likes this.
  9. joneman

    joneman

    Joined:
    Mar 5, 2016
    Posts:
    8
    You can try this Unity-Admob-Plugin ,It support ios and android with the same code
     
    Adishah11 likes this.
  10. Adishah11

    Adishah11

    Joined:
    Aug 10, 2015
    Posts:
    9
  11. Mercbaker

    Mercbaker

    Joined:
    Apr 18, 2017
    Posts:
    18
    Seeing as no one has clearly answered this question...

    When testing any ads you need to get the .apk onto the device, then install, then open the app on the device.

    You cannot test ads with the Unity emulator.

    Additionally if you are TESTING an ad you need to build a test advertisement and assign your testing device ID, build the following AdRequest:

    Code (CSharp):
    1.  request = new AdRequest.Builder()
    2.     .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
    3.     .AddTestDevice(SystemInfo.deviceUniqueIdentifier)  // My test device.
    4. .Build();
    SystemInfo.deviceUniqueIdentifier returns your devices unique 'Device Id'.

    Also, when defining the Banner (or any test Ad) use the testing ID's provided by the Google Doc @
    Sample Ad Units

    example:
    Code (CSharp):
    1. bannerView = new BannerView([B]sample_ad_unit_[/B], AdSize.SmartBanner, AdPosition.Top);
    If you are running a live ad keep in mind that AdMob can take 24 hours to link your ap to their servers. So if you filled out your AdMob account with your Ap details you probably will not see any live ads until the next day.

    And remember... DO NOT, click your own live ads, its a good way to get your AdMob account banned. You can click test ads when testing.

     
  12. zeyneptopalll

    zeyneptopalll

    Joined:
    Jun 11, 2019
    Posts:
    1
    hey i have a similar problem ,on the console i got the same output but app doesnt open in android studio.
     
  13. blinovalexei97

    blinovalexei97

    Joined:
    Apr 20, 2019
    Posts:
    8
    You will not see even TestAds if you only recently made an appId for your google admob? So you'll have to wait 24 hours? I followed the instructions as I could, added the test device info for the AdRequest builder but it still doesn't work.
     
    carloshasaidea likes this.
  14. KratosBelmont

    KratosBelmont

    Joined:
    Jul 11, 2015
    Posts:
    4
    I have the same problem, I did everything there is to fre, but nothing does not break the ads on smartphones android... help :(
     
  15. rahul20dec

    rahul20dec

    Joined:
    Jul 8, 2018
    Posts:
    9
    For me ads didn't show up in the unity editor but worked on android device. I used test ad unit ID.
     
    Last edited: Aug 8, 2019
  16. BenThomas5

    BenThomas5

    Joined:
    Jul 23, 2019
    Posts:
    10
    Hi,If test ads are working there is no problem with your ads integration .At present admob ads shows within 24-48 hrs (i mean real ads) Previously they used to show within 10 minutes after integration .I suggest you to generate signed copy of apk and try it on real device.They are not showing real ads when debugged.This is my recent findings :p
     
  17. aboazar

    aboazar

    Joined:
    Jan 17, 2017
    Posts:
    4
    It happened to me recently, my problem was that I forgot to call Initialize "MobileAds.Initialize()", maybe that would help :)
     
  18. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    I'm getting the same thing, no ads showing and those "Dummy .ctor/Dummy CreateBannerView/Dummy LoadAd" prints in the Unity Console.

    I've followed the Google Developers tutorial as well as a YouTube video from AwesomeTuts (basically follows the Google Dev documentation).

    No ads show in either Unity when hitting Play or when installing the apk on my phone. I have the device set for test ads shown in the following code (which is in the Start method for an empty GameObject named AdManager).

    Code (CSharp):
    1. MobileAds.Initialize(initStatus => { });
    2.  
    3.         string adUnitId = @"ca-app-pub-3940256099942544/6300978111"; // test ID
    4.  
    5.         // create a 320x50 banner at the top of the screen
    6.         bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
    7.  
    8.         // I also have the OnAdXYZ event handlers assigned here but they just write to Console using Debug.Log
    9.  
    10. AdRequest request = new AdRequest.Builder()
    11.             .AddTestDevice(AdRequest.TestDeviceSimulator)
    12.             .AddTestDevice(SystemInfo.deviceUniqueIdentifier)
    13.             .Build();
    14.  
    15. // load the banner with the request
    16.         bannerView.LoadAd(request);
    17.  
    I did sign up for an AdMob account about 24 hours ago so I dunno if that's related. Seems like Test ads should still show though, right?
     
  19. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    As an update, in another thread on this topic a guy said he simply solved it by adding "bannerView.Show()" call to the end, as the documentation forgot it apparently.

    Didn't work for me though. I put the bannerView.Show() call after all my other code, after the "bannerView.LoadAd(request)" line, and that didn't worked. So I also tried putting it in my "HandleOnAdLoaded" event handler method, and no dice there either.

    I'm hoping it's just because I signed up for AdMob 24 hours ago but I dunno... seems odd.
     
  20. Kumsan

    Kumsan

    Joined:
    Apr 28, 2015
    Posts:
    2
    did anybody solve this?
     
  21. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    I wish.

    I ended up getting an asset that takes care of the AdMob implemention (and other ad systems) itself but I had to revert my project back to a month old backup cause it got all crapped up. So I haven't been able to use that asset yet lol. Hopefully it works though.
     
  22. Brad3355

    Brad3355

    Joined:
    Aug 5, 2017
    Posts:
    14
    I have same problem? Using admob with the easy mobile pro asset. Problem existed before i installed easy mobile, that it why i installed easy mobile to try to fix it. Everything works in android ok. Test ads work perfectly in ios but not real ads. "No ads to show" error. Have tested on real devices. I can see in the admob console that the app has made over 400 requests, not 1 impression. The admob ids were set up months ago. I notice in the admob settings you can provide a url for the app store once it is published. Will that make it work? I dont really want to release it until i am sure ads work. But may be i need to, to link it. Too scary publishing not knowing if your ads work, i have read other posts of users who have published and still have no ads months later. What are we meant to do. Use a different ad network may be?
     
  23. Brad3355

    Brad3355

    Joined:
    Aug 5, 2017
    Posts:
    14
    I just need one person to say, "trust me it will work once published" Then i will release and see and report back here if it worked and how long it took for ads to start running. Someone, anyone? Or any other checks i can do first?
     
    polyphonic13 likes this.
  24. polyphonic13

    polyphonic13

    Joined:
    Apr 2, 2013
    Posts:
    17
    I'm right there with you, @Brad3355 . I've successfully implemented AdMob for Android in 3 games. I've continually had problems with AdMob and iOS though. Last game, there were conflicts with UIWebView being added to the build which prevented XCode from uploading. This current game, everything works fine until I get to running the iOS build on an iPhone. Then, I see this gem of an error: "Invalid Request. Cannot determine request type. Is your ad unit id correct?". The settings in Unity are correct with AdId and AdUnitIds, as evidenced by the live Android version. My app and placements in AdMob are over 48 hours old, but I don't yet have an App Store link. I am wondering the same thing: will putting the app store link in the AdMob console resolve this?
     
  25. AuzkyA

    AuzkyA

    Joined:
    Mar 10, 2019
    Posts:
    2
    @polyphonic13 Did you test your theory? My Interstitial test add is properly showing in the Unity editor using either button or calling the function in code. But when i build it, suddenly i cant open the add by calling the ShowInterstitial() function in code. Any Ideas?
     
    polyphonic13 likes this.
  26. polyphonic13

    polyphonic13

    Joined:
    Apr 2, 2013
    Posts:
    17
    I gave up and switched to Yodo1