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

Sometimes Advertisement.Show() is successful but no ads show up

Discussion in 'Unity Ads & User Acquisition' started by CaptainKiyaku, Jan 27, 2017.

  1. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Hi,

    i implemented UnityAds into our iOS project today but once in a while they seem to not work and block input to the game until you either minimize the app and bring it up again, or sometimes just wait for several minutes.

    Basically i have a "Watch ad" button and once the user clicks it, it triggers something like this:

    Code (CSharp):
    1. if(Advertisement.isReady()) {
    2.   adButton.interactable = false;
    3.   Advertisement.Show();
    4. }
    I can see the button getting disabled and XCode log shows that it's trying to display the ad.

    Code (CSharp):
    1. 2017-01-26 15:09:43.413385 appName[354:37740] I/UnityAds: +[UnityAds show:placementId:] (line:111) :: Unity Ads opening new ad unit for placement video
    2.  
    3. 2017-01-26 15:09:43.773209 appName[354:37999] I/UnityAds: +[UADSApiSdk WebViewExposed_logInfo:callback:] (line:57) :: Opening performance ad with orientation 24
    But nothing happens and i can no longer interact with anything else in my game, it's like it opened a new invisible window on top of my game, but without showing the ads. Like i mentioned, sometimes just waiting for several minutes makes the ad eventually show up, but also minimizing/maximizing the game works.

    This is what xcode prints out when an add shows up successfully:

    Code (CSharp):
    1. 2017-01-26 15:09:43.413385 appName[354:37740] I/UnityAds: +[UnityAds show:placementId:] (line:111) :: Unity Ads opening new ad unit for placement video
    2.  
    3. 2017-01-26 15:09:43.773209 appName[354:37999] I/UnityAds: +[UADSApiSdk WebViewExposed_logInfo:callback:] (line:57) :: Opening performance ad with orientation 24
    4.  
    5. 2017-01-26 15:09:45.326384 appName[354:37999] I/UnityAds: +[UADSApiSdk WebViewExposed_logInfo:callback:] (line:57) :: Unity Ads event: sending start event to https://adserver.unityads.unity3d.com/mobile/gamers/50507b163822f20000000001/video/video_start/000000000000000000000000/1273152
    As you can see it has a third line at the bottom that seems to return the proper ad video URL, that line is missing whenever it fails.

    I tried this with Unity 5.5.0f3 and 5.5.1, tried both using ads through the Services window and also through the package from the Asset Store. Nothing seems to make a difference really.

    Has anyone else run into this issue before? Any idea what this could be?

    Thanks,
    Sven
     
  2. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Hi,

    Thanks for bringing this up!

    There are known issues with these editor versions, but it should be fixed if you disable the services integration for Ads and use the Asset Store package:
    https://forum.unity3d.com/threads/b...5-1-if-using-ads-from-services-window.453084/

    After doing the Asset Store integration, have you tried rebuilding and uninstalling / reinstalling?

    If your issue persists - can you send an e-mail to unityads-support@unity3d.com along with your project so that we can investigate it further.
     
  3. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Hey,

    thanks for getting back so quickly!

    yeah i did try to disable the services integration and use the asset store package, but that didn't seem to have helped.
    Basically i started in 5.5.0, used the service integration, ran into the problem, read here that that might cause issues in certain versions, disabled the services, downloaded and used the package, didnt work, then upgraded to 5.5.1 and tried with the package only, no success.

    When i built the project in 5.5.1, i did a "replace", but i'll try deleting the xcode folder all together and make a clean one.

    Besides having to use the package, do you think there is anything else that could possibly help? Any temporary work arounds?

    Might not be able to send this project over but i'll double check, or i might try it in an empty one with just the ads stuff, to see if that causes issues too.

    Thanks!
     
  4. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Not sure if helpful at all, but i enabled the debug mode for Advertisement, this is the last entry when it breaks, nothing happens afterwards (unless i minimize, etc):


    Code (CSharp):
    1.  
    2. 2017-01-27 03:03:12.261136 appName[444:98260] I/UnityAds: +[UADSApiSdk WebViewExposed_logInfo:callback:] (line:57) :: Opening performance ad with orientation 24
    3.  
    4. 2017-01-27 03:03:12.261308 appName[444:98260] D/UnityAds: -[UADSWebViewApp invokeJavascriptMethod:className:params:] (line:68) :: JS_STRING: window.nativebridge.handleCallback([["461","OK",[]]]);
    5.  
    6. 2017-01-27 03:03:12.325130 appName[444:98260] D/UnityAds: -[UADSURLProtocol handleInvocation:] (line:98) :: (
    7.         (
    8.         UADSApiAdUnit,
    9.         open,
    10.                 (
    11.                         (
    12.                 videoplayer,
    13.                 webview
    14.             ),
    15.             24,
    16.             1,
    17.             1
    18.         ),
    19.         462
    20.     )
    21. )
    22.  
    23. 2017-01-27 03:03:12.325590 appName[444:98260] D/UnityAds: -[UADSWebViewApp invokeJavascriptMethod:className:params:] (line:68) :: JS_STRING: window.nativebridge.handleCallback([["462","OK",[]]]);
    24.  
    25. 2017-01-27 03:03:12.353047 appName[444:97958] D/UnityAds: __101+[UADSApiAdUnit WebViewExposed_open:supportedOrientations:statusBarHidden:shouldAutorotate:callback:]_block_invoke (line:32) :: PRESENTING VIEWCONTROLLER
    26.  
    27. 2017-01-27 03:03:12.353912 appName[444:97958] D/UnityAds: -[UADSWebViewApp invokeJavascriptMethod:className:params:] (line:68) :: JS_STRING: window.nativebridge.handleEvent(["ADUNIT","VIEW_CONTROLLER_DID_LOAD"]);
    28.  
    29. 2017-01-27 03:03:12.354094 appName[444:97958] D/UnityAds: -[UADSWebViewApp invokeJavascriptMethod:className:params:] (line:68) :: JS_STRING: window.nativebridge.handleEvent(["ADUNIT","VIEW_CONTROLLER_INIT"]);
    30.  
    31. 2017-01-27 03:03:15.791766 appName[444:97958] D/UnityAds: __72-[UADSAppSheet prepareAppSheet:prepareTimeoutInSeconds:completionBlock:]_block_invoke.43 (line:73) :: Preloading product information succeeded for id: 453467175.
    32.  
    33. 2017-01-27 03:03:15.792097 appName[444:97958] D/UnityAds: -[UADSWebViewApp invokeJavascriptMethod:className:params:] (line:68) :: JS_STRING: window.nativebridge.handleEvent(["APPSHEET","PREPARED",{"id":453467175}]);
     
  5. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Hi,

    How did you integrate the Asset Store package? Did you remember to run Advertisement.Initialize(gameId,testMode); ?

    After that, did you wait until Advertisement.IsReady() returns true before trying to run Show()?

    Other than that - I'd like to see a screenshot of your services window and perhaps UnityConnectSettings.asset under ProjectSettings (fist, change the asset serialization to text only from Editor preferences) https://docs.unity3d.com/Manual/class-EditorManager.html

    Yeah, try cleaning the xcode project as well.
     
  6. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Hey,

    yeah i do call Initialize in the start of my GameManager script (which has DontDestroyOnLoad enabled). This does not need to be called before every ad call, correct?

    Exact code is here:
    Code (CSharp):
    1. // in my gamemanager
    2. private void Start() {
    3.     string gameId = null;
    4.  
    5.     // not using android yet
    6.     #if UNITY_ANDROID
    7.             gameId = "";
    8.     #elif UNITY_IOS
    9.             gameId = "1273152";
    10.     #endif
    11.  
    12.     if (Advertisement.isSupported && !Advertisement.isInitialized) {
    13.         //Advertisement.debugMode = true;
    14.         Advertisement.Initialize(gameId, false);
    15.     }
    16. }
    17.  
    18.  
    19.  
    20.  
    21. // In my ads script, gets called much later than the initialize
    22. public void WatchAd() {
    23.     if (!watchedAd) {
    24.         WatchAdButton.interactable = false;
    25.         StartCoroutine(ShowAd());
    26.     } else {
    27.         WatchAdButton.interactable = false;
    28.         isOpen = true;
    29.     }
    30. }
    31.  
    32.  
    33. private IEnumerator ShowAd() {
    34.     while (!Advertisement.IsReady()) {
    35.         yield return new WaitForEndOfFrame();
    36.     }
    37.  
    38.     // tried both with and without
    39.     //yield return null;
    40.  
    41.     // isReady/inInitialized print out true in the logs, even in cases where ads dont show up
    42.     Debug.Log("Advertisement is ready: " + Advertisement.IsReady());
    43.     Debug.Log("Advertisement is initialized: " + Advertisement.isInitialized);
    44.     Debug.Log("Advertisement is showing: " + Advertisement.isShowing);
    45.  
    46.     var options = new ShowOptions { resultCallback = HandleShowResult };
    47.     Advertisement.Show(options);
    48.  
    49.     yield return null;
    50. }

    Also here is my services window and my UnityConnectSettings.asset:


    Code (CSharp):
    1. %YAML 1.1
    2. %TAG !u! tag:unity3d.com,2011:
    3. --- !u!310 &1
    4. UnityConnectSettings:
    5.   m_ObjectHideFlags: 0
    6.   m_Enabled: 0
    7.   m_TestMode: 0
    8.   m_TestEventUrl:
    9.   m_TestConfigUrl:
    10.   CrashReportingSettings:
    11.     m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes
    12.     m_Enabled: 1
    13.     m_CaptureEditorExceptions: 1
    14.   UnityPurchasingSettings:
    15.     m_Enabled: 1
    16.     m_TestMode: 0
    17.   UnityAnalyticsSettings:
    18.     m_Enabled: 1
    19.     m_InitializeOnStartup: 1
    20.     m_TestMode: 0
    21.     m_TestEventUrl:
    22.     m_TestConfigUrl:
    23.   UnityAdsSettings:
    24.     m_Enabled: 0
    25.     m_InitializeOnStartup: 1
    26.     m_TestMode: 0
    27.     m_EnabledPlatforms: 4294967295
    28.     m_IosGameId: 0
    29.     m_AndroidGameId: 0
    Just deleted my xcode folder and made a fresh build (just build, not build & run). Still stops working once in a while unfortunately.

    Hope this helps!

    Thanks,
    Sven
     
  7. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Heya,

    any news on this? Any ideas or anything i could provide still that may help out?

    Thanks,
    Sven
     
  8. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Hi,

    Thanks for providing this. Nothing unusual there though.

    Yes - you only need to initialize ads in the beginning. After that - you need to wait until Advertisement.IsReady() returns true. Then you can run Advertisement.Show();

    Maybe you're showing too many ads? There's a limit of 25 ads per user per day. To avoid this - use test mode or add your device advertising ID to the list of test devices from the https://dashboard.unityads.unity3d.com
     
  9. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Hey,

    i am using test mode through the Advertisement.Initialize("id", true);
    Is there a difference between this one and the one on the dashboard?

    And yes like i mentioned before a few times, i do wait for IsReady before i even call the Show.

    I know i'm terrible at explaining things sometimes, but to summarize what is happening:
    • I click a button
    • The button checks if Advertisement.IsReady returns true
    • Only if it returns true, i call Advertisement.Show()
    • 9 out of 10 times (not the actual numbers, it's random) it brings up the ad ViewController properly and displays the app
    • The other 1 out of 10 times it brings up the ViewController which is completely empty and transparent. No ad is loading unless i minimize to the desktop and bring up the app again. This empty view controller (not sure if that's 100% what it is, but let's call it that for now to make it easier) is blocking input to my app
    I tried some "bruteforcing" as well by forcing a 2nd Show() if the empty viewcontroller shows up without actually showing an ad but the xcode log says that it failed cause an ad is already being displayed (which is not true).

    Since there is no Advertisement.Cancel() or something, i can no longer interact with my app unless i do the minimize thing or restart.
     
  10. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Okay - can you send a support ticket to unityads-support@unity3d.com and preferably include your project so that we can investigate it closer?
     
  11. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    We found a solution, posting it here in case anyone else runs into the same issue.

    Ended up talking to support via email and they brought up the following:
    Our CPU usage was very high during this scene which seems to what have caused the ad view controller not showing up properly once in a while.

    Reducing the CPU usage by quite a bit seemed to have helped, now it pops up 100% of the time.
     
  12. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    82
    We're having the same issue where it runs perfectly fine 9/10 times but just hangs every now and then on iOS.

    CPU on iPhone6 tends to be used in the region of 50%. @CaptainKiyaku do you remember what CPU usage percentages you had in your case?

    We've seen this happen across the board though. (iPhone 7,8 and X)
    This doesn't happen when we test in 'Test mode'. Is that a valid real-world test though?
     
    Last edited: May 27, 2019