Search Unity

Question about ad placement when testmode = true

Discussion in 'Unity Ads & User Acquisition' started by Banglemoose, Jan 8, 2015.

  1. Banglemoose

    Banglemoose

    Joined:
    Dec 9, 2014
    Posts:
    9
    Hi,

    I have implemented some code that I found in a different thread:

    Code (CSharp):
    1. public static void ShowRewardedAd ()
    2. {
    3.     string zoneID = "rewardedVideoZone";
    4.     // If the value of zoneID is an empty string, set the value to null.
    5.     //  The default zone is used when the value of zoneID is null.
    6.     if (string.IsNullOrEmpty(zoneID)) zoneID = null;
    7.     ShowOptions options = new ShowOptions();
    8.     options.pause = true;                        // Pauses game while ads are shown
    9.     options.resultCallback = HandleShowResult;   // Triggered when the ad is closed
    10.     Advertisement.Show(zoneID,options);
    11. }
    12. public static void HandleShowResult (ShowResult result)
    13. {
    14.     switch (result)
    15.     {
    16.     case ShowResult.Finished:
    17.         // Add code here to rewarding players for watching ads without skipping.
    18.         //  Note: This will be the same result for picture ads when shown.
    19.         Debug.Log("The ad was successfully shown.");
    20.         break;
    21.     case ShowResult.Skipped:
    22.         Debug.Log("The ad was skipped before reaching the end.");
    23.         break;
    24.     case ShowResult.Failed:
    25.         Debug.LogError("The ad failed to be shown.");
    26.         break;
    27.     }
    28. }
    Even though I have testmode set to true, sometimes the ad fails to load. There is no apparent reason or pattern to this, it just sometimes works and sometimes doesn't.

    Is this a known issue? My concern is that the same issue will occur when I do not have testmode set to true, since I don't understand why there could be anything stopping the placeholder ad from loading which leads me to believe it could be some fault in the code. Although it seems watertight to me.

    Thanks in advance.
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello,

    Could you pls share your full code. Cant see initialization code from here.

    Regards,

    Edit: Or you can check this link for unity official Nikkolai Davenport's simple implementation script. It works for me.
     
    Last edited: Jan 8, 2015
    Banglemoose and unity-nikkolai like this.
  3. Banglemoose

    Banglemoose

    Joined:
    Dec 9, 2014
    Posts:
    9
    Thanks Salazar, full code is as follows:


    Code (CSharp):
    1. void Awake() {
    2.         if (Advertisement.isSupported) {
    3.             Advertisement.allowPrecache = true;
    4.             Advertisement.Initialize ("22597", true);
    5.         } else {
    6.             Debug.Log("Platform not supported");
    7.         }
    8.     }
    9.  
    10.     public  void ShowRewardedAd ()
    11.     {
    12.         string zoneID = "videoAds";
    13.        
    14.         // If the value of zoneID is an empty string, set the value to null.
    15.         //  The default zone is used when the value of zoneID is null.
    16.         if (string.IsNullOrEmpty(zoneID)) zoneID = null;
    17.        
    18.         ShowOptions options = new ShowOptions();
    19.         options.pause = true;                        // Pauses game while ads are shown
    20.         options.resultCallback = HandleShowResult;   // Triggered when the ad is closed
    21.        
    22.         if(Advertisement.isReady()){
    23.         Advertisement.Show("pictureZone",options);
    24.         }
    25.     }
    26.    
    27.     public void HandleShowResult (ShowResult result)
    28.     {
    29.         switch (result)
    30.         {
    31.         case ShowResult.Finished:
    32.             // Add code here to rewarding players for watching ads without skipping.
    33.             //  Note: This will be the same result for picture ads when shown.
    34.             Debug.Log("The ad was successfully shown.");
    35.             break;
    36.         case ShowResult.Skipped:
    37.             Debug.Log("The ad was skipped before reaching the end.");
    38.             break;
    39.         case ShowResult.Failed:
    40.             Debug.LogError("The ad failed to be shown.");
    41.             break;
    42.         }
    43.     }
     
  4. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Okay, so a few things are going on here:

    The reason you're not seeing ads all the time is because you're checking if one zone is ready, and then attempting to show a different one. They may not always be ready at the same time.

    In your code, you are passing "pictureZone" as the zone ID when calling the Show() method, but you're not checking to make sure that the same zone is ready. If you don't specify a zone, the default value of null will be passed instead. This tells Unity Ads to check for the default zone (in your case, the default zone is set as "defaultVideoAndPictureZone").

    You need to pass the same zone ID to both the isReady() and Show() methods:
    Code (CSharp):
    1. if (Advertisement.isReady("pictureZone") Advertisement.Show("pictureZone",options);
    Keep in mind, picture ads are still in beta. Which means there is limited fill for English speaking countries, and in most cases no fill for non-English speaking countries.

    You've also assigned the value "videoAds" to zoneID, but there are no zone IDs for your game profile with that ID. This isn't crucial in this case since you're not actually using the variable, but it is important to note.

    Lastly, you may want to use something like the following to initialize Unity Ads. This code exposes gameID and disableTestMode to the inspector, so you can set these values without having to edit your code. It also acts as a safeguard against releasing your game with Test Mode still enabled by accident. To use Test Mode with this code, make sure Development Build is enabled in the Build Settings window in Unity.
    Code (CSharp):
    1. public string gameID;
    2. public string disableTestMode;
    3. void Awake ()
    4. {
    5.      // Development Build must be enabled in Build Settings to enable Test Mode.
    6.      bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
    7.      Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
    8.                              gameID, enableTestMode ? "enabled" : "disabled"));
    9.      Advertisement.Initialize(gameID,enableTestMode);
    10. }
     
    Last edited: Jan 9, 2015
    Salazar likes this.
  5. Banglemoose

    Banglemoose

    Joined:
    Dec 9, 2014
    Posts:
    9
    Thanks for the prompt reply Nikolai. Unfortunately I am still getting the same problem when I have fixed this mistake. Furthermore, I added this script to an object that is instantiated at the start of the game and not destroyed. Am I correct in assuming that once the ad is ready to load, it should stay ready on this object?
     
  6. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    That question sounds somewhat loaded.

    The isReady method provides you with the ability to check if ads are ready before attempting to show, but it also allows you the check if they're ready before even presenting your users with the option to watch an ad for a reward. If for whatever reason an ad is unable to be shown when you call the Show method, you should then handle the ShowResult accordingly via the callback method.

    For instance, I wouldn't recommend calling isReady when you start the app, but not attempt to show it until some later time during gameplay. You want to call isReady sometime shortly before calling Show so that functionality is as predictable as possible. Errors may still occur, which is what the ShowResult is partially for.

    Since you're still getting the issue, I recommend trying the "defaultVideoAndPictureZone" instead, which should have at least some volume in all countries. The picture zone does not have volume for non-English speaking countries. Also, make sure that test mode is enabled. If you're using the script I provided, make sure that Development Build is enabled and that disableTestMode is not checked.