[Unity] Issues with Collapsible Banner Preload and BannerView.Hide() in Google Mobile Ads SDK

194 views
Skip to first unread message

Huy Le

unread,
Sep 27, 2024, 3:29:15 AMSep 27
to Google Mobile Ads SDK Developers
Hi,
We have issues while developing a game with Collapsible Banner.

Issue 1: Collapsible Banner Appearing Immediately After Loading

We are preloading collapsible banners during the loading scene and only intend to show them when needed. However, the collapsible banner is being displayed immediately after it finishes loading, even though we haven't requested it to be shown at that time. Ideally, the banner should remain hidden until it is explicitly called to display.

Issue 2: BannerView.Hide() Not Functioning as Expected

In an effort to hide the banner, we attempted to use the BannerView.Hide() function, but it does not appear to be working. As a temporary solution, we are using BannerView.Destroy() to remove the banner instead. However, this creates a new issue as it triggers a reload of the collapsible banner, and we have to wait for the reloading process to complete. This causes a delay in determining the next steps and, in some cases, unintentionally triggers the Open Ads, which is not the desired outcome.

I had reproduce these problems in this project, please take a look.
https://github.com/NotthingStudioo/DemoCollapsible

 Best regards,
Huy Le,  

Mobile Ads SDK Forum Advisor

unread,
Sep 27, 2024, 5:08:03 PMSep 27
to huylqn...@gmail.com, google-adm...@googlegroups.com

Hi Huy Le,

Thank you for contacting the Mobile Ads SDK support team.

  1. If the loaded ad is a collapsible banner, the banner shows the collapsible overlay immediately once it's placed in the view hierarchy.
  2. The reason that bannerVeiw.hide() doesn’t work is that the "myGameObject" keeps cloning itself each time you go back to the main menu. to fix it on the "GameAdControl" script add "Destroy (myGameObject)” at the end of "void Start" and it will work as per the Github Issue.
void Start () {
//this give me null reference exeption
admob.bannerview.hide();
}

void OnDisable () {
admob.bannervier.Show();
}

I hope this helps! Let me know if you have any other questions. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02vGayJ:ref" (ADR-00269817)

Thanks,
 
Google Logo Mobile Ads SDK Team


Huy Le

unread,
Sep 30, 2024, 5:18:56 AMSep 30
to Google Mobile Ads SDK Developers

Hi Mobile Ads SDK support team,

Thank you for your detailed explanation! It helped me solve the first issue. I found that the bannerView.Hide() function works perfectly when I place it at the end of LoadCollapsibleBannerAd().

Regarding the second issue, in the project I provided, there is no scene-changing action involved. I have checked the instance ID of both the GameObject and the hashcode of the BannerView, and they match. This confirms there are no null reference exceptions when trying to hide the banner.

In the provided link, I’ve also included a playable APK. Please try it on your device.

Thank you for your assistance!

Best regards,
Huy Le

Mobile Ads SDK Forum Advisor

unread,
Oct 1, 2024, 1:37:49 AMOct 1
to huylqn...@gmail.com, google-adm...@googlegroups.com

Hi Huy Le,

Thank you for confirming that your first issue got fixed. 

For the second Issue can you make sure that you are not redeclaring the bannerView as a local variable in any of the methods and try to destroy the Ad

void OnDisable(){
bannerView.Hide(); or bannerview.destroy();
}

Huy Le

unread,
Oct 1, 2024, 6:03:12 AMOct 1
to Google Mobile Ads SDK Developers

Hi,

Thank you for your response.

I can confirm that there is no redeclaration of the bannerView in the provided project, as long as the Destroy button has not been clicked. The instance of collapsibleBannerView is only destroyed when the Destroy button is explicitly clicked. Below is the relevant code from the project:

using System;
using GoogleMobileAds.Api;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour
{
public Button btnLoad, btnShow, btnHide, btnDestroy;
private const string CollapsibleBannerAdFormat = "CollapsibleBanner";
private BannerView collapsibleBannerView;
public TextMeshProUGUI txt;

private void Awake()
{
this.btnLoad.onClick.AddListener(this.LoadCollapsibleBannerAd);
this.btnShow.onClick.AddListener(() =>
{
this.txt.text="Show CollapsibleBanner.";
Debug.Log("Show CollapsibleBanner.");
this.collapsibleBannerView?.Show();
});
this.btnHide.onClick.AddListener(() =>
{
this.txt.text="Hide CollapsibleBanner.";
Debug.Log("Hide CollapsibleBanner.");
this.collapsibleBannerView?.Hide();
});
this.btnDestroy.onClick.AddListener(() =>
{
this.txt.text="Destroy CollapsibleBanner.";
Debug.Log("Destroy CollapsibleBanner.");
this.collapsibleBannerView?.Destroy();
});
}

private static string GetNewGuid() => Guid.NewGuid().ToString();

private void LoadCollapsibleBannerAd()
{
var collapsibleBannerGuid = GetNewGuid();

var adSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);

this.collapsibleBannerView = new BannerView("ca-app-pub-3940256099942544/2014213617", adSize, AdPosition.Bottom); 
// Test ID

#region Events

this.collapsibleBannerView.OnBannerAdLoaded += () => this.OnCollapsibleBannerLoaded(CollapsibleBannerAdFormat, collapsibleBannerView);
this.collapsibleBannerView.OnBannerAdLoadFailed += error => this.OnCollapsibleBannerLoadFailed(CollapsibleBannerAdFormat, error);
this.collapsibleBannerView.OnAdFullScreenContentOpened += () => this.OnCollapsibleBannerPresented(CollapsibleBannerAdFormat);
this.collapsibleBannerView.OnAdFullScreenContentClosed += () => this.OnCollapsibleBannerDismissed(CollapsibleBannerAdFormat);
this.collapsibleBannerView.OnAdClicked += () => this.OnCollapsibleBannerClicked(CollapsibleBannerAdFormat);

#endregion

var request = new AdRequest();
AddPramsCollapsible();
Debug.Log("Load CollapsibleBanner.");
this.txt.text="Load CollapsibleBanner.";
this.collapsibleBannerView.LoadAd(request);
this.collapsibleBannerView.Hide();

return;

void AddPramsCollapsible()
{
request.Extras.Add("collapsible_request_id", collapsibleBannerGuid);
request.Extras.Add("collapsible", "bottom");
}
}

private void OnCollapsibleBannerLoaded(string placement, BannerView collapsibleBannerView) { Debug.Log($"OnCollapsibleBannerLoaded "); }

private void OnCollapsibleBannerLoadFailed(string placement, AdError adError) { Debug.Log($"OnCollapsibleBannerLoadFailed {placement} - {adError.GetMessage()}"); }

private void OnCollapsibleBannerPresented(string placement) { Debug.Log("OnCollapsibleBannerPresented"); }

private void OnCollapsibleBannerDismissed(string placement) { Debug.Log("OnCollapsibleBannerDismissed"); }

private void OnCollapsibleBannerClicked(string placement) { Debug.Log("OnCollapsibleBannerClicked"); }
}

Thank you for your help!

Best regards,
Huy Le

Mobile Ads SDK Forum Advisor

unread,
Oct 1, 2024, 2:22:49 PMOct 1
to huylqn...@gmail.com, google-adm...@googlegroups.com
Hi Huy Le,

Kindly update the sample provided with the recent code changes so that we can run the project and provide you the solution. In addition to the code kindly let us know is this issue is reproducible in all the devices or any specific device.

Huy Le

unread,
Oct 2, 2024, 9:06:28 PMOct 2
to Google Mobile Ads SDK Developers
  Hi,
The  sample provided works perfectly in my Unity Editor. However, in the Editor, only the Banner appears, and the Collapsible does not. The Git repository is just for reference, so you should download the APK file from the ApkSample folder and test it on a real device. Once installed on an actual device or simulator, the bug will reproduce. I've tested it on several devices, and the error still persists.
Test devices:
xiaomi 11 lite 5g
Samsung Galaxy Note 8
Xiaomi POCO X3 Pro
(simulator) BlueStacks App Player 5.21.560.1027

Mobile Ads SDK Forum Advisor

unread,
Oct 3, 2024, 8:23:29 AMOct 3
to huylqn...@gmail.com, google-adm...@googlegroups.com
Hi Huy Le,

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this.

Há Hà

unread,
Nov 21, 2024, 9:21:10 PMNov 21
to Google Mobile Ads SDK Developers
Hi!
I am also having the same issue so I wanted to know if there is any update on this?

Mobile Ads SDK Forum Advisor

unread,
Nov 21, 2024, 11:55:24 PMNov 21
to ahaha...@gmail.com, google-adm...@googlegroups.com

Hi,

The issue is still under investigation. Once we receive any updates, we will intimate you. Meanwhile, your patience is important.

This message is in relation to case "ref:!00D1U01174p.!5004Q02vGayJ:ref" (ADR-00269817)

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5


 

 

Mobile Ads SDK Forum Advisor

unread,
Dec 11, 2024, 2:43:07 PMDec 11
to ahaha...@gmail.com, google-adm...@googlegroups.com
Hi,

Looks like this issue is fixed now, could you check once and confirm.
Thanks

Mobile Ads SDK Forum Advisor

unread,
Dec 27, 2024, 2:27:36 AM (23 hours ago) Dec 27
to huylqn...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for getting back to us.

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated. 

Mobile Ads SDK Forum Advisor

unread,
Dec 27, 2024, 12:05:09 PM (14 hours ago) Dec 27
to huylqn...@gmail.com, google-adm...@googlegroups.com

Hi Huy,

Can you try to hide the banner before loading it? This should tell the SDK to not show the banner when loading completes.

        _banner = new BannerView(_adUnitId, AdSize.Banner, AdPosition.Top);
        _banner.Hide();
        
        var adRequest = new AdRequest.Builder()
            .AddExtra("collapsible", "top")
            .Build();

        _banner.LoadAd(adRequest);

 

This message is in relation to case "ref:!00D1U01174p.!5004Q02vGayJ:ref" (ADR-00269817)

Thanks,
 
Google Logo
Nicholas Ventimiglia
Mobile Ads SDK Team


Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
 

 



Reply all
Reply to author
Forward
0 new messages