MTAdmob


With this Plugin you can add a Google Admob Ads inside your Xamarin Projects with a single line!!!

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...)

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...)
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.Show("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

EVENTS

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

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