1

I made an android game. I added some ads on it with the test mode off and than I released the game to internal testers and the ads were working so than I fixed some issues in game and released the game for production on playstore.

Now that the game is up on Playstore ads are not working. Will it take some time for ads to show up? There was a popup on unity monetization dashboard that I need to update package name and I did it but ads are still not showing up although playstore listing shows that my app contain ads.

My code is :

public string gameId = "ihavemygameidhere";

public bool testMode = true;
void Start()
{
    // Initialize the Ads service:
    Advertisement.Initialize(gameId, testMode);
}

public void ShowInterstitialAd()
{
    // Check if UnityAds ready before calling Show method:
    if (Advertisement.IsReady())
    {
        Advertisement.Show();
    }
    else
    {
        Debug.Log("Interstitial ad not ready at the moment! Please try again later!");
    }
}
  • The play store listing of ads is a setting set by you in the `Google Console`, so it will show that there are ads regardless if they are working once that is checked. I would use [`Android Studio`](https://developer.android.com/studio) to debug the issue with logcat. I am sure something is being logged that can resolve this. I find it odd that your ads work in a build on the Interal track but do not work in a production environment. They should be near identical. – TEEBQNE May 04 '21 at 18:46
  • @TEEBQNE where is the setting in google console, I am sorry I am new to all this – Malik Nouman May 04 '21 at 18:52
  • @TEEBQNE I understand but i have no idea how to log but i will look in to it – Malik Nouman May 04 '21 at 18:58
  • @TEEBQNE there is package manager of logcat now in unity so i used that and it says that 2021/05/05 00:26:12.733 17366 19359 Info Unity Interstitial ad not ready at the moment! Please try again later! and i have updated the question – Malik Nouman May 04 '21 at 19:28
  • Alright, then that would be your issue. I can fix the code you just attached. – TEEBQNE May 04 '21 at 19:29

1 Answers1

0

When the ad is not ready, that means that the ad server has not yet sent an ad to be seen. I would recommend placing the IsReady() check in a Coroutine, then showing a loading screen UI when the player is waiting. I would also put a fail of some amount of time in case the IsReady() always fails.

[SerializeField] private GameObect LoadingUI = null;
private float waitTime = 5f;

public void ShowInterstitialAd()
{
    StartCoroutine(ShowAd());
}

private IEnumerator ShowAd()
{
    float currentTime = 0.0f;
    
    LoadingUI.SetActive(true);
    
    while(currentTime <= waitTime && !Advertisement.IsReady())
    {
         currenTime += Time.deltaTime;
         yield return null;
    }
    
    // show the ad if it is now ready
    if(Advertisement.IsReady())
    {
         Advertisement.Show();   
    }
    else
    {
        Debug.LogError("Error: Ad was not able to be loaded in " + waitTime + " seconds!");
    }   
    
    LoadingUI.SetActive(false);
}

Make sure to assign some object in the inspector for the LoadingUI object so players can not tap to view ads again or just some UI that blocks all input while the ad is attempting to load. I would use a ScreenOverlay UI as it would be rendered over everything.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37
  • okay great I will look in to it. But my question is that than why was it working in the internal testing without this code , my app just got published today maybe ads take time to show up? and 2nd question is will I need to release an update now for this? – Malik Nouman May 04 '21 at 19:40
  • 1
    I am unsure why it is not working in the live environment. I have not released an app yet and have only worked in closed/internal testing. It could be that as an internal app it does not go through the proper channels to request an ad, and receives it almost immediately. You will need to release a new version, yes. – TEEBQNE May 04 '21 at 19:43
  • 1
    Thank you so much <3 – Malik Nouman May 04 '21 at 19:44
  • omg bro https://unityads.unity3d.com/help/unity/integration-guide-unity on this site you can see that they used something called placement id in Advertisement.Show(placmentid); . Can that be the issue? – Malik Nouman May 04 '21 at 20:11
  • Without using a string it would use the default ID. If you are unsure of what the ID is, I would read the docs more or look into a tutorial that goes step by step. There are a lot of steps to setting up ads outside of Unity as well, so it is hard to say if one of those could also be the reason it is not working. – TEEBQNE May 04 '21 at 20:13
  • Actually I think you were right before. I mean its not getting passed the if condition as the ad is not ready so now I am gonna add your code and release an update – Malik Nouman May 04 '21 at 20:17
  • @MalikNouman I would first release to the internal track and test if the code works. I typed this up untested, so I would not recommend sending it out without testing. Test it in editor first, then internal build, and then release. – TEEBQNE May 04 '21 at 20:21
  • cant I just install the apk and test it or is it compulsory to release it internally – Malik Nouman May 04 '21 at 20:23
  • Due to the SHA key you have, I believe side-loading the APK will not allow most functionality to work, especially with Google Play Games functionality. Internal builds should upload/update almost immediately tho so it should be near the same as side loading. – TEEBQNE May 04 '21 at 20:31
  • Thank you so much. You have been a great help. I have released an internal test although it says it will take some hours to get update to internal testers so i will let you know – Malik Nouman May 04 '21 at 20:35
  • Try clearing the cache and force stopping the Play Store and checking your app again. The internal track should update within seconds. The closed/live track will take 3 - 4 hours usually. – TEEBQNE May 04 '21 at 20:37
  • Okay bro I think I understand the issue. It worked with yours but that loaded screen took way too long only first time now even if I close the app or emulator it still load ad perfectly – Malik Nouman May 04 '21 at 21:08
  • Sorry not sure I follow. Are you saying that it is working, or that the loading screen is taking a while? Do ads still load properly? Or is something frozen? – TEEBQNE May 04 '21 at 21:09
  • Bro I wanna die. I tested it on emulator and loading screen took like 6-7 seconds and than the ad came so i than tested it on my phone and its stuck on loading screen – Malik Nouman May 04 '21 at 21:16
  • It must mean there is an error. I would try to use logcat again. The issue might be that your ad ID is not properly set up in Unity. I am not very familiar with common issues with Unity Ads. – TEEBQNE May 04 '21 at 21:17
  • Okay so i used logcat and I think problem is that it takes too long to request an ad plan? com.unity3d.services.core.api.Sdk.logInfo() (line:84) :: Requesting ad plan from https://auction.unityads.unity3d.com/v6/games/ – Malik Nouman May 04 '21 at 21:19
  • Some errors can occur if your device's time is not synced with Unity's ad server. Make sure your time is set correctly. – TEEBQNE May 04 '21 at 21:21
  • so I tested it on other phone and its working. Loading screen took 2 sec max and shows up an ad. I swear this is killing me – Malik Nouman May 04 '21 at 21:24
  • f this. Are there any other ad services that are easy to implement? – Malik Nouman May 04 '21 at 21:26
  • 1
    There is [admob](https://developers.google.com/admob/unity/quick-start) but I find Unity Ads is easier. – TEEBQNE May 04 '21 at 21:30
  • Now it doesnt even on work on the second phone. What do you mean by ad server? – Malik Nouman May 04 '21 at 21:38
  • I do not know exactly how Unity's ads work, but to retrieve the ad the video has to come from somewhere. It is most likely served and loaded from a server Unity controls. – TEEBQNE May 04 '21 at 21:41
  • Its working in the emulator btw. I dont know what to do. Any hints? – Malik Nouman May 04 '21 at 21:41
  • As I can not see exactly how you setup your ads, I would recommend watching a [video tutorial](https://www.youtube.com/watch?v=DWmD1RRORfc&ab_channel=KeeGamedev) just to assure you have met every step required to setting up ads. – TEEBQNE May 04 '21 at 21:43
  • I have added the script in the pause button. Like everytime the user touches it it shows an ad, – Malik Nouman May 04 '21 at 21:50
  • Do you think it can be because there are no more ads campaign to show? – Malik Nouman May 04 '21 at 21:59
  • It could be? I believe there is a daily limit for each user for how often they can watch ads. – TEEBQNE May 04 '21 at 22:03
  • i am gonna connect to vpn and see. I am gonna solve this i promise – Malik Nouman May 04 '21 at 22:07
  • umm unity asked to collect my cookies during the ad. is that common? – Malik Nouman May 04 '21 at 22:08
  • 2
    Okay I think that is the issue as my ads are only video ads so I dont think there are much of em. I am gonna add banner ads as well and a loading screen for 5 seconds and rolll out the update. Thank You for your help – Malik Nouman May 04 '21 at 22:11