Getting adaptive banner height in Unity

521 views
Skip to first unread message

Assaf Cohen

unread,
Jul 12, 2023, 7:36:19 AM7/12/23
to Google Mobile Ads SDK Developers
Hello,
Is there a way to get the height of an adaptive banner before it shows on screen?
We want to adjust the layout of the game before the banner shows.

It looks like 
AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth)
Doesn't return the actual height.

And the callback
_bannerView.OnBannerAdLoaded += () =>
Does contain the height, but it's only after the ad is displayed

Thanks.

Mobile Ads SDK Forum Advisor

unread,
Jul 12, 2023, 12:05:58 PM7/12/23
to zkof...@gmail.com, google-adm...@googlegroups.com

Hi Assaf,

Thank you for reaching out to us.

With regard to adaptive banner, as per the documentation guide (https://developers.google.com/admob/unity/banner/anchored-adaptive), anchored banner height is never larger than the lesser of 15% of the device's height or 90 density independent pixels and never smaller than 50 density independent pixels. Can you confirm if you already try to use the AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth() method to get the size for a banner in an anchored position for the current interface orientation. This method takes the width of the banner as an input and returns an AdSize object that contains the height of the banner. Once you have the height of the banner, you can use it to adjust the layout of your app so that the banner fits properly. In addition to that, if you want to get the exact size of the ads, you need to show first the ads.  

This message is in relation to case "ref:_00D1U1174p._5004Q2n6ira:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


Assaf Cohen

unread,
Jul 13, 2023, 3:41:55 AM7/13/23
to Google Mobile Ads SDK Developers
Hello,
Thanks for your reply.
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth() will always return height=0, it looks like this value is hard-coded in the SDK.
If the only way is to actually call "new BannerView(...)" and get an ad - is there a way to delay showing it until the layout is adjusted?

Mobile Ads SDK Forum Advisor

unread,
Jul 13, 2023, 6:29:14 AM7/13/23
to zkof...@gmail.com, google-adm...@googlegroups.com
Hello Assaf,

I'm afraid delaying when the ad will be shown until the layout is adjusted isn't possible as the banner size adjusts as the same time as the ad is served/rendered. This is necessary due to impression tracking. An impression is counted when one or more pixels of the ad creative is visible on a device's screen. Hence, the banner size and ad size adjustments are done synchronously.
Reply all
Reply to author
Forward
0 new messages