Skip to content

AdView

The AdView class is responsible for creating, loading, positioning, and displaying banner ads.

Constructors

_init / AdView

Initializes a new instance of the AdView class.

func _init(ad_unit_id: String, ad_size: AdSize, ad_position: AdPosition) -> void

Usage:

var ad_view := AdView.new("ca-app-pub-3940256099942544/6300978111", ad_size, ad_position)

public AdView(string adUnitId, AdSize adSize, AdPosition adPosition)

Usage:

AdView adView = new AdView("ca-app-pub-3940256099942544/2934735716", adSize, adPosition);


Properties

ad_listener / AdListener

The listener object that receives various ad loading and lifecycle callbacks. See AdListener.

var ad_listener: AdListener

Usage:

ad_view.ad_listener.on_ad_loaded = func():
    print("Ad loaded successfully!")

public AdListener AdListener { get; set; }

Usage:

adView.AdListener.OnAdLoaded = () => {
    GD.Print("Ad loaded successfully!");
};

on_ad_paid / OnAdPaid

Callback triggered when an impression has occurred and the ad value (revenue) is calculated. Receives an AdValue.

var on_ad_paid: Callable # Receives AdValue

Usage:

ad_view.on_ad_paid = func(ad_value: AdValue):
    print("Ad revenue generated: ", ad_value.value_micros)

public Action<AdValue> OnAdPaid { get; set; }

Usage:

adView.OnAdPaid = (adValue) => {
    GD.Print($"Ad revenue generated: {adValue.ValueMicros}");
};


Methods

load_ad / LoadAd

Loads an ad based on the request configuration.

func load_ad(ad_request: AdRequest) -> void

Usage:

var ad_request := AdRequest.new()
ad_view.load_ad(ad_request)

public void LoadAd(AdRequest adRequest)

Usage:

AdRequest adRequest = new AdRequest();
adView.LoadAd(adRequest);


destroy / Destroy

Destroys the banner and releases its native resources.

func destroy() -> void
public void Destroy()

get_response_info / GetResponseInfo

Returns information about the loaded ad's response and mediation metadata.

func get_response_info() -> ResponseInfo
public ResponseInfo GetResponseInfo()

show / Show

Displays the banner ad on screen.

func show() -> void
public void Show()

hide / Hide

Hides the banner ad from the screen.

func hide() -> void
public void Hide()

set_position / SetPosition

Sets a new position for the banner ad.

func set_position(ad_position: AdPosition) -> void
public void SetPosition(AdPosition adPosition)

get_width / GetWidth

Returns the width of the ad in density-independent pixels (dp).

func get_width() -> int
public int GetWidth()

get_height / GetHeight

Returns the height of the ad in density-independent pixels (dp).

func get_height() -> int
public int GetHeight()

get_width_in_pixels / GetWidthInPixels

Returns the width of the ad in physical screen pixels.

func get_width_in_pixels() -> int
public int GetWidthInPixels()

get_height_in_pixels / GetHeightInPixels

Returns the height of the ad in physical screen pixels.

func get_height_in_pixels() -> int
public int GetHeightInPixels()

is_collapsible / IsCollapsible

Returns whether the loaded banner ad is a collapsible banner.

func is_collapsible() -> bool
public bool IsCollapsible()