MarcTron.Admob 1.2.0

MtAdmob Plugin for Xamarin

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

MtAdmob Readme

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

Release Notes

Version 1.2
With this version Loading and Showing Interstitials and rewarded videos are 2 separate events. Now the methods are:

  • void LoadInterstitial(string adUnit);
  • void ShowInterstitial();
  • bool IsInterstitialLoaded();
  • void LoadRewardedVideo(string adUnit);
  • void ShowRewardedVideo();
  • bool IsRewardedVideoLoaded();

I've removed the two methods:

  • void ShowInterstitial(string adUnit);
  • void ShowRewardedVideo(string adUnit);

Now you have to load the Interstitial or Rewarded Video and when you want you can show it. You can see if an interstitial or rewared video are loaded using the new methods

  • bool IsInterstitialLoaded();
  • bool IsRewardedVideoLoaded();

Thanks to these changes you have now more control over the 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

BANNER

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

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

remember to add this line in your XAML:

xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
CODE
AdView ads = new AdView();

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)

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)
TestDevices: You can add here the ID of your test devices

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:

Add your AdMob App ID to your app's AndroidManifest.xml file by adding the <meta-data> tag shown below:

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="[ADMOB_APP_ID]"/>
    </application>
</manifest>

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);
            MobileAds.Initialize(ApplicationContext, "xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");
            Xamarin.Forms.Forms.Init(this, savedInstanceState); 
            LoadApplication(new App());
        }

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

LINKS

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

Project website: https://www.xamarinexpert.it/Plugin/MTAdmob

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

To report any issue: https://bitbucket.org/marcojak81/mtadmob

MtAdmob Readme

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

Release Notes

Version 1.2
With this version Loading and Showing Interstitials and rewarded videos are 2 separate events. Now the methods are:

  • void LoadInterstitial(string adUnit);
  • void ShowInterstitial();
  • bool IsInterstitialLoaded();
  • void LoadRewardedVideo(string adUnit);
  • void ShowRewardedVideo();
  • bool IsRewardedVideoLoaded();

I've removed the two methods:

  • void ShowInterstitial(string adUnit);
  • void ShowRewardedVideo(string adUnit);

Now you have to load the Interstitial or Rewarded Video and when you want you can show it. You can see if an interstitial or rewared video are loaded using the new methods

  • bool IsInterstitialLoaded();
  • bool IsRewardedVideoLoaded();

Thanks to these changes you have now more control over the 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

BANNER

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

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

remember to add this line in your XAML:

xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
CODE
AdView ads = new AdView();

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)

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)
TestDevices: You can add here the ID of your test devices

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:

Add your AdMob App ID to your app's AndroidManifest.xml file by adding the <meta-data> tag shown below:

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="[ADMOB_APP_ID]"/>
    </application>
</manifest>

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);
            MobileAds.Initialize(ApplicationContext, "xx-xxx-xxx-xxxxxxxxxxxxxxxx~xxxxxxxxxx");
            Xamarin.Forms.Forms.Init(this, savedInstanceState); 
            LoadApplication(new App());
        }

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

LINKS

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

Project website: https://www.xamarinexpert.it/Plugin/MTAdmob

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

To report any issue: https://bitbucket.org/marcojak81/mtadmob

Release Notes

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

Version History

Version Downloads Last updated
1.2.0 108 4/8/2019
1.1.0 76 3/22/2019
1.0.0 68 3/5/2019