Plugin.MauiMTAdmob 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.MauiMTAdmob --version 1.0.1                
NuGet\Install-Package Plugin.MauiMTAdmob -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.MauiMTAdmob" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.MauiMTAdmob --version 1.0.1                
#r "nuget: Plugin.MauiMTAdmob, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.MauiMTAdmob as a Cake Addin
#addin nuget:?package=Plugin.MauiMTAdmob&version=1.0.1

// Install Plugin.MauiMTAdmob as a Cake Tool
#tool nuget:?package=Plugin.MauiMTAdmob&version=1.0.1                

Stop the WAR in Ukraine!

MAUIMtAdmob plugin for MAUI (Android & iOS)

With this Plugin you can add a Google Admob Ads inside your MAUI Projects with a single line!!! This plugin supports: Banners, Interstitial and Rewarded Videos

Please, support me

If possible, please, support my work with few coffees or even better with a Membership! You can do it here: Buy Me A Coffee Your help allows me to continue to spend time on this project and continue to maintain and update it with new features and to be ready for the new Google SDK 20: Google SDK 20 Migration.

Setup

This plugin supports:
  • Maui (Android and iOS)

Disclaimer

This plugin is free of charge and you may use it as you like, but regardless of your situation and usage, I won�t be held responsible of any loss.

How to use MauiMTAdmob

You can find a tutorial on my blog: https://www.xamarinexpert.it/admob-made-easy/ (Version for Xamarin, I'll update it with the new version for MAUI)

To add a banner in your project

To add a Banner on a page you have two options:

1) XAML
<controls:MTAdView x:Name="myAds"/>

remember to add this line in your XAML:

xmlns:controls="clr-namespace:Plugin.MauiMTAdmob.Controls;assembly=Plugin.MauiMTAdmob"

As you can have different Banner Ids for iOS and for Android, you could use the OnPlatform-Property like this:

<controls:MTAdView x:Name="myAds" AdsId="{OnPlatform Android='ca-app-pub-3940256099942544/6300978111', 
                                   iOS='ca-app-pub-3940256099942544/2934735716'}"/>

Or set it in App.xaml (similar to HeightRequest as explained below) for all banners in your app.

2) Code
MTAdView ads = new MTAdView();
Important

To test the banner during the development google uses two Banner Id, one for Android and the other for iOS. Use them then remember to replace them with your own IDs:

Android: ca-app-pub-3940256099942544/6300978111
iOS: ca-app-pub-3940256099942544/2934735716

Properties

For each AdView if you want, you can set these properties:

AdsId: To add the id of your ads

PersonalizedAds: You can set it to False if you want to use generic ads (for GDPR...) (It works only for Android Banners, for the others, you must ask for consent)

For GDPR it's better to rely on a custom consent instead or using the non personalized ads as I cannot guarantee it works. So it's better if you create a custom consent

Global Properties

AdsId: To add the id of your ads

PersonalizedAds: You can set it to False if you want to use generic ads (for GDPR...) (It works only for Android Banners, for the others, you must ask for consent) For GDPR it's better to rely on a custom consent instead or using the non personalized ads as I cannot guarantee it works. So it's better if you create a custom consent

TestDevices: You can add here the ID of your test devices

You can use Global Properties in this way:

CrossMauiMTAdmob.Current.UserPersonalizedAds = true;

Interstitial

You can show an interstitial with a single line of code:

CrossMauiMTAdmob.Current.ShowInterstitial();

To Load an interstitial you can use this line:

CrossMauiMTAdmob.Current.LoadInterstitial("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if an interstitial is loaded:

CrossMauiMTAdmob.Current.IsInterstitialLoaded();

Rewarded

You can show a Rewarded video with a single line of code:

CrossMauiMTAdmob.Current.ShowRewarded();

To Load a Rewarded Video you can use this line:

CrossMauiMTAdmob.Current.LoadRewarded("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if a rewarded is loaded:

CrossMauiMTAdmob.Current.IsRewardedLoaded();

Rewarded Interstitial

You can show a Rewarded video with a single line of code:

CrossMauiMTAdmob.Current.ShowRewardInterstitial();

To Load a Rewarded Video you can use this line:

CrossMauiMTAdmob.Current.LoadRewardInterstitial("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

To see if a rewarded interstitial is loaded:

CrossMauiMTAdmob.Current.IsRewardInterstitialLoaded();

Events for Banners

Just in case you need, the Banner ads offer 4 events:

AdsClicked		When a user clicks on the ads
AdsClosed		When the user closes the ads
AdsImpression	Called when an impression is recorded for an ad.
AdsOpened		When the ads is opened
AdsFailedToLoad Ads couldn't be loaded
AdsLoaded       Ads loaded

Events for Interstitials

the Interstitial ads offer 3 events:

OnInterstitialLoaded        When it's loaded
OnInterstitialOpened        When it's opened      
OnInterstitialClosed        When it's closed
OnInterstitialFailedToLoad
OnInterstitialFailedToShow

Events for Rewarded Videos

The Rewarded Videos offer 7 events:

OnRewardedLoaded                       
OnRewardedFailedToLoad        
OnRewardedFailedToShow
OnRewardedOpened
OnRewardedClosed
OnRewardedImpression

Events for Interstitials and Rewarded

The Rewarded Videos offer 7 events:

OnRewardedLoaded                       
OnRewardedFailedToLoad        
OnRewardedFailedToShow
OnRewardedOpened
OnRewardedClosed
OnRewardedImpression

Events for Rewarded and Rewarded interstitials

The Rewarded Videos offer 7 events:

OnUserEarnedReward

Important

Remember to include the MTAdmob library with this code (usually it's added automatically):

using Plugin.MauiMTAdmob;

Important for Android

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() with your AdMob App ID. This needs to be done only once, ideally at app launch. For example:

 protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            MobileAds.Initialize(this);
        }

Remember to add this to your AppManifest:


<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
           android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

If your Ads are not displayed on your Android Emulator, make sure your Emulator has Google Play Store API installed, otherwise you'll find this message in your Debugger Console:

[GooglePlayServicesUtil] Google Play Store is missing.

If it's still not showing ads after adding Play Store, open Google Play Store on your emulator. There might be some config work to be done by Play Store, e.g. login with your google account, so just start it and make sure it's working fine on your emulator.

IMPORTANT FOR IOS:

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.SharedInstance.Start with your AdMob App ID. This needs to be done only once, ideally at app launch. For example:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            MobileAds.SharedInstance.Start(CompletionHandler);   <--
            return base.FinishedLaunching(application, launchOptions);
        }

        private void CompletionHandler(InitializationStatus status) { }   <--

Edit your info.plist adding these Keys:

  <key>GADApplicationIdentifier</key>
  <string>ca-app-pub-3940256099942544~1458002511</string> <- This is a test key, replace it with your APPID
  <key>GADIsAdManagerApp</key>
  <true/>

If you are builing your app for iOS on Windows without using your Mac, then MobileAds.SharedInstance will be null and the ads will not work.

You have to build the app using your Mac to use Admob on iOS!

That's it. Cannot be easier than that 😃

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-android31.0 is compatible.  net6.0-ios was computed.  net6.0-ios15.4 is compatible.  net6.0-maccatalyst was computed.  net6.0-maccatalyst15.4 is compatible.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows10.0.19041 is compatible.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Plugin.MauiMTAdmob:

Package Downloads
MetaFrm.Maui.Essentials.net7.0

Meta Framework (Multi platform & Meta management)

MetaFrm.Maui.Essentials.net8.0

Meta Framework (Multi platform & Meta management)

AnchorAppsIT.MAUI.Controls

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Plugin.MauiMTAdmob:

Repository Stars
lswiderski/mi-scale-exporter
Mobile App to export data from Mi Body Composition Scale and upload it to Garmin Connect Cloud
marcojak/MauiMTAdmob
Version Downloads Last updated
1.7.0 316 11/2/2024
1.6.4 1,356 9/17/2024
1.6.3 908 9/3/2024
1.6.2 208 9/1/2024
1.6.1 193 8/30/2024
1.6.0 407 8/23/2024
1.5.1 880 8/9/2024
1.5.0 190 8/8/2024
1.4.5 972 7/9/2024
1.4.4 279 7/5/2024
1.4.3 452 6/18/2024
1.4.2 1,347 4/12/2024
1.4.1 733 3/19/2024
1.4.0 253 3/18/2024
1.3.3 301 3/14/2024
1.3.2 341 3/8/2024
1.3.1 472 2/22/2024
1.3.0 218 2/21/2024
1.2.1 418 2/8/2024
1.2.0 246 2/5/2024
1.1.3 256 2/2/2024
1.1.2 166 2/1/2024
1.1.1 228 1/27/2024
1.1.0 227 1/25/2024
1.0.4 8,113 5/21/2023
1.0.3 385 5/14/2023
1.0.2 2,699 12/3/2022
1.0.1 2,188 7/26/2022
1.0.0 1,419 7/19/2022

Version 1.0.1
Added user-messaging-platform-2.0.0

Version 1.0
Support for Banner, Interstitials, Rewarded, RewardedInterstitials