Ads not working on the production build of android game - unity3d

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.

Related

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

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

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 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.

How to Show Admob Interstitials on Counted Click?

I am trying to something like this:
if button clicked for 4 times, I could show Interstitial?
However i couldn't make it happen.
Created a game object.
Attached script to that object.
Created a restart button.
Implemented this object on that button with onclick-runtime only etc.
Now every time user clicks restart button, interstitial ads show itself. but of course as you might know, it is very annoying.
I dont know how to count how many times users press the restart button and for example show the ads every 3 or 4 times if user press the button.
Thank you.
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviour
{
InterstitialAd interstitial;
public string InterstitialId;
// Use this for initialization
void Start()
{
//Request Ads
//RequestBanner();
RequestInterstitial();
}
public void showInterstitialAd()
{
//Show Ad
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
private void RequestInterstitial()
{
string adUnitId = InterstitialId;
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
}
I can give you idea ,you can use time class to know last showed ad or use variable saying like every 4 game show ad on restart button click.
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviou
{
int counter =0;
InterstitialAd interstitial;
public string InterstitialId;
// Use this for initialization
void Start()
{
//Request Ads
//RequestBanner();
RequestInterstitial();
}
public void showInterstitialAd()
{
counter ++;
if(counter%4==0)
{
//Show Ad
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
private void RequestInterstitial()
{
string adUnitId = InterstitialId;
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
}

Implementing Unity BannerView

Sup, I need some help about this plugin googleads-mobile-plugins
In my game, I created a Class that holds a static variable of the bannerView.
I made it like this so it will be loaded only once.
but first I tried putting this code from the instruction on onGui
but it makes my game lag
onGUI{
bannerView = new BannerView ("123123123", AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder ().Build ();
bannerView.LoadAd (request);
}
so the new version i made is like this.
public class MainController {
private static BannerView bannerView;
public static void bannerLoad()
{
if (bannerView == null)
{
bannerView = new BannerView ("123123123", AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder ().Build ();
bannerView.LoadAd (request);
}
}
public static void bannerShow()
{
if (bannerView != null)
{
bannerView.Show ();
}
}
public static void bannerHide()
{
if (bannerView != null)
{
bannerView.Hide ();
}
}
}
each scene has its own controller
example
public class Scene1Controller : MonoBehaviour
{
onStart()
{
MainController.bannerShow();
}
}
My problem is that it looks like the ads are not refreshing
I only show the ads on my menu then hide when playing
the refresh rate must only be 60 seconds but the ads are not refresh. is there something wrong with my implementation by putting it on static?
should I always send command bannerView.LoadAd (request); ?
Should I send a new ad request when on every start of the scene?
BannerView bannerView = new BannerView ("123123123", AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder ().Build ();
bannerView.LoadAd (request);
The problems is that when the scene was loaded and the ads where still not loaded and the user exit that scene is that even count in my admob impression?
Yes, you don't need to include ad code in onGUI() method.
And also, you don't need to call LoadAd again and again. In my app build with unity, the ads do refresh. For example if there is no other ad available to show at that point of time, I guess the same ad will remain but as a new impression. Also, you can check the logcat while testing your app using Xcode ( for iOS) and Eclipse/Android Studio ( for android). It will show ad is refreshed.