Skip to content

Banners

Marco edited this page Aug 17, 2021 · 2 revisions

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

  1. XAML

In your XAML file, add the MTAdView wherever you prefer: <controls:MTAdView x:Name="myAds"/>

remember to add this line in your XAML:

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

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.

  1. Code

You can add your MTAdView using:

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"/> </Setter.Value> </Setter> </Style>

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

Clone this wiki locally