### Adapter Response Info Example (JSON) Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info This JSON object shows sample response information for an individual ad source, including its class name, latency, and identifiers. ```json { "adapter_class_name": "com.google.ads.mediation.admob.AdMobAdapter", "latency_millis": 328, "ad_source_name": "Reservation campaign", "ad_source_id": "7068401028668408324", "ad_source_instance_name": "[DO NOT EDIT] Publisher Test Interstitial", "ad_source_instance_id": "4665218928925097", "ad_unit_mapping": {}, "ad_error": {} } ``` -------------------------------- ### Create an AdView Instance in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/get_started Initialize the AdMob SDK and create an AdView instance for banner ads in C#. This example selects the appropriate ad unit ID for Android or iOS. ```csharp using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; using PoingStudios.AdMob.Api.Listeners; public partial class BannerAd : Node2D { private AdView _adView; public override void _Ready() { //The initializate needs to be done only once, ideally at app launch. MobileAds.Initialize(); } private void CreateAdView() { //free memory if (_adView != null) DestroyAdView(); string unitId = null; if (OS.GetName() == "Android") unitId = "ca-app-pub-3940256099942544/6300978111"; else if (OS.GetName() == "iOS") unitId = "ca-app-pub-3940256099942544/2934735716"; _adView = new AdView(unitId, AdSize.Banner, AdPosition.Top); } } ``` -------------------------------- ### Rewarded Interstitial Example Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/rewarded_interstitial This code sample demonstrates how to create a Rewarded Interstitial instance, load an ad using an AdRequest, and handle its lifecycle events. Ensure you have completed the 'Get started' guide before implementation. ```gdscript # Example code for Rewarded Interstitial (actual code not provided in source) ``` -------------------------------- ### Create an AdView Instance in GDScript Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/get_started Initialize the AdMob SDK and create an AdView instance for banner ads. This example shows how to select the correct ad unit ID based on the operating system. ```gdscript extends Node2D var _ad_view : AdView func _ready(): #The initializate needs to be done only once, ideally at app launch. MobileAds.initialize() func _create_ad_view() -> void: #free memory if _ad_view: destroy_ad_view() var unit_id : String if OS.get_name() == "Android": unit_id = "ca-app-pub-3940256099942544/6300978111" elif OS.get_name() == "iOS": unit_id = "ca-app-pub-3940256099942544/2934735716" _ad_view = AdView.new(unit_id, AdSize.BANNER, AdPosition.TOP) ``` -------------------------------- ### Accessing AdapterResponseInfo in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info Example of how to retrieve and access properties of AdapterResponseInfo within a C# callback. ```APIDOC ## Accessing AdapterResponseInfo in C# ### Description This C# code demonstrates how to get the `AdapterResponseInfo` object from an interstitial ad's response and access its various properties. ### Method ```csharp private void OnInterstitialAdPaid(AdValue adValue) { AdapterResponseInfo loadedAdapterResponseInfo = interstitialAd.GetResponseInfo().LoadedAdapterResponseInfo; AdError adError = loadedAdapterResponseInfo.AdError; string adSourceId = loadedAdapterResponseInfo.AdSourceId; string adSourceInstanceId = loadedAdapterResponseInfo.AdSourceInstanceId; string adSourceInstanceName = loadedAdapterResponseInfo.AdSourceInstanceName; string adSourceName = loadedAdapterResponseInfo.AdSourceName; string adapterClassName = loadedAdapterResponseInfo.AdapterClassName; Godot.Collections.Dictionary adUnitMapping = loadedAdapterResponseInfo.AdUnitMapping; int latencyMillis = loadedAdapterResponseInfo.LatencyMillis; } ``` ``` -------------------------------- ### Accessing AdapterResponseInfo in GDScript Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info Example of how to retrieve and access properties of AdapterResponseInfo within a GDScript callback. ```APIDOC ## Accessing AdapterResponseInfo in GDScript ### Description This GDScript code demonstrates how to get the `AdapterResponseInfo` object from an interstitial ad's response and access its various properties. ### Method ```gdscript func _on_interstitial_ad_paid(ad_value: AdValue) -> void: var loaded_adapter_response_info := interstitial_ad.get_response_info().loaded_adapter_response_info var ad_error: AdError = loaded_adapter_response_info.ad_error var ad_source_id: String = loaded_adapter_response_info.ad_source_id var ad_source_instance_id: String = loaded_adapter_response_info.ad_source_instance_id var ad_source_instance_name: String = loaded_adapter_response_info.ad_source_instance_name var ad_source_name: String = loaded_adapter_response_info.ad_source_name var adapter_class_name: String = loaded_adapter_response_info.adapter_class_name var ad_unit_mapping: Dictionary = loaded_adapter_response_info.ad_unit_mapping var latency_millis: int = loaded_adapter_response_info.latency_millis ``` ``` -------------------------------- ### Check Consent Status on App Start Source: https://poingstudios.github.io/godot-admob-plugin/latest/privacy/user_messaging_tools/get_started Request an update of the user's consent information at every app launch to determine if a consent form needs to be displayed. ```GDScript extends Node func _ready(): var request := ConsentRequestParameters.new() # Set tag for underage of consent. false means users are not underage. request.tag_for_under_age_of_consent = false UserMessagingPlatform.consent_information.update(request, _on_consent_info_updated_success, _on_consent_info_updated_failure) func _on_consent_info_updated_success(): # The consent information state was updated. # You are now ready to check if a form is available. pass func _on_consent_info_updated_failure(form_error : FormError): # Handle the error. pass ``` ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Ump.Api; using PoingStudios.AdMob.Ump.Core; public partial class UmpExample : Node { public override void _Ready() { var request = new ConsentRequestParameters(); // Set tag for underage of consent. false means users are not underage. request.TagForUnderAgeOfConsent = false; UserMessagingPlatform.ConsentInformation.Update(request, OnConsentInfoUpdatedSuccess, OnConsentInfoUpdatedFailure); } private void OnConsentInfoUpdatedSuccess() { // The consent information state was updated. // You are now ready to check if a form is available. } private void OnConsentInfoUpdatedFailure(FormError formError) { // Handle the error. } } ``` -------------------------------- ### Configure FullScreenContentCallback Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/rewarded_interstitial Sets up event handlers for ad lifecycle events such as clicks, dismissals, and impression tracking before showing the ad. ```GDScript extends Node2D var _rewarded_interstitial_ad : RewardedInterstitialAd var _full_screen_content_callback := FullScreenContentCallback.new() func _ready() -> void: #... _full_screen_content_callback.on_ad_clicked = func() -> void: print("on_ad_clicked") _full_screen_content_callback.on_ad_dismissed_full_screen_content = func() -> void: print("on_ad_dismissed_full_screen_content") _full_screen_content_callback.on_ad_failed_to_show_full_screen_content = func(ad_error : AdError) -> void: print("on_ad_failed_to_show_full_screen_content") _full_screen_content_callback.on_ad_impression = func() -> void: print("on_ad_impression") _full_screen_content_callback.on_ad_showed_full_screen_content = func() -> void: print("on_ad_showed_full_screen_content") func _on_load_pressed(): #... var rewarded_interstitial_ad_load_callback := RewardedInterstitialAdLoadCallback.new() #... rewarded_interstitial_ad_load_callback.on_ad_loaded = func(rewarded_interstitial_ad : RewardedInterstitialAd) -> void: print("rewarded interstitial ad loaded" + str(rewarded_interstitial_ad._uid)) _rewarded_interstitial_ad = rewarded_interstitial_ad _rewarded_interstitial_ad.full_screen_content_callback = _full_screen_content_callback #... ``` ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; using PoingStudios.AdMob.Api.Listeners; public partial class RewardedInterstitialAdExample : Node2D { private RewardedInterstitialAd _rewardedInterstitialAd; private FullScreenContentCallback _fullScreenContentCallback; public override void _Ready() { //... _fullScreenContentCallback = new FullScreenContentCallback { OnAdClicked = () => GD.Print("on_ad_clicked"), OnAdDismissedFullScreenContent = () => GD.Print("on_ad_dismissed_full_screen_content"), OnAdFailedToShowFullScreenContent = (AdError adError) => GD.Print("on_ad_failed_to_show_full_screen_content"), OnAdImpression = () => GD.Print("on_ad_impression"), OnAdShowedFullScreenContent = () => GD.Print("on_ad_showed_full_screen_content") }; } private void OnLoadPressed() { //... var rewardedInterstitialAdLoadCallback = new RewardedInterstitialAdLoadCallback { //... OnAdLoaded = (RewardedInterstitialAd rewardedInterstitialAd) => { GD.Print("rewarded interstitial ad loaded"); _rewardedInterstitialAd = rewardedInterstitialAd; _rewardedInterstitialAd.FullScreenContentCallback = _fullScreenContentCallback; } }; //... } } ``` -------------------------------- ### AdColony Adapter Error Codes Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/ad_colony Reference guide for troubleshooting AdColony ad load failures on Android and iOS. ```APIDOC ## AdColony Adapter Error Codes ### Description This section outlines the error codes returned by the AdColony adapter when an ad fails to load. Publishers can use these codes to diagnose issues with ad requests. ### Android Error Codes | Error code | Reason | |---|---| | 100 | The AdColony SDK returned an error. | | 101 | Invalid server parameters (e.g. missing Zone ID). | | 102 | An ad was already requested for the same Zone ID. | | 103 | The AdColony SDK returned an initialization error. | | 104 | The requested banner size does not map to a valid AdColony ad size. | | 105 | Presentation error due to ad not loaded. | | 106 | Context used to initialize the AdColony SDK was not an Activity instance. | ### iOS Error Codes | Error code | Reason | |---|---| | 0 - 3 | AdColony SDK returned an error. See documentation for more details. | | 101 | Invalid server parameters (e.g. missing Zone ID). | | 102 | Root view controller presenting the ad is nil. | | 103 | The AdColony SDK returned an initialization error. | | 104 | The AdColony SDK does not support being configured twice within a five second period. | | 105 | Failed to show ad. | | 106 | Zone used for rewarded is not a rewarded zone on AdColony portal. | ``` -------------------------------- ### Create a Smart Banner in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/smart_banner Initializes an AdView with the SmartBanner size at the top of the screen using the PoingStudios AdMob API. ```C# using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; // Create a Smart Banner at the top of the screen. var adView = new AdView(unitId, AdSize.SmartBanner, AdPosition.Top); ``` -------------------------------- ### Configure FullScreenContentCallback for Interstitial Ads (C#) Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/interstitial Set up event handlers for interstitial ad lifecycle events in C#. Ensure the callback is configured before presenting the ad. ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; using PoingStudios.AdMob.Api.Listeners; public partial class InterstitialAdExample : Node2D { private InterstitialAd _interstitialAd; private FullScreenContentCallback _fullScreenContentCallback; public override void _Ready() { //... _fullScreenContentCallback = new FullScreenContentCallback { OnAdClicked = () => GD.Print("on_ad_clicked"), OnAdDismissedFullScreenContent = () => GD.Print("on_ad_dismissed_full_screen_content"), OnAdFailedToShowFullScreenContent = (AdError adError) => GD.Print("on_ad_failed_to_show_full_screen_content"), OnAdImpression = () => GD.Print("on_ad_impression"), OnAdShowedFullScreenContent = () => GD.Print("on_ad_showed_full_screen_content") }; } private void OnLoadPressed() { //... var interstitialAdLoadCallback = new InterstitialAdLoadCallback { //... OnAdLoaded = (InterstitialAd interstitialAd) => { GD.Print("interstitial ad loaded"); _interstitialAd = interstitialAd; _interstitialAd.FullScreenContentCallback = _fullScreenContentCallback; } }; //... } } ``` -------------------------------- ### Get Portrait Anchored Adaptive Banner Ad Size Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/anchored_adaptive Obtain an adaptive ad size for portrait orientation. Requires the width of the view where the ad will be placed. ```gdscript var ad_size = AdSize.get_portrait_anchored_adaptive_banner_ad_size(width) ``` -------------------------------- ### Get Landscape Anchored Adaptive Banner Ad Size Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/anchored_adaptive Obtain an adaptive ad size for landscape orientation. Requires the width of the view where the ad will be placed. ```gdscript var ad_size = AdSize.get_landscape_anchored_adaptive_banner_ad_size(width) ``` -------------------------------- ### Configure FullScreenContentCallback for Rewarded Ads (C#) Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/rewarded Set up a FullScreenContentCallback to handle events such as ad clicks, dismissals, failures, impressions, and successful shows for a rewarded ad. This callback must be configured before presenting the ad. ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; using PoingStudios.AdMob.Api.Listeners; public partial class RewardedAdExample : Node2D { private RewardedAd _rewardedAd; private FullScreenContentCallback _fullScreenContentCallback; public override void _Ready() { //... _fullScreenContentCallback = new FullScreenContentCallback { OnAdClicked = () => GD.Print("on_ad_clicked"), OnAdDismissedFullScreenContent = () => GD.Print("on_ad_dismissed_full_screen_content"), OnAdFailedToShowFullScreenContent = (AdError adError) => GD.Print("on_ad_failed_to_show_full_screen_content"), OnAdImpression = () => GD.Print("on_ad_impression"), OnAdShowedFullScreenContent = () => GD.Print("on_ad_showed_full_screen_content") }; } private void OnLoadPressed() { //... var rewardedAdLoadCallback = new RewardedAdLoadCallback { //... OnAdLoaded = (RewardedAd rewardedAd) => { GD.Print("rewarded ad loaded"); _rewardedAd = rewardedAd; _rewardedAd.FullScreenContentCallback = _fullScreenContentCallback; } }; //... } } ``` -------------------------------- ### Initialize Google Mobile Ads SDK (C#) Source: https://poingstudios.github.io/godot-admob-plugin/stable Call MobileAds.Initialize() once during app launch to initialize the SDK. A completion listener triggers when initialization is finished or times out. Essential for mediation to ensure adapters are ready before ad requests. ```C# public override void _Ready() { MobileAds.Initialize(); } ``` -------------------------------- ### Create and Load an Adaptive Anchor Banner Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/anchored_adaptive Instantiate an AdView with an ad unit ID, adaptive size, and position, then load the ad. This is similar to loading a standard banner. ```gdscript var ad_view = AdView.new() ad_view.ad_unit_id = "YOUR_AD_UNIT_ID" ad_view.ad_size = ad_size ad_view.position = Vector2(x, y) var ad_request = AdRequest.new() ad_view.load_ad(ad_request) ``` -------------------------------- ### Get Current Orientation Anchored Adaptive Banner Ad Size Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/anchored_adaptive Obtain an adaptive ad size for the current device orientation. Requires the width of the view where the ad will be placed. ```gdscript var ad_size = AdSize.get_current_orientation_anchored_adaptive_banner_ad_size(width) ``` -------------------------------- ### Create a Smart Banner in GDScript Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/smart_banner Initializes an AdView with the SMART_BANNER size at the top of the screen. ```GDScript # Create a Smart Banner at the top of the screen. var ad_view := AdView.new(unit_id, AdSize.SMART_BANNER, AdPosition.TOP) ``` -------------------------------- ### Initialize Mobile Ads SDK and Verify Adapter Status Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/get_started Initializes the Mobile Ads SDK and iterates through the adapter status map to verify successful initialization of each network. ```GDScript extends Control func _ready() -> void: var on_initialization_complete_listener := OnInitializationCompleteListener.new() on_initialization_complete_listener.on_initialization_complete = _on_initialization_complete MobileAds.initialize(on_initialization_complete_listener) func _on_initialization_complete(initialization_status : InitializationStatus) -> void: print("MobileAds initialization complete") for key in initialization_status.adapter_status_map: var adapterStatus : AdapterStatus = initialization_status.adapter_status_map[key] prints( "Key:", key, "Latency:", adapterStatus.latency, "Initialization Status:", adapterStatus.initialization_status, "Description:", adapterStatus.description ) ``` ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Listeners; using PoingStudios.AdMob.Api.Core; public partial class MediationExample : Control { public override void _Ready() { var onInitializationCompleteListener = new OnInitializationCompleteListener { OnInitializationComplete = OnInitializationComplete }; MobileAds.Initialize(onInitializationCompleteListener); } private void OnInitializationComplete(InitializationStatus initializationStatus) { GD.Print("MobileAds initialization complete"); foreach (var kvp in initializationStatus.AdapterStatusMap) { string key = kvp.Key; AdapterStatus adapterStatus = kvp.Value; GD.Print( "Key: ", key, " Latency: ", adapterStatus.Latency, " Initialization Status: ", adapterStatus.State, " Description: ", adapterStatus.Description ); } } } ``` -------------------------------- ### Load App Open Ad in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open This C# snippet demonstrates how to load an app open ad. It requires an ad unit ID and proper handling of ad loading callbacks. Be cautious about retrying loads after failures. ```csharp public void LoadAppOpenAd() { // Clean up the old ad before loading a new one. if (_appOpenAd != null) { _appOpenAd.Destroy(); _appOpenAd = null; } GD.Print("Loading the app open ad."); // Create our request used to load the ad. var adRequest = new AdRequest(); // Send the request to load the ad. var loadCallback = new AppOpenAdLoadCallback(); loadCallback.OnAdLoaded = (ad) => { GD.Print("App open ad loaded with response : " + ad.GetResponseInfo().ResponseId); _appOpenAd = ad; RegisterEventHandlers(ad); }; loadCallback.OnAdFailedToLoad = (error) => { GD.Print("App open ad failed to load an ad with error : " + error.Message); }; new AppOpenAdLoader().Load(_adUnitId, adRequest, loadCallback); } ``` -------------------------------- ### Accessing AdMob Response Info in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info This C# snippet shows how to get response information from an interstitial ad, including the response ID, mediation adapter class name, adapter responses, loaded adapter response info, and extras such as mediation group name. ```C# private void OnInterstitialAdLoaded(InterstitialAd interstitialAd) { ResponseInfo responseInfo = interstitialAd.ResponseInfo; string responseId = responseInfo.ResponseId; string mediationAdapterClassName = responseInfo.MediationAdapterClassName; System.Collections.Generic.List adapterResponses = responseInfo.AdapterResponses; AdapterResponseInfo loadedAdapterResponseInfo = responseInfo.LoadedAdapterResponseInfo; Godot.Collections.Dictionary extras = responseInfo.ResponseExtras; string mediationGroupName = extras.ContainsKey("mediation_group_name") ? extras["mediation_group_name"].ToString() : ""; string mediationABTestName = extras.ContainsKey("mediation_ab_test_name") ? extras["mediation_ab_test_name"].ToString() : ""; string mediationABTestVariant = extras.ContainsKey("mediation_ab_test_variant") ? extras["mediation_ab_test_variant"].ToString() : ""; } ``` -------------------------------- ### Configure FullScreenContentCallback for Interstitial Ads Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/interstitial Set up event handlers for interstitial ad lifecycle events. Ensure the callback is configured before presenting the ad. ```GDScript extends Node2D var _interstitial_ad : InterstitialAd var _full_screen_content_callback := FullScreenContentCallback.new() func _ready() -> void: #... _full_screen_content_callback.on_ad_clicked = func() -> void: print("on_ad_clicked") _full_screen_content_callback.on_ad_dismissed_full_screen_content = func() -> void: print("on_ad_dismissed_full_screen_content") _full_screen_content_callback.on_ad_failed_to_show_full_screen_content = func(ad_error : AdError) -> void: print("on_ad_failed_to_show_full_screen_content") _full_screen_content_callback.on_ad_impression = func() -> void: print("on_ad_impression") _full_screen_content_callback.on_ad_showed_full_screen_content = func() -> void: print("on_ad_showed_full_screen_content") func _on_load_pressed(): #... var interstitial_ad_load_callback := InterstitialAdLoadCallback.new() #... interstitial_ad_load_callback.on_ad_loaded = func(interstitial_ad : InterstitialAd) -> void: print("interstitial ad loaded" + str(interstitial_ad._uid)) _interstitial_ad = interstitial_ad _interstitial_ad.full_screen_content_callback = _full_screen_content_callback #... ``` -------------------------------- ### Configure FullScreenContentCallback for Rewarded Ads Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/rewarded Set up a FullScreenContentCallback to handle events such as ad clicks, dismissals, failures, impressions, and successful shows for a rewarded ad. This callback must be configured before presenting the ad. ```GDScript extends Node2D var _rewarded_ad : RewardedAd var _full_screen_content_callback := FullScreenContentCallback.new() func _ready() -> void: #... _full_screen_content_callback.on_ad_clicked = func() -> void: print("on_ad_clicked") _full_screen_content_callback.on_ad_dismissed_full_screen_content = func() -> void: print("on_ad_dismissed_full_screen_content") _full_screen_content_callback.on_ad_failed_to_show_full_screen_content = func(ad_error : AdError) -> void: print("on_ad_failed_to_show_full_screen_content") _full_screen_content_callback.on_ad_impression = func() -> void: print("on_ad_impression") _full_screen_content_callback.on_ad_showed_full_screen_content = func() -> void: print("on_ad_showed_full_screen_content") func _on_load_pressed(): #... var rewarded_ad_load_callback := RewardedAdLoadCallback.new() #... rewarded_ad_load_callback.on_ad_loaded = func(rewarded_ad : RewardedAd) -> void: print("rewarded ad loaded" + str(rewarded_ad._uid)) _rewarded_ad = rewarded_ad _rewarded_ad.full_screen_content_callback = _full_screen_content_callback #... ``` -------------------------------- ### Load an AdView banner Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/get_started Initialize an AdRequest and load it into the AdView instance. ```GDScript func _on_load_banner_pressed(): if _ad_view == null: _create_ad_view() var ad_request := AdRequest.new() _ad_view.load_ad(ad_request) ``` ```C# private void OnLoadBannerPressed() { if (_adView == null) CreateAdView(); var adRequest = new AdRequest(); _adView.LoadAd(adRequest); } ``` -------------------------------- ### Show App Open Ad - C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open Displays a loaded app open ad. Logs a message if the ad is not ready. ```csharp public void ShowAppOpenAd() { if (_appOpenAd != null) { GD.Print("Showing app open ad."); _appOpenAd.Show(); } else { GD.Print("App open ad is not ready yet."); } } ``` -------------------------------- ### Initialize MobileAds SDK Source: https://poingstudios.github.io/godot-admob-plugin/latest Call the initialize method during the app's launch phase to prepare the SDK for ad loading. ```GDScript func _ready() -> void: MobileAds.initialize() ``` ```C# public override void _Ready() { MobileAds.Initialize(); } ``` -------------------------------- ### Load App Open Ad - C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open Loads an app open ad and sets up expiration time. Ensure the AppOpenAdLoadCallback is correctly implemented to handle load success or failure. Cleans up any existing ad before loading a new one. ```csharp public void LoadAppOpenAd() { // Clean up the old ad before loading a new one. if (_appOpenAd != null) { _appOpenAd.Destroy(); _appOpenAd = null; } GD.Print("Loading the app open ad."); // Create our request used to load the ad. var adRequest = new AdRequest(); // Send the request to load the ad. var loadCallback = new AppOpenAdLoadCallback(); loadCallback.OnAdFailedToLoad = (error) => { // If the operation failed, an error is returned. GD.Print("App open ad failed to load an ad with error : " + error.Message); }; loadCallback.OnAdLoaded = (ad) => { // If the operation completed successfully, no error is returned. GD.Print("App open ad loaded with response : " + ad.GetResponseInfo().ResponseId); // App open ads can be preloaded for up to 4 hours. _expireTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + (4 * 60 * 60); _appOpenAd = ad; RegisterEventHandlers(ad); }; new AppOpenAdLoader().Load(_adUnitId, adRequest, loadCallback); } ``` -------------------------------- ### Handle Application Focus In - C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open Listens for the application gaining focus and shows an app open ad if it is available. This uses Godot's notification system. ```csharp public override void _Notification(int what) { if (what == NotificationApplicationFocusIn) { // If the app is Foregrounded and the ad is available, show it. if (IsAdAvailable) { ShowAppOpenAd(); } } } ``` -------------------------------- ### AppOpenAdManager Utility Class (C#) Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open This C# class manages app open ads, handling ad loading and display logic. It's recommended to add this as a Singleton for persistence across scene changes. ```csharp using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; using PoingStudios.AdMob.Api.Listeners; using System; public partial class AppOpenAdManager : Node { private AppOpenAd _appOpenAd; private long _expireTime; private bool _isShowingAd; // These ad units are configured to always serve test ads. private string _adUnitId => OS.GetName() == "Android" ? "ca-app-pub-3940256099942544/9257395921" : "ca-app-pub-3940256099942544/5575463023"; public bool IsAdAvailable => _appOpenAd != null; public void LoadAppOpenAd() { // implementation below } public void ShowAppOpenAd() { // implementation below } } ``` -------------------------------- ### Implement Adaptive Banner Ad Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/sizes/anchored_adaptive Demonstrates initializing MobileAds and requesting an anchored adaptive banner ad in Godot. ```GDScript extends Node2D var _ad_view : AdView var _ad_listener := AdListener.new() func _ready() -> void: var on_initialization_complete_listener := OnInitializationCompleteListener.new() on_initialization_complete_listener.on_initialization_complete = func(initialization_status : InitializationStatus) -> void: _request_ad_view() MobileAds.initialize(on_initialization_complete_listener) _ad_listener.on_ad_failed_to_load = _on_ad_failed_to_load _ad_listener.on_ad_loaded = _on_ad_loaded func _request_ad_view() -> void: var unit_id : String if OS.get_name() == "Android": unit_id = "ca-app-pub-3940256099942544/6300978111" elif OS.get_name() == "iOS": unit_id = "ca-app-pub-3940256099942544/6300978111" if (_ad_view != null): _ad_view.destroy() var adaptive_size := AdSize.get_current_orientation_anchored_adaptive_banner_ad_size(AdSize.FULL_WIDTH) _ad_view = AdView.new(unit_id, adaptive_size, AdPosition.TOP) _ad_view.ad_listener = _ad_listener _ad_view.load_ad(AdRequest.new()) func _on_ad_failed_to_load(load_ad_error : LoadAdError) -> void: print("_on_ad_failed_to_load: " + load_ad_error.message) func _on_ad_loaded() -> void: print("_on_ad_loaded") ``` ```C# using Godot; using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Listeners; using PoingStudios.AdMob.Api.Core; public partial class AnchoredAdaptiveExample : Node2D { private AdView _adView; private AdListener _adListener; public override void _Ready() { var onInitializationCompleteListener = new OnInitializationCompleteListener { OnInitializationComplete = (InitializationStatus status) => RequestAdView() }; MobileAds.Initialize(onInitializationCompleteListener); _adListener = new AdListener { OnAdFailedToLoad = OnAdFailedToLoad, OnAdLoaded = OnAdLoaded }; } private void RequestAdView() { string unitId = null; if (OS.GetName() == "Android") unitId = "ca-app-pub-3940256099942544/6300978111"; else if (OS.GetName() == "iOS") unitId = "ca-app-pub-3940256099942544/6300978111"; if (_adView != null) _adView.Destroy(); var adaptiveSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSize(AdSize.FullWidth); _adView = new AdView(unitId, adaptiveSize, AdPosition.Top); _adView.AdListener = _adListener; _adView.LoadAd(new AdRequest()); } private void OnAdFailedToLoad(LoadAdError loadAdError) { GD.Print("_on_ad_failed_to_load: " + loadAdError.Message); } private void OnAdLoaded() { GD.Print("_on_ad_loaded"); } } ``` -------------------------------- ### Sample AdMob Response Info JSON Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info This JSON object represents the sample data returned for a loaded ad, detailing response ID, mediation adapter class name, adapter responses, loaded adapter response info, and response extras. ```json { "response_id": "COOllLGxlPoCFdAx4Aod-Q4A0g", "mediation_adapter_class_name": "com.google.ads.mediation.admob.AdMobAdapter", "adapter_responses": { "0": { "adapter_class_name": "com.google.ads.mediation.admob.AdMobAdapter", "latency_millis": 328, "ad_source_name": "Reservation campaign", "ad_source_id": "7068401028668408324", "ad_source_instance_name": "[DO NOT EDIT] Publisher Test Interstitial", "ad_source_instance_id": "4665218928925097", "ad_unit_mapping": {}, "ad_error": {} } }, "loaded_adapter_response_info": { "adapter_class_name": "com.google.ads.mediation.admob.AdMobAdapter", "latency_millis": 328, "ad_source_name": "Reservation campaign", "ad_source_id": "7068401028668408324", "ad_source_instance_name": "[DO NOT EDIT] Publisher Test Interstitial", "ad_source_instance_id": "4665218928925097", "ad_unit_mapping": {}, "ad_error": {} }, "response_extras": { "mediation_group_name": "Campaign" } } ``` -------------------------------- ### Initialize Google Mobile Ads SDK (GDScript) Source: https://poingstudios.github.io/godot-admob-plugin/stable Call MobileAds.initialize() once during app launch to initialize the SDK. A completion listener triggers when initialization is finished or times out. ```GDScript func _ready() -> void: MobileAds.initialize() ``` -------------------------------- ### Add Swift Paths to Build Settings (iOS) Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/meta These paths are required in the target's Build Settings under Library Search Paths to prevent compile errors when integrating Swift-based SDKs. ```bash $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) ``` ```bash $(SDKROOT)/usr/lib/swift ``` -------------------------------- ### Load Native Overlay Ad Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/native_overlay Implementation of loading a native ad with custom options and handling the completion callback. ```gdscript var _native_overlay_ad: NativeOverlayAd # These ad units are configured to always serve test ads. var _ad_unit_id: String: get: if OS.get_name() == "Android": return "ca-app-pub-3940256099942544/2247696110" return "ca-app-pub-3940256099942544/3986624511" func _load_native_ad() -> void: var ad_request := AdRequest.new() var options := NativeAdOptions.new() # Optional: configure options options.ad_choices_placement = AdChoicesPlacement.Values.TOP_RIGHT options.media_aspect_ratio = NativeMediaAspectRatio.Values.ANY NativeOverlayAd.load(_ad_unit_id, ad_request, options, _on_ad_load_finished) func _on_ad_load_finished(ad: NativeOverlayAd, error: LoadAdError) -> void: if error: print("Native ad failed to load: ", error.message) return print("Native ad loaded successfully") _native_overlay_ad = ad _render_native_ad() ``` ```csharp using PoingStudios.AdMob.Api; using PoingStudios.AdMob.Api.Core; private NativeOverlayAd _nativeOverlayAd; // These ad units are configured to always serve test ads. private string _adUnitId => OS.GetName() == "Android" ? "ca-app-pub-3940256099942544/2247696110" : "ca-app-pub-3940256099942544/3986624511"; private void LoadNativeAd() { var adRequest = new AdRequest(); var options = new NativeAdOptions(); // Optional: configure options options.AdChoicesPlacement = AdChoicesPlacement.Values.TopRight; options.MediaAspectRatio = NativeMediaAspectRatio.Values.Any; NativeOverlayAd.Load(_adUnitId, adRequest, options, OnAdLoadFinished); } private void OnAdLoadFinished(NativeOverlayAd ad, LoadAdError error) { if (error != null) { GD.Print("Native ad failed to load: " + error.Message); return; } GD.Print("Native ad loaded successfully"); _nativeOverlayAd = ad; RenderNativeAd(); } ``` -------------------------------- ### Vungle Mediation Configuration Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/vungle Configuring mediation extras for Vungle Interstitial and Rewarded ads in Godot. ```APIDOC ## Vungle Mediation Configuration ### Description Configure network-specific parameters for Vungle ads using mediation extras classes. These parameters are passed to the AdRequest object to customize ad behavior. ### Parameters #### Request Body (Mediation Extras Classes) - **sound_enabled** (boolean) - Optional - Determines whether sound should be enabled when playing video ads. - **user_id** (string) - Optional - Incentivized User ID for Liftoff Monetize integration. - **all_placements** (array) - Optional - Array of all Placement IDs within the app (not required for Vungle SDK 6.2.0+). ### Request Example ``` var vungle_mediation_extras := VungleInterstitialMediationExtras.new() vungle_mediation_extras.sound_enabled = true vungle_mediation_extras.user_id = "user_123" var ad_request := AdRequest.new() ad_request.mediation_extras.append(vungle_mediation_extras) ``` ``` -------------------------------- ### AppOpenAdManager Utility Class (GDScript) Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open This GDScript class manages app open ads, handling ad loading and display logic. It's recommended to add this as an Autoload (Singleton) for persistence across scene changes. ```gdscript extends Node var _app_open_ad: AppOpenAd var _expire_time: int = 0 var _is_showing_ad: bool = false # These ad units are configured to always serve test ads. var _ad_unit_id: String: get: if OS.get_name() == "Android": return "ca-app-pub-3940256099942544/9257395921" return "ca-app-pub-3940256099942544/5575463023" func is_ad_available() -> bool: return _app_open_ad != null func load_app_open_ad() -> void: pass # implementation below func show_app_open_ad() -> void: pass # implementation below ``` -------------------------------- ### Add Runpath Search Path for Swift (iOS) Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/meta This path must be added to the target's Build Settings under Runpath Search Paths to ensure Swift libraries are found at runtime. ```bash /usr/lib/swift ``` -------------------------------- ### Create Swift File to Resolve Build Errors Source: https://poingstudios.github.io/godot-admob-plugin/latest If you encounter a '__swift_FORCE_LOAD_' error during the build process on iOS, create an empty Swift file in your Xcode project. This often resolves linking issues. ```swift import Foundation ``` -------------------------------- ### Listen to AdView signals Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/banner/get_started Register an AdListener to handle lifecycle events like loading, clicking, and closing. ```GDScript func register_ad_listener() -> void: if _ad_view != null: var ad_listener := AdListener.new() ad_listener.on_ad_failed_to_load = func(load_ad_error : LoadAdError) -> void: print("_on_ad_failed_to_load: " + load_ad_error.message) ad_listener.on_ad_clicked = func() -> void: print("_on_ad_clicked") ad_listener.on_ad_closed = func() -> void: print("_on_ad_closed") ad_listener.on_ad_impression = func() -> void: print("_on_ad_impression") ad_listener.on_ad_loaded = func() -> void: print("_on_ad_loaded") ad_listener.on_ad_opened = func() -> void: print("_on_ad_opened") _ad_view.ad_listener = ad_listener ``` ```C# private void RegisterAdListener() { if (_adView != null) { _adView.AdListener = new AdListener { OnAdFailedToLoad = (LoadAdError loadAdError) => GD.Print("_on_ad_failed_to_load: " + loadAdError.Message), OnAdClicked = () => GD.Print("_on_ad_clicked"), OnAdClosed = () => GD.Print("_on_ad_closed"), OnAdImpression = () => GD.Print("_on_ad_impression"), OnAdLoaded = () => GD.Print("_on_ad_loaded"), OnAdOpened = () => GD.Print("_on_ad_opened") }; } } ``` -------------------------------- ### Configure Rewarded Mediation Extras Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/vungle Pass a list of placement IDs to the Vungle SDK for rewarded ads using mediation extras. ```GDScript var vungle_mediation_extras := VungleRewardedMediationExtras.new() if OS.get_name() == "iOS": vungle_mediation_extras.all_placements = ["ios_placement1", "ios_placement2"] elif OS.get_name() == "Android": vungle_mediation_extras.all_placements = ["android_placement1", "android_placement2"] var ad_request := AdRequest.new() ad_request.mediation_extras.append(vungle_mediation_extras) ``` ```C# var vungleMediationExtras = new VungleRewardedMediationExtras(); if (OS.GetName() == "iOS") { vungleMediationExtras.AllPlacements = new string[] { "ios_placement1", "ios_placement2" }; } else if (OS.GetName() == "Android") { vungleMediationExtras.AllPlacements = new string[] { "android_placement1", "android_placement2" }; } var adRequest = new AdRequest(); adRequest.MediationExtras.Add(vungleMediationExtras); ``` -------------------------------- ### Configure Info.plist for App Tracking Transparency Source: https://poingstudios.github.io/godot-admob-plugin/latest/privacy/user_messaging_tools/idfa_support Add the NSUserTrackingUsageDescription key to your Info.plist file to provide a custom message for the iOS system tracking dialog. ```xml NSUserTrackingUsageDescription This identifier will be used to deliver personalized ads to you. ``` -------------------------------- ### Control Ad Visibility and Lifecycle Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/native_overlay Methods to show, hide, or destroy the native ad instance to manage memory usage. ```GDScript # To hide the ad _native_overlay_ad.hide() # To show it again _native_overlay_ad.show() # To destroy it (required when finished) _native_overlay_ad.destroy() _native_overlay_ad = null ``` ```C# // To hide the ad _nativeOverlayAd.Hide(); // To show it again _nativeOverlayAd.Show(); // To destroy it (required when finished) _nativeOverlayAd.Destroy(); _nativeOverlayAd = null; ``` -------------------------------- ### Configure AdColony mediation parameters Source: https://poingstudios.github.io/godot-admob-plugin/latest/mediate/integrate_partner_networks/ad_colony Set up AdColonyAppOptions and AdColonyMediationExtras to customize ad requests and SDK behavior. ```gdscript # Using AdColonyAppOptions var adcolony_app_options := AdColonyAppOptions.new() adcolony_app_options.set_user_id("your_user_id") adcolony_app_options.set_test_mode(true) # Using AdColonyMediationExtras var ad_request := AdRequest.new() var ad_colony_mediation_extras := AdColonyMediationExtras.new() ad_colony_mediation_extras.show_post_popup = false ad_colony_mediation_extras.show_pre_popup = true ad_request.mediation_extras.append(ad_colony_mediation_extras) ``` ```csharp // Using AdColonyAppOptions var adColonyAppOptions = new AdColonyAppOptions(); adColonyAppOptions.SetUserId("your_user_id"); adColonyAppOptions.SetTestMode(true); // Using AdColonyMediationExtras var adRequest = new AdRequest(); var adColonyMediationExtras = new AdColonyMediationExtras(); adColonyMediationExtras.ShowPostPopup = false; adColonyMediationExtras.ShowPrePopup = true; adRequest.MediationExtras.Add(adColonyMediationExtras); ``` -------------------------------- ### Register App Open Ad Event Handlers in C# Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open This C# snippet demonstrates how to register event handlers for app open ads. It includes callbacks for ad paid, impression, click, content shown, content closed, and failure to show. ```csharp private void RegisterEventHandlers(AppOpenAd ad) { // Raised when the ad is estimated to have earned money. ad.OnAdPaid = (adValue) => { GD.Print($"App open ad paid {adValue.ValueMicros} {adValue.CurrencyCode}."); }; var contentCallback = new FullScreenContentCallback(); // Raised when an impression is recorded for an ad. contentCallback.OnAdImpression = () => GD.Print("App open ad recorded an impression."); // Raised when a click is recorded for an ad. contentCallback.OnAdClicked = () => GD.Print("App open ad was clicked."); // Raised when an ad opened full screen content. contentCallback.OnAdShowedFullScreenContent = () => GD.Print("App open ad full screen content opened."); // Raised when the ad closed full screen content. contentCallback.OnAdDismissedFullScreenContent = () => GD.Print("App open ad full screen content closed."); // Raised when the ad failed to open full screen content. contentCallback.OnAdFailedToShowFullScreenContent = (error) => GD.Print("App open ad failed to open full screen content with error : " + error.Message); ad.FullScreenContentCallback = contentCallback; } ``` -------------------------------- ### Load App Open Ad - GDScript Source: https://poingstudios.github.io/godot-admob-plugin/latest/ad_formats/app_open Loads an app open ad and sets up expiration time. Ensure the AppOpenAdLoadCallback is correctly implemented to handle load success or failure. ```gdscript func load_app_open_ad() -> void: # ... # Send the request to load the ad. var load_callback := AppOpenAdLoadCallback.new() load_callback.on_ad_failed_to_load = func(error: LoadAdError): # If the operation failed, an error is returned. print("App open ad failed to load an ad with error : " + error.message) load_callback.on_ad_loaded = func(ad: AppOpenAd): # If the operation completed successfully, no error is returned. print("App open ad loaded with response : " + ad.get_response_info().response_id) # App open ads can be preloaded for up to 4 hours. _expire_time = Time.get_unix_time_from_system() + (4 * 60 * 60) _app_open_ad = ad _register_event_handlers(ad) ``` -------------------------------- ### Access ResponseInfo on Ad Failed to Load (C#) Source: https://poingstudios.github.io/godot-admob-plugin/latest/advanced_topics/response_info This C# snippet shows how to retrieve and print the `ResponseInfo` object when an ad fails to load, which is helpful for troubleshooting ad loading problems. ```csharp private void OnInterstitialAdFailedToLoad(LoadAdError loadAdError) { ResponseInfo responseInfo = loadAdError.ResponseInfo; GD.Print(responseInfo); } ```