Get Started
Banner ads are rectangular advertisements, consisting of either images or text, that are integrated into an app's layout. These ads remain on the screen while users engage with the app and can automatically refresh after a designated time interval. If you're new to mobile advertising, banner ads provide an excellent starting point for your ad implementation journey.
This guide demonstrates how to seamlessly integrate banner ads from AdMob into a Godot app. Alongside code snippets and detailed instructions, it also provides guidance on appropriately sizing banners and directs you to additional resources for further assistance.
This document is based on:
Prerequisites
- Complete the Get started guide
Always test with test ads
When developing and testing your Godot apps, it's crucial to use test ads rather than live production ads. Failure to do so can result in the suspension of your AdMob account.
The most straightforward method to load test ads is by utilizing our dedicated test ad unit ID for Android and iOS banners:
This particular ad unit ID has been purposefully configured to deliver test ads for every request. You can safely employ it during your coding, testing, and debugging phases. However, remember to replace this test ad unit ID with your own when you are ready to publish your app.
For a more comprehensive understanding of how the Mobile Ads SDK's test ads function, please refer to our documentation on Test Ads.
AdView example
The code sample below demonstrates how to utilize the AdView. In this example, you'll create an instance of an AdView, load an ad into it using an AdRequest, and enhance functionality by handling various life cycle events.
Create a AdView (banner)
The initial step in utilizing a banner ad is to create an instance of an AdView within a GDScript attached to a Node.
The constructor for an AdView in Godot has the following parameters:
unit_id
: The AdMob ad unit ID from which the AdView should load ads.AdSize
: The AdMob ad size you wish to utilize (refer to AdView sizes for specifics).AdPosition
: The position at which the banner ad should be positioned. TheAdPosition.Values
enum enumerates the valid ad position values.
Take note of the distinct ad units used based on the platform. When making ad requests on iOS, you should utilize an iOS ad unit, while for Android, you must use an Android ad unit.
(Optional) Generate an AdView with a customized size
In addition to utilizing predefined AdSize constants, you can also specify a custom size for your ad:
Load a AdView (banner)
The second phase in utilizing the AdView involves crafting an AdRequest and then passing it to the load_banner()
method.
Listen to AdView signals
To tailor the behavior of your ad, you can connect to various events in the ad's lifecycle, such as loading, opening, closing, and more. To monitor these events, you can register a AdListener
:
Destroy the AdView (banner)
Upon completion of using the AdView, remember to call Destroy() to release allocated resources and free up memory.
That's all there is to it! Your app is now fully prepared to showcase banner ads from AdMob.
AdView sizes
Below is a table presenting the standard banner ad sizes:
Size in dp (WxH) | Description | Availability | AdSize constant |
---|---|---|---|
320x50 | Standard Banner | Phones and Tablets | BANNER |
320x100 | Large Banner | Phones and Tablets | LARGE_BANNER |
300x250 | IAB Medium Rectangle | Phones and Tablets | MEDIUM_RECTANGLE |
468x60 | IAB Full-Size Banner | Tablets | FULL_BANNER |
728x90 | IAB Leaderboard | Tablets | LEADERBOARD |
Provided width x Adaptive height | Adaptive banner | Phones and Tablets | N/A |
Screen width x 32/50/90 | Smart banner | Phones and Tablets | N/A |
Further References
Samples
- Sample Project: A Minimal Illustration of usage of all Ad Formats