How to get AdMob Banner height correctly in Unity project?

1,679 views
Skip to first unread message

Omido Yutaka

unread,
Jan 20, 2023, 7:08:01 PM1/20/23
to Google Mobile Ads SDK Developers
I am developing a game with Unity, and I am trying to show banner on the bottom of scene.
I know that if the banner overlap game contents, it is conflict with AdMob policy.
So, I want to get banner size and change scene layout so that ad will not overlap contents.

First, I implemented to show banner like below code.
========== code start ==========
_bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
_bannerView.OnBannerAdLoaded += OnBannerAdLoaded;
_bannerView.OnBannerAdLoadFailed += OnBannerAdLoadFailed;
var request = new AdRequest.Builder().Build();
_bannerView.LoadAd(request);
========== code end ==========

Then I got the height using 'GetHeightInPixels' and modify camera rect not to overlap it like below.
Render mode of camera is "Screen space - Camera" and canvas scalar set to "Scale With Screen Size".
========== code start ==========
var h = this.bannerView.GetHeightInPixels();
var height = this.bannerView.GetHeightInPixels();
var heightViewPortRadio = height / Screen.height;
Camera.main.rect = new Rect(0, heightViewPortRadio, 1, 1 - heightViewPortRadio);
========== code end ==========

However, the result is like the screenshot I attouched this message.
It overlaps content of game.

So, the questions are
1. 'GetHeightInPixels' is suitable way to get banner height in Unity?
2. How to convert 'GetHeightInPixels' result to Unity compatible value of height?

Regards.

スクリーンショット 2023-01-21 9.00.35.png

Mobile Ads SDK Forum Advisor

unread,
Jan 23, 2023, 2:37:06 AM1/23/23
to yutaka...@gmail.com, google-adm...@googlegroups.com

Hello Omido,

 

Thank you for reaching out to us.

 

To get you started, here is our guide on Unity banner ads and Anchored adaptive banners. With regards to your concern:

 

  1. No, 'GetHeightInPixels' is not a suitable way to get banner height in Unity. 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. You can read more in this section.
  2. To further assist you on this, can you send us a sample of your code and can you help us visualise your intended output through an illustration?

 

You can provide the following details via reply privately to author option or you can provide directly to the link below.

 

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

 

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002i12HUQAY&entry.80707362=00164351

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

 

Regards,

Google Logo
Zoilo Isagani
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2i12HU:ref

Omido Yutaka

unread,
Feb 17, 2023, 8:18:24 AM2/17/23
to Google Mobile Ads SDK Developers
Thank you for your reply.
And I am so sorry for my late response.

> No, 'GetHeightInPixels' is not a suitable way to get banner height in Unity. 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.
I see.
So in order to prevent banner ads from overlapping game content in Unity, we need to reserve 15% of the screen height that can be obtained with Screen.height, right?
Or is 15% of the safe area height sufficient?

Regards.

2023年1月23日月曜日 16:37:06 UTC+9 Mobile Ads SDK Forum Advisor:

Mobile Ads SDK Forum Advisor

unread,
Feb 17, 2023, 2:15:03 PM2/17/23
to yutaka...@gmail.com, google-adm...@googlegroups.com

Hi,

 

Thank you for your response. Kindly note that this is for Anchored banner height, that is never larger than the lesser of 15% of the device's height. You may check the custom ad position, for greater control over where a BannerView is placed on screen than what's offered by AdPosition values, use the BannerView constructor that has x- and y-coordinates as parameters. What we can recommend is to check our implementation guide and sample app project for reference in your implementation.

If you still have encounter the ads overlapping, it would be best if you can provide a sample app project where we can check your implementation. You can provide the following details via reply privately to author option or directly provide it to the link below.

 

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

 

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002i12HUQAY&entry.80707362=00164351

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

 

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2i12HU:ref
Reply all
Reply to author
Forward
0 new messages