Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity Ads Never Play if No Internet During Initialization

Discussion in 'Unity Ads' started by kumagostudios, Aug 10, 2018 at 10:38 AM.

  1. kumagostudios

    kumagostudios

    Joined:
    Jul 29, 2017
    Posts:
    8
    Hello, I'm having a problem with ads not showing. If a user switches the internet off at the start of my game and then on later, Unity Ads always fails. Strangely enough Advertisement.isIntialized always returns true, but
    Advertisement.Show(AD_KEY) will always fail. This allows users to just turn their internet off and back on once the game has started to circumvent all ads. Advertisement.IsReady() never returns true even when I call Advertisement.Initialize(<id>); once internet is switched back on.

    If internet was on the entire time, this issue never arises. Does anyone know how to fix this? Thank you.
     
  2. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,124
    Ads SDK will automatically fetch campaigns when internet is available again, however the model is that we increase the time between retries (to avoid DDoS'ing our servers, in case of general internet blackout cases). So just wait a bit, then it should work. There is no need to call Initialize() again. And you should check IsReady() instead of isInitialized to see if ads are available to be shown.

    And regarding not showing ads in this case, did you see e.g. https://blogs.unity3d.com/2015/04/15/a-designers-guide-to-using-video-ads/ on rewarded ads, which actually gives users an incentive to watch ads, as they get some sort of reward in game, so not "wasting" their time.

    Thanks,
    Rasmus
     
    kumagostudios likes this.
  3. kumagostudios

    kumagostudios

    Joined:
    Jul 29, 2017
    Posts:
    8
    Thanks Rasmus, I was using IsReady() but it always returns false. What will trigger IsReady() to return true once internet is turned on? I've waited a LONG TIME after turning the internet back on but calling showAd still fails.

    Also https://blogs.unity3d.com/2015/04/15/a-designers-guide-to-using-video-ads/ and https://unityads.unity3d.com/help/monetization/integration-guide-unity seem to show two different implementations in that one polls for ads while the other is called once. Would you be able to confirm which implementation is correct?
     
    Last edited: Aug 10, 2018 at 12:16 PM
  4. kumagostudios

    kumagostudios

    Joined:
    Jul 29, 2017
    Posts:
    8
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using UnityEngine.Analytics;
    4.  
    5. public sealed class AdManager
    6. {
    7.     // Instance
    8.     private static AdManager _instance;
    9.     public static AdManager Instance
    10.     {
    11.         get
    12.         {
    13.             if (_instance == null) _instance = new AdManager();
    14.             return _instance;
    15.         }
    16.     }
    17.  
    18.     // Callback
    19.     public delegate void AdDelegate();
    20.     protected AdDelegate callback;
    21.    
    22.     // Ad Configuration
    23.     private const string AD_KEY = "video";
    24.  
    25.     #if UNITY_IOS
    26.     private const string GAME_ID = "xxx";
    27.     #elif UNITY_ANDROID
    28.     private const string GAME_ID = "xxx";
    29.     #endif
    30.  
    31.     // Class Initialization
    32.     private AdManager()
    33.     {
    34.         Advertisement.Initialize(GAME_ID);
    35.     }
    36.  
    37.     public void ShowAd(AdDelegate cb)
    38.     {
    39.         // If purchased remove ads, just run callback and skip rest
    40.         if (Preferences.item_removeAds > 0) {
    41.             Debug.Log ("Purchased Remove Ads.");
    42.             cb ();
    43.             return;
    44.         }
    45.  
    46.         if (Advertisement.IsReady(AD_KEY)) {
    47.             callback = cb; // used in another function
    48.             Preferences.AdCount += 1;
    49.             Advertisement.Show(AD_KEY, new ShowOptions(){ resultCallback = HandleShowResult });
    50.  
    51.             // Analytics: Ads
    52.             AnalyticsEvent.AdStart(false);
    53.         }
    54.     }
    55.  
    56.     private void HandleShowResult(ShowResult result)
    57.     {
    58.         switch (result)
    59.         {
    60.         case ShowResult.Finished:
    61.             AnalyticsEvent.AdComplete(false);
    62.             break;
    63.         case ShowResult.Skipped:
    64.             AnalyticsEvent.AdSkip(false);
    65.             break;
    66.         case ShowResult.Failed:
    67.             Debug.LogError ("Ad launch failed (internet?)");
    68.             break;
    69.         }
    70.  
    71.         callback();
    72.     }
    73. }
    74.  
    Here is my code if it helps.