Unity Ads working fine on Unity Editor (pc) but not in Android phone - unity3d

I have made a banner ad by using Unity Ads. In my pc seems to be working fine, but when I export it to my android phone no ad is shown. Any idea how to solve this?
This is the code that I am using:
(I did not put the actual app id due to privacy)
public class AdsManager : MonoBehaviour
{
string appId = "....";
void Start()
{
Advertisement.Initialize(appId);
}
void Update()
{
ShowBanner();
}
void ShowBanner()
{
Advertisement.Banner.Show("Banner_Android");
}
}
I read the documentation, whatched Youtube tutorials, tryied to use a corroutine

Related

Google AdMob test ads not showing after building in Unity

I wanted to implement google ads into my unity app with the official package (version 5.4.0, unity version is 2019.4.14):
https://github.com/googleads/googleads-mobile-unity/releases
When I run the project in the editor, the test ad is displayed. But when I build the app and install it on my phone, it doesn't show anything (my WiFi connection is good and I have access to Google services).
My ad manager:
using System;
using System.Collections;
using UnityEngine;
using GoogleMobileAds.Api;
public class AdsManager : MonoBehaviour
{
private static readonly string appId = "ca-app-pub-3940256099942544/3419835294";
private static readonly string bannerId = "ca-app-pub-3940256099942544/6300978111";
private static readonly string interstitialId = "ca-app-pub-3940256099942544/1033173712";
private static readonly string rewardedId = "ca-app-pub-3940256099942544/5224354917";
private static readonly string rewardedInterstitialId = "ca-app-pub-3940256099942544/5354046379";
private static readonly string nativeId = "ca-app-pub-3940256099942544/2247696110";
private InterstitialAd interstitialAd;
void Start()
{
MobileAds.Initialize(InitializationStatus => {});
this.RequestInterstitial();
}
public AdRequest CreateAdRequest() {
return new AdRequest.Builder().Build();
}
public void RequestInterstitial() {
Debug.Log("Requesting interstitial ad");
if(this.interstitialAd != null) {
this.interstitialAd.Destroy();
};
this.interstitialAd = new InterstitialAd(interstitialId);
this.interstitialAd.OnAdClosed += HandleOnInterstitialAdClosed;
this.interstitialAd.LoadAd(this.CreateAdRequest());
ShowInterstitial();
}
public void ShowInterstitial() {
if(this.interstitialAd.IsLoaded()) {
this.interstitialAd.Show();
} else {
this.RequestInterstitial();
}
}
public void HandleOnInterstitialAdClosed(object sender, EventArgs args)
{
Debug.Log("Closed interstitial ad");
}
}
I tried using the Android LogCat but it didn't find any mention of "Requesting interstitial ad". I get this log in the editor though and the test ad is shown. Any idea what is the issue?
Thanks
1 - The editor always shows test ads, after all when you use the app on the editor, you are testing it.
2 - If you want to display test ads on the device where you have installed the app, there are two ways: the first is to define your device as a test device in AdMob, the second to use strings for test ad units (https: //developers.google.com/admob/unity/test-ads#android)
3 - If you want to view real ads instead (be careful, if you see too many ads that you publish yourself and / or click them, you may have invalid traffic problems, so it is always better to view them as test ads), the real ads come to the end of a process:
First you need to create the app with the official app ID and ad unit strings that you get from the AdMob page for your app. Then you have to upload the app to a supported store, then you have to connect the app of the store to the app on AdMob, then the AdMob team performs a review on your app to verify that you are in order at a legal and regulatory level. , and eventually you will have your real, monetizable ads.

unity ads not showing up

i followed the official unity tutorial on how to put bannner ads on my game, i set everything up in the unity dashboard, and in the editor i see a rectangle that says the ad should be there, but when i build the game nothing shows up, here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class bannerad : MonoBehaviour
{
bool testMode = false;
public string gameId = "******" (my game id is here i just dot want to share it);
// Start is called before the first frame update
IEnumerator Start()
{
Advertisement.Initialize(gameId, testMode);
while (!Advertisement.IsReady("Lost_Ad"))
{
yield return null;
}
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show("Lost_Ad");
}
}
anyone knows what is the solution?
Are you ever calling this function? If you just replaced the Start function with this IEnumerator it will not get called unless you call it.
private void Start()
{
Advertisement.Initialize(gameId, testMode);
StartCoroutine(StartAds());
}
private IEnumerator StartAds()
{
// your code here
}

Ads not working on the production build of android game

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!");
}
}
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.

Unity Admob Interstitial Ads Not Showing

I know this question has been asked several times but i got stuck even though i have implemented and tried all the solutions. I follow this tutorial for interstitial ads showing:
https://developers.google.com/admob/unity/interstitial
My main goal is to show ad whenever user taps on "Restart" button for the game.
Here is my main ad manager class (which is linked with an game object):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
public class AdManager : MonoBehaviour {
public string interstitial_id;
public string app_id;
public InterstitialAd interstitial;
// Use this for initialization
void Start () {
//MobileAds.Initialize(app_id);
DontDestroyOnLoad(this);
Prepare_Video();
Debug.Log("Admob ilklendirildi: " + interstitial.ToString());
}
public void Show_Video()
{
Debug.Log("Reklam hazırlık durumu: " + interstitial.IsLoaded());
if (interstitial.IsLoaded()) {
Debug.Log("Reklam hazır, gösterilecek");
interstitial.Show();
}
else
{
Prepare_Video();
interstitial.Show();
}
}
public void Destroy_Video()
{
if(interstitial != null)
{
interstitial.Destroy();
}
}
public void Prepare_Video()
{
interstitial = new InterstitialAd(interstitial_id);
AdRequest request = new AdRequest.Builder().Build();
interstitial.LoadAd(request);
}
}
I call the show method in restart action:
public void RestartScene()
{
GameStatusText.gameObject.SetActive(false);
RestartButton.gameObject.SetActive(false);
MeterText.gameObject.SetActive(false);
MeterTextTop.text = "";
Time.timeScale = 1;
TimeController.TimeLeft = 50f;
FindObjectOfType<AdManager>().Show_Video();
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
you need Initialize admob first
Check what's going on with the scene that AdManager is assigned to, and if there is any changes to the scene, and do you have Google Ads unity asset installed in your game?
I have reinstalled the admob plugin and followed the instructions from the beginning. It worked. It seems like my plugin package was damaged and some files were missing.

showing admob interstitial every x play unity

I am trying to make my interstitial admob ad appear when a user enters the map for the third time.
My code is:
using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class interstitial_ad : MonoBehaviour {
private InterstitialAd interstitial;
void Start()
{
interstitial = new InterstitialAd ("ca-app-pub-xxx");
interstitial.LoadAd (new AdRequest.Builder ().Build ());
}
void Update()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
It shows the ad every time I enter the map, so I tried to add:
playCount++;
if (playCount % 3 == 0) {
but that did not work for me, probably because of the void Update() part. Do you have any ideas/hints how to make it work?