We have redirected you to our new domain: store.godotengine.org. Please update your bookmarks!

Description
Changelog
Reviews

🏁Initialize AdMob

GDScript

func _ready() -> void:
    #just need to call once
    MobileAds.initialize()

C#

using PoingStudios.AdMob.Api;

public override void _Ready()
{
    //just need to call once
    MobileAds.Initialize();
}

🎏Banner Ads

GDScript

Load (will automatically show)

# button signal on scene
func _on_load_banner_pressed() -> 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/2934735716"

    var ad_view := AdView.new(unit_id, AdSize.BANNER, AdPosition.Values.TOP)
    ad_view.load_ad(AdRequest.new())

C#

Load (will automatically show)

using Godot;
using PoingStudios.AdMob.Api;
using PoingStudios.AdMob.Api.Core;

// button signal on scene
private void OnLoadBannerPressed()
{
    string unitId = "";
    if (OS.GetName() == "Android")
    {
        unitId = "ca-app-pub-3940256099942544/6300978111";
    }
    else if (OS.GetName() == "iOS")
    {
        unitId = "ca-app-pub-3940256099942544/2934735716";
    }

    var adView = new AdView(unitId, AdSize.Banner, AdPosition.Top);
    adView.LoadAd(new AdRequest());
}

πŸ“ΊInterstitial Ads

GDScript

Load

var interstitial_ad : InterstitialAd
var interstitial_ad_load_callback := InterstitialAdLoadCallback.new()
func _ready():
    interstitial_ad_load_callback.on_ad_failed_to_load = on_interstitial_ad_failed_to_load
    interstitial_ad_load_callback.on_ad_loaded = on_interstitial_ad_loaded

# button signal on scene
func _on_load_interstitial_pressed() -> void:
    var unit_id : String
    if OS.get_name() == "Android":
        unit_id = "ca-app-pub-3940256099942544/1033173712"
    elif OS.get_name() == "iOS":
        unit_id = "ca-app-pub-3940256099942544/4411468910"

    InterstitialAdLoader.new().load(unit_id, AdRequest.new(), interstitial_ad_load_callback)

func on_interstitial_ad_failed_to_load(adError : LoadAdError) -> void:
    print(adError.message)

func on_interstitial_ad_loaded(interstitial_ad : InterstitialAd) -> void:
    self.interstitial_ad = interstitial_ad

Show

# button signal on scene
func _on_show_pressed():
    if interstitial_ad:
        interstitial_ad.show()

C#

Load

using Godot;
using PoingStudios.AdMob.Api;
using PoingStudios.AdMob.Api.Core;
using PoingStudios.AdMob.Api.Listeners;

private InterstitialAd _interstitialAd;

// button signal on scene
private void OnLoadInterstitialPressed()
{
    string unitId = "";
    if (OS.GetName() == "Android")
    {
        unitId = "ca-app-pub-3940256099942544/1033173712";
    }
    else if (OS.GetName() == "iOS")
    {
        unitId = "ca-app-pub-3940256099942544/4411468910";
    }

    new InterstitialAdLoader().Load(unitId, new AdRequest(), new InterstitialAdLoadCallback
    {
        OnAdLoaded = ad => _interstitialAd = ad,
        OnAdFailedToLoad = err => GD.Print(err.Message)
    });
}

Show

// button signal on scene
private void OnShowPressed()
{
    if (_interstitialAd != null)
    {
        _interstitialAd.Show();
    }
}

🎁Rewarded Ads

GDScript

Load

var rewarded_ad : RewardedAd
var rewarded_ad_load_callback := RewardedAdLoadCallback.new()

func _ready():
    rewarded_ad_load_callback.on_ad_failed_to_load = on_rewarded_ad_failed_to_load
    rewarded_ad_load_callback.on_ad_loaded = on_rewarded_ad_loaded

# button signal on scene
func _on_load_rewarded_pressed() -> void:
    var unit_id : String
    if OS.get_name() == "Android":
        unit_id = "ca-app-pub-3940256099942544/5224354917"
    elif OS.get_name() == "iOS":
        unit_id = "ca-app-pub-3940256099942544/1712485313"

    RewardedAdLoader.new().load(unit_id, AdRequest.new(), rewarded_ad_load_callback)

func on_rewarded_ad_failed_to_load(adError : LoadAdError) -> void:
    print(adError.message)

func on_rewarded_ad_loaded(rewarded_ad : RewardedAd) -> void:
    self.rewarded_ad = rewarded_ad

Show

# button signal on scene
func _on_show_pressed():
    if rewarded_ad:
        rewarded_ad.show()

C#

Load

using Godot;
using PoingStudios.AdMob.Api;
using PoingStudios.AdMob.Api.Core;
using PoingStudios.AdMob.Api.Listeners;

private RewardedAd _rewardedAd;

// button signal on scene
private void OnLoadRewardedPressed()
{
    string unitId = "";
    if (OS.GetName() == "Android")
    {
        unitId = "ca-app-pub-3940256099942544/5224354917";
    }
    else if (OS.GetName() == "iOS")
    {
        unitId = "ca-app-pub-3940256099942544/1712485313";
    }

    new RewardedAdLoader().Load(unitId, new AdRequest(), new RewardedAdLoadCallback
    {
        OnAdLoaded = ad => _rewardedAd = ad,
        OnAdFailedToLoad = err => GD.Print(err.Message)
    });
}

Show

// button signal on scene
private void OnShowPressed()
{
    if (_rewardedAd != null)
    {
        _rewardedAd.Show(new OnUserEarnedRewardListener
        {
            OnUserEarnedReward = reward => GD.Print($"Reward: {reward.Amount} {reward.Type}")
        });
    }
}

πŸŽπŸ“ΊRewarded Interstitial Ads

GDScript

Load

var rewarded_interstitial_ad : RewardedInterstitialAd
var rewarded_interstitial_ad_load_callback := RewardedInterstitialAdLoadCallback.new()

func _ready():
    rewarded_interstitial_ad_load_callback.on_ad_failed_to_load = on_rewarded_interstitial_ad_failed_to_load
    rewarded_interstitial_ad_load_callback.on_ad_loaded = on_rewarded_interstitial_ad_loaded

# button signal on scene
func _on_load_rewarded_interstitial_pressed() -> void:
    var unit_id : String
    if OS.get_name() == "Android":
        unit_id = "ca-app-pub-3940256099942544/5354046379"
    elif OS.get_name() == "iOS":
        unit_id = "ca-app-pub-3940256099942544/6978759866"

    RewardedInterstitialAdLoader.new().load(unit_id, AdRequest.new(), rewarded_interstitial_ad_load_callback)

func on_rewarded_interstitial_ad_failed_to_load(adError : LoadAdError) -> void:
    print(adError.message)

func on_rewarded_interstitial_ad_loaded(rewarded_interstitial_ad : RewardedInterstitialAd) -> void:
    self.rewarded_interstitial_ad = rewarded_interstitial_ad

Show

# button signal on scene
func _on_show_pressed():
    if rewarded_interstitial_ad:
        rewarded_interstitial_ad.show(on_user_earned_reward_listener)

C#

Load

using Godot;
using PoingStudios.AdMob.Api;
using PoingStudios.AdMob.Api.Core;
using PoingStudios.AdMob.Api.Listeners;

private RewardedInterstitialAd _rewardedInterstitialAd;

// button signal on scene
private void OnLoadRewardedInterstitialPressed()
{
    string unitId = "";
    if (OS.GetName() == "Android")
    {
        unitId = "ca-app-pub-3940256099942544/5354046379";
    }
    else if (OS.GetName() == "iOS")
    {
        unitId = "ca-app-pub-3940256099942544/6978759866";
    }

    new RewardedInterstitialAdLoader().Load(unitId, new AdRequest(), new RewardedInterstitialAdLoadCallback
    {
        OnAdLoaded = ad => _rewardedInterstitialAd = ad,
        OnAdFailedToLoad = err => GD.Print(err.Message)
    });
}

Show

// button signal on scene
private void OnShowPressed()
{
    if (_rewardedInterstitialAd != null)
    {
        _rewardedInterstitialAd.Show(new OnUserEarnedRewardListener
        {
            OnUserEarnedReward = reward => GD.Print($"Reward: {reward.Amount} {reward.Type}")
        });
    }
}

Changelog for version v4.3.1

No changelog provided for this version.

Reviews (0)

AdMob has no reviews yet.

Login to write a review.