Search Unity

Placement IDs are not working?

Discussion in 'Unity Ads & User Acquisition' started by clintonb, May 20, 2015.

  1. clintonb

    clintonb

    Joined:
    Dec 14, 2013
    Posts:
    15
    Greetings.

    I find that when I ask if an ad is ready and show it, and use a null zoneID, everything works as expected -- the ad becomes ready and I can show it.

    If, however, I try to use a zone ID, the ad never becomes ready. (I suppose I didn't test where I could show it anyway.) I was able to reproduce these results on both iOS and Android. (Both variations work fine in the Editor). I am using Unity 5.0.1, and Unity Ads 1.1.4.

    Here is my code, slightly modified from the Unity Ads from the Asset Store integration example.

    Code (csharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class UnityAdsTest : MonoBehaviour {
    7.     public string adName = "pictureZone";
    8.  
    9.     void Awake() {
    10.         if (Advertisement.isSupported) {
    11.             Advertisement.allowPrecache = true;
    12.             Advertisement.Initialize ( <Your Game ID Here> );
    13.         } else {
    14.             Debug.Log("Platform not supported");
    15.         }
    16.  
    17.         // adName = null;
    18.     }
    19.    
    20.     void OnGUI() {
    21.         if(GUI.Button(new Rect(10, 10, 150, 50), Advertisement.isReady(adName) ? "Show Ad" : "Waiting...")) {
    22.             // Show with default zone, pause engine and print result to debug log
    23.             Advertisement.Show(adName, new ShowOptions {
    24.                 pause = true,
    25.                 resultCallback = result => {
    26.                     Debug.Log(result.ToString());
    27.                 }
    28.             });
    29.         }
    30.     }
    31. }
    32.  
    That is the complete code; it just needs a game ID, and to be added to an empty gameobject in a new scene. It will fail as written, and work if you uncomment the 'adName = null' line.
     
  2. clintonb

    clintonb

    Joined:
    Dec 14, 2013
    Posts:
    15
    Aha!

    Unlike, say, Heyzap, with Unity Ads you need to define the ad placement zoneId before you can use it. You do that by going to https://unityads.unity3d.com/admin/#/games , selecting your game, clicking on "Monetization Settings", and then clicking on "Show Advanced Settings". From there, you can "Add [a] new ad placement" and enter in a name and get an ID back.

    If you use that ID, isReady(placementID) will return true and you'll get an ad on the actual device (not just in the Editor).

    Might I suggest that it would be useful for the documentation to be explicit on this matter? I only read the Integration Guide for Unity Asset Store, because all I was doing was integrating the system, it seemed to cover everything I needed to know, and none of the other documentation looked relevant. (My bad). It detailed how to show ad placements, and, admittedly, said to use the "correct" zoneId, but I thought it was talking about passing the same string to both Show() and isReady(). I believe a link to the Introduction To Ad Placements page would be appropriate, especially if it had more details on how, exactly, the placement IDs are created.

    [And, I finally have an answer to another question I didn't ask -- how do I specify what sort of ad I want to show, such as a video or picture (or a reward video, which I didn't know was possible with Unity Ads). You specify the settings corresponding to the names placement in the admin portal.]

    I'm glad to have this resolved.
     
    trombonaut and Los_Kittyhawk like this.