MarcTron.Admob 1.6.0

This plugin allows you to add Banner, Insterstitial and Rewarded Video Ads to your Android and iOS projects in just a line of code

Install-Package MarcTron.Admob -Version 1.6.0
dotnet add package MarcTron.Admob --version 1.6.0
<PackageReference Include="MarcTron.Admob" Version="1.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MarcTron.Admob --version 1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MtAdmob plugin for Xamarin

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

IMPORTANT

  • Remember to edit your AppManifest otherwise it will not work on Android

  • On iOS you MUST now change the Ads init. In your iOS project Replace MobileAds.Configure with MobileAds.SharedInstance.Start(CompletionHandler);
    where CompletionHandler is something like: 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 don't do this, your iOS app will crash

  • I'm slowly starting to move toward AndroidX, so it's possible that you need to install more packages in your Android project, in case of a build error,
    Visual Studio will tell you which packages you need to install.

BANNER

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

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

remember to add this line in your XAML:

xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
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

If the Banners don't appear in your app, probably it's a size problem. To solve it, add this style you your app.xaml:

<Style TargetType="controls:MTAdView">
    <Setter Property="HeightRequest">
        <Setter.Value>
            <x:OnIdiom Phone="50" Tablet="90"></x:OnIdiom>
        </Setter.Value>
    </Setter>
</Style>

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

UseRestrictedDataProcessing: For compliance with the CCPA

You can use Global Properties in this way:
CrossMTAdmob.Current.UserPersonalizedAds = true;

INTERSTITIAL

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

CrossMTAdmob.Current.ShowInterstitial();

To Load an interstitial you can use this line:

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

REWARDED VIDEO

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

CrossMTAdmob.Current.ShowRewardedVideo();

To Load a Rewarded Video you can use this line:

CrossMTAdmob.Current.LoadRewardedVideo("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

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

EVENTS FOR INTERSTITIALS

the Interstitial ads offer 3 events:

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

EVENTS FOR REWARDED VIDEOS

The Rewarded Videos offer 7 events:

OnRewarded                          When the user gets a reward
OnRewardedVideoAdClosed             When the ads is closed
OnRewardedVideoAdFailedToLoad       When the ads fails to load
OnRewardedVideoAdLeftApplication    When the users leaves the application
OnRewardedVideoAdLoaded             When the ads is loaded
OnRewardedVideoAdOpened             When the ads is opened
OnRewardedVideoStarted              When the ads starts

IMPORTANT

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

using MarcTron.Plugin;

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)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
            MobileAds.Initialize(ApplicationContext, "xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");
            Xamarin.Forms.Forms.Init(this, savedInstanceState); 
            LoadApplication(new App());
        }

Remeber to add this to your AppManifest:

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

IMPORTANT FOR IOS:

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:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~1458002511 -->
  MobileAds.Configure("xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");

  LoadApplication(new App());

  return base.FinishedLaunching(app, options);
  }

**In case the plugin doesn't install automatically the nuget package

Xamarin.Google.iOS.MobileAds

you need to add it manually.**

That's it. Cannot be easier than that :)

LINKS

Available on Nuget: https://www.nuget.org/packages/MarcTron.Admob

Tutorial: https://www.xamarinexpert.it/admob-made-easy/

To report any issue: https://github.com/marcojak/MTAdmob/issues

MtAdmob plugin for Xamarin

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

IMPORTANT

  • Remember to edit your AppManifest otherwise it will not work on Android

  • On iOS you MUST now change the Ads init. In your iOS project Replace MobileAds.Configure with MobileAds.SharedInstance.Start(CompletionHandler);
    where CompletionHandler is something like: 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 don't do this, your iOS app will crash

  • I'm slowly starting to move toward AndroidX, so it's possible that you need to install more packages in your Android project, in case of a build error,
    Visual Studio will tell you which packages you need to install.

BANNER

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

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

remember to add this line in your XAML:

xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
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

If the Banners don't appear in your app, probably it's a size problem. To solve it, add this style you your app.xaml:

<Style TargetType="controls:MTAdView">
    <Setter Property="HeightRequest">
        <Setter.Value>
            <x:OnIdiom Phone="50" Tablet="90"></x:OnIdiom>
        </Setter.Value>
    </Setter>
</Style>

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

UseRestrictedDataProcessing: For compliance with the CCPA

You can use Global Properties in this way:
CrossMTAdmob.Current.UserPersonalizedAds = true;

INTERSTITIAL

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

CrossMTAdmob.Current.ShowInterstitial();

To Load an interstitial you can use this line:

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

REWARDED VIDEO

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

CrossMTAdmob.Current.ShowRewardedVideo();

To Load a Rewarded Video you can use this line:

CrossMTAdmob.Current.LoadRewardedVideo("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

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

EVENTS FOR INTERSTITIALS

the Interstitial ads offer 3 events:

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

EVENTS FOR REWARDED VIDEOS

The Rewarded Videos offer 7 events:

OnRewarded                          When the user gets a reward
OnRewardedVideoAdClosed             When the ads is closed
OnRewardedVideoAdFailedToLoad       When the ads fails to load
OnRewardedVideoAdLeftApplication    When the users leaves the application
OnRewardedVideoAdLoaded             When the ads is loaded
OnRewardedVideoAdOpened             When the ads is opened
OnRewardedVideoStarted              When the ads starts

IMPORTANT

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

using MarcTron.Plugin;

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)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
            MobileAds.Initialize(ApplicationContext, "xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");
            Xamarin.Forms.Forms.Init(this, savedInstanceState); 
            LoadApplication(new App());
        }

Remeber to add this to your AppManifest:

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

IMPORTANT FOR IOS:

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:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~1458002511 -->
  MobileAds.Configure("xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");

  LoadApplication(new App());

  return base.FinishedLaunching(app, options);
  }

**In case the plugin doesn't install automatically the nuget package

Xamarin.Google.iOS.MobileAds

you need to add it manually.**

That's it. Cannot be easier than that :)

LINKS

Available on Nuget: https://www.nuget.org/packages/MarcTron.Admob

Tutorial: https://www.xamarinexpert.it/admob-made-easy/

To report any issue: https://github.com/marcojak/MTAdmob/issues

Release Notes

Version 1.6.0
Updated Xamarin.Google.iOS.MobileAds to 7.66 (Required for iOS 14+)
Updated GooglePlayServices.Ads.Lite to 119.1.0

Version 1.5.8
Added support for Comply with Google Play’s Families Policy (Thanks to Abdul Rahman)

Version 1.5.7
Added IsEnabled to disable the ads (banners, interstitials, rewarded videos) (Default = true)
Added UseRestrictedDataProcessing for CCPA compliance (Default = false)

Version 1.5.6
Fixed possible issue with some MONODROID versions for LoadRewardedVideo

Version 1.5.5
Updated MobileAds to 7.57.0 to avoid Apple rejection because of the reference to UIWebView

Version 1.5.0
Updated packages
Improved code
Add custom data to RewardedAd (thanks to Lordinaire)

Version 1.4.5
Automatically added Google.SignIn 4.4.0 (This version is required to compile your project).

Version 1.4.4
Removed deprecated code on iOS
Fixed issues on iOS (Please update from version 1.4.3 and read the README to init your projects)

Version 1.4.3
Added Consent option to iOS
Updated Xamarin.Google.iOS.MobileAds to 7.47.0

Version 1.4.2
Updated GooglePlayServicesAds.Lite 71.1720.1

Version 1.4.1
Fixed issue on iOS where some events weren't called on RewardedVideos in case of no internet

Version 1.4
Fixed issue with multiple events called on RewardedVideos
Improved code for Interstitials.

Version 1.3
Fixed crash on iOS with multiple Banner
To avoid compatibilty now the Banner control has been renamed from AdView to MTAdView

Version 1.2
Now Load and Show are two separate methods to give you more control over your Ads

Version 1.1
Added support for Rewarded Videos
Added events for Rewarded Videos
Added events for Interstitials

Version 1.0
Banner and Insterstitial for Android
Banner and Insterstitial for iOS

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.6.0 758 11/7/2020
1.5.8 2,050 9/27/2020
1.5.7 1,912 8/1/2020
1.5.6 1,684 6/7/2020
1.5.5 1,198 5/10/2020
1.5.0 627 4/11/2020
1.4.5 1,862 11/19/2019
1.4.4 656 10/11/2019
1.4.3 219 10/7/2019
1.4.2 301 9/7/2019
1.4.1 543 8/12/2019
1.4.0 262 8/2/2019
1.3.0 441 6/1/2019
1.2.0 325 4/8/2019
1.1.0 264 3/22/2019
1.0.0 247 3/5/2019