Intro

With this Plugin you can add Google Admob Ads inside your .NET Android apps with a single line!!! This plugin supports: Banners, Native Ads, Open Ads, Interstitial, Rewarded Videos and Rewarded Interstitials

Commercial support

If you need faster support with this plugin, or custom changes or you would like to hire me to help with the development of your project, contact me at [email protected] to discuss it further.

Important

I've added support for the consent required by Google. This support for UMP is only available in the licensed version of the plugin. Without the license, the plugin will continue to work as usual with all the other features normally available. This will allow me to continue supporting the development of the plugin. You can buy the license here. If you are a charity or your app is used to support a good cause, contact me and I'll verify and send you a free license.

If you are not ready to buy a license, if possible, please, support my work with a 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.

Cryptography

This plugin uses a cryptographic algorithm to handle the license.

Current Status

Latest version: 1.0.0

Android
Banner
Native Ads
Interstitial
Rewarded
Rewarded Interstitial
Open Ads
UMP Consent

Methods

General

Init
SetAppMuted
SetAppVolume

Ads

Banner Interstitial Rewarded Rewarded Interstitial
LoadAd LoadInterstitial LoadRewarded LoadRewardedInterstitial
  ShowInterstitial ShowRewarded ShowRewardedInterstitial
  IsInterstitialLoaded IsRewardedLoaded IsRewardedInterstitialLoaded
  GetNumberOfInterstitialsLoaded GetNumberOfRewardedLoaded GetNumberOfRewardedInterstitialsLoaded
  EmptyInterstitialAdsList EmptyRewardedAdsList EmptyRewardedInterstitialsAdsList  

Native Ads App Open Ads
LoadNativeAd -
LoadNativeAds  

Consent
InitialiseConsent
InitialiseAndShowConsentForm
ShowPrivacyOptionsForm
Reset

Events

Ads

Banner Interstitial Rewarded Rewarded Interstitial App Open Ads
AdsLoaded OnInterstitialLoaded OnRewardedLoaded OnRewardedLoaded OnAppOpenAdLoaded
AdsFailedToLoad OnInterstitialFailedToLoad OnRewardedFailedToLoad OnRewardedFailedToLoad OnAppOpenFailedToLoad
AdsImpression OnInterstitialImpression OnRewardedImpression OnRewardedImpression OnAppOpenImpression
AdsClicked OnInterstitialOpened OnRewardedOpened OnRewardedOpened OnAppOpenOpened
AdsOpened OnInterstitialFailedToShow OnRewardedFailedToShow OnRewardedFailedToShow OnAppOpenFailedToShow
AdsClosed OnInterstitialClosed OnRewardedClosed OnRewardedClosed OnAppOpenClosed
AdsSwiped OnUserEarnedReward OnAppOpenClicked
OnUserEarnedReward
Consent
OnConsentInfoUpdateSuccess
OnConsentInfoUpdateFailure
OnConsentFormDismissed
OnConsentFormLoadSuccess
OnConsentFormLoadFailure

Initialization

To initialise the plugin, you need to call the init method

void Init(Activity activity, string appId, string license = null, string nativeAdsId = null, string openAdsId = null, bool enableOpenAds = false, bool tagForUnderAgeOfConsent = false, string testDeviceId = null, bool forceTesting = false, DebugGeography geography = DebugGeography.DEBUG_GEOGRAPHY_DISABLED, bool initialiseConsentAtStartup = true);

Parameters

Parameter Type Description Default Value
activity Activity The activity to initialize the plugin with. N/A
appId string The AdMob app ID. N/A
license string The license key. null
openAdsId string The open ads ID. null
nativeAdsId string The native ads ID. null
enableOpenAds bool True to enable open ads, false otherwise. false
tagForUnderAgeOfConsent bool True to tag for under age of consent, false otherwise. false
testDeviceId string The test device ID. null
forceTesting bool True to force testing, false otherwise. false
geography DebugGeography The debug geography. DebugGeography.DEBUG_GEOGRAPHY_DISABLED
initialiseConsentAtStartup bool True to initialize consent at startup, false otherwise. true

Please note:

You don't need to call:

MobileAds.Initialize(this); (Android)

The plugin will do it for you!

Add your App Id

  • Android

You need to add your Admob APPLICATION_ID to your AppManifest:

<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="YOUR APPLICATION ID" />

Banners

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

  • XML
<Plugin.DroidMTAdmob.Controls.MTAdView></Plugin.DroidMTAdmob.Controls.MTAdView>
  • Code
MTAdView ads = new MTAdView();

Now you can add the control to your layout.

IMPORTANT

To test the banner, during development, you can use the test Banner Id. Just remember to replace them with your IDs:

Android: ca-app-pub-3940256099942544/6300978111

Collapsible Banners (Licensed version only)

You can show a collapsible banner calling:

myAds.LoadAd(CollapsibleBannerMode.Top);

CollapsibleBannerMode can have the following values: None, Top, Bottom.

PROPERTIES

For each AdView if you want, you can set the following properties:

AdsId: To add the id of your ads.

AdSize: To choose the size of your banners.

GLOBAL PROPERTIES

AdsId: To add the id of your ads

UsePersonalizedAds: 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

UseRestrictedDataProcessing: For compliance with the CCPA

You can use Global Properties in this way:

DroidMTAdmob.Current.UsePersonalizedAds = false;

IMTAdmob Interstitials Documentation

This documentation provides an overview of how to use interstitial ads with the DroidMTAdmob.Current interface.

Loading an Interstitial Ad

To load an interstitial ad, use the LoadInterstitial method with the specified ad unit:

void LoadInterstitial(string adUnit);

Example:

DroidMTAdmob.Current.LoadInterstitial("your-ad-unit-id");

Checking if an Interstitial Ad is Loaded

To check if an interstitial ad is loaded, use the IsInterstitialLoaded method:

bool IsInterstitialLoaded();

Example:

bool isLoaded = DroidMTAdmob.Current.IsInterstitialLoaded();
if (isLoaded) {
    // Interstitial ad is loaded
}

Showing an Interstitial Ad

To show the loaded interstitial ad, use the ShowInterstitial method:

void ShowInterstitial();

Example:

if (DroidMTAdmob.Current.IsInterstitialLoaded()) {
    DroidMTAdmob.Current.ShowInterstitial();
}

Handling Interstitial Ad Events

The plugin provides several events to handle interstitial ad lifecycle events:

  • event EventHandler OnInterstitialLoaded: Raised when an interstitial ad is loaded.
  • event EventHandler<MTEventArgs> OnInterstitialFailedToLoad: Raised when an interstitial ad fails to load.
  • event EventHandler OnInterstitialOpened: Raised when an interstitial ad is opened.
  • event EventHandler OnInterstitialClosed: Raised when an interstitial ad is closed.
  • event EventHandler<MTEventArgs> OnInterstitialFailedToShow: Raised when an interstitial ad fails to show.
  • event EventHandler OnInterstitialImpression: Raised when an interstitial ad impression occurs.
  • event EventHandler OnInterstitialClicked: Raised when an interstitial ad is clicked.

Example:

DroidMTAdmob.Current.OnInterstitialLoaded += (sender, args) => {
    // Handle interstitial ad loaded
};

DroidMTAdmob.Current.OnInterstitialFailedToLoad += (sender, args) => {
    // Handle interstitial ad failed to load
};

DroidMTAdmob.Current.OnInterstitialOpened += (sender, args) => {
    // Handle interstitial ad opened
};

DroidMTAdmob.Current.OnInterstitialClosed += (sender, args) => {
    // Handle interstitial ad closed
};

DroidMTAdmob.Current.OnInterstitialFailedToShow += (sender, args) => {
    // Handle interstitial ad failed to show
};

DroidMTAdmob.Current.OnInterstitialImpression += (sender, args) => {
    // Handle interstitial ad impression
};

DroidMTAdmob.Current.OnInterstitialClicked += (sender, args) => {
    // Handle interstitial ad clicked
};

Getting the Number of Interstitials Loaded

To get the number of interstitials loaded, use the GetNumberOfInterstitialsLoaded method:

int GetNumberOfInterstitialsLoaded();

Example:

int numberOfInterstitials = DroidMTAdmob.Current.GetNumberOfInterstitialsLoaded();

Only the licensed version allows to load multiple interstitials and show them when needed.


Emptying the Interstitial Ads List

To empty the interstitial ads list, use the EmptyInterstitialAdsList method:

void EmptyInterstitialAdsList();

Example:

DroidMTAdmob.Current.EmptyInterstitialAdsList();

Use this method to clear the list of loaded interstitial ads. Normally, you don't need to use it as the library automatically removes loaded ads that are too old (1 hour) as they might be not valid anymore.

Rewarded Ads

This documentation provides an overview of how to use rewarded ads with the DroidMTAdmob.Current interface.

Loading a Rewarded Ad

To load a rewarded ad, use the LoadRewarded method with the specified ad unit:

void LoadRewarded(string adUnit);

Example:

DroidMTAdmob.Current.LoadRewarded("your-ad-unit-id");

Checking if a Rewarded Ad is Loaded

To check if a rewarded ad is loaded, use the IsRewardedLoaded method:

bool IsRewardedLoaded();

Example:

bool isLoaded = DroidMTAdmob.Current.IsRewardedLoaded();
if (isLoaded) {
    // Rewarded ad is loaded
}

Showing a Rewarded Ad

To show the loaded rewarded ad, use the ShowRewarded method:

void ShowRewarded();

Example:

if (DroidMTAdmob.Current.IsRewardedLoaded()) {
    DroidMTAdmob.Current.ShowRewarded();
}

Handling Rewarded Ad Events

The plugin provides several events to handle rewarded ad lifecycle events:

  • event EventHandler OnRewardedLoaded: Raised when a rewarded ad is loaded.
  • event EventHandler<MTEventArgs> OnRewardedFailedToLoad: Raised when a rewarded ad fails to load.
  • event EventHandler OnRewardedOpened: Raised when a rewarded ad is opened.
  • event EventHandler OnRewardedClosed: Raised when a rewarded ad is closed.
  • event EventHandler<MTEventArgs> OnRewardedFailedToShow: Raised when a rewarded ad fails to show.
  • event EventHandler OnRewardedImpression: Raised when a rewarded ad impression occurs.
  • event EventHandler OnRewardedClicked: Raised when a rewarded ad is clicked.
  • event EventHandler<RewardEventArgs> OnUserEarnedReward: Raised when the user earns a reward.

Example:

DroidMTAdmob.Current.OnRewardedLoaded += (sender, args) => {
    // Handle rewarded ad loaded
};

DroidMTAdmob.Current.OnRewardedFailedToLoad += (sender, args) => {
    // Handle rewarded ad failed to load
};

DroidMTAdmob.Current.OnRewardedOpened += (sender, args) => {
    // Handle rewarded ad opened
};

DroidMTAdmob.Current.OnRewardedClosed += (sender, args) => {
    // Handle rewarded ad closed
};

DroidMTAdmob.Current.OnRewardedFailedToShow += (sender, args) => {
    // Handle rewarded ad failed to show
};

DroidMTAdmob.Current.OnRewardedImpression += (sender, args) => {
    // Handle rewarded ad impression
};

DroidMTAdmob.Current.OnRewardedClicked += (sender, args) => {
    // Handle rewarded ad clicked
};

DroidMTAdmob.Current.OnUserEarnedReward += (sender, args) => {
    // Handle user earned reward
    var reward = args.Reward;
    // reward.Type and reward.Amount
};

Getting the Number of Rewarded Ads Loaded

To get the number of rewarded ads loaded, use the GetNumberOfRewardedLoaded method:

int GetNumberOfRewardedLoaded();

Example:

int numberOfRewarded = DroidMTAdmob.Current.GetNumberOfRewardedLoaded();

Only the licensed version allows to load multiple rewarded ads and show them when needed.


Emptying the Rewarded Ads List

To empty the rewarded ads list, use the EmptyRewardedAdsList method:

void EmptyRewardedAdsList();

Example:

DroidMTAdmob.Current.EmptyRewardedAdsList();

Use this method to clear the list of loaded rewarded ads. Normally you don't need to use it as the library automatically removes loaded ads that are too old (1 hour) as they might be not valid anymore.

Rewarded Interstitial Ads

This documentation provides an overview of how to use rewarded interstitial ads

Loading a Rewarded Interstitial Ad

To load a rewarded interstitial ad, use the LoadRewardedInterstitial method with the specified ad unit:

void LoadRewardedInterstitial(string adUnit);

Example:

DroidMTAdmob.Current.LoadRewardedInterstitial("your-ad-unit-id");

Checking if a Rewarded Interstitial Ad is Loaded

To check if a rewarded interstitial ad is loaded, use the IsRewardedInterstitialLoaded method:

bool IsRewardedInterstitialLoaded();

Example:

bool isLoaded = DroidMTAdmob.Current.IsRewardedInterstitialLoaded();
if (isLoaded) {
    // Rewarded interstitial ad is loaded
}

Showing a Rewarded Interstitial Ad

To show the loaded rewarded interstitial ad, use the ShowRewardedInterstitial method:

void ShowRewardedInterstitial();

Example:

if (DroidMTAdmob.Current.IsRewardedInterstitialLoaded()) {
    DroidMTAdmob.Current.ShowRewardedInterstitial();
}

Handling Rewarded Interstitial Ad Events

The plugin provides several events to handle rewarded interstitial ad lifecycle events:

  • event EventHandler OnRewardedInterstitialLoaded: Raised when a rewarded interstitial ad is loaded.
  • event EventHandler<MTEventArgs> OnRewardedInterstitialFailedToLoad: Raised when a rewarded interstitial ad fails to load.
  • event EventHandler OnRewardedInterstitialOpened: Raised when a rewarded interstitial ad is opened.
  • event EventHandler OnRewardedInterstitialClosed: Raised when a rewarded interstitial ad is closed.
  • event EventHandler<MTEventArgs> OnRewardedInterstitialFailedToShow: Raised when a rewarded interstitial ad fails to show.
  • event EventHandler OnRewardedInterstitialImpression: Raised when a rewarded interstitial ad impression occurs.
  • event EventHandler OnRewardedInterstitialClicked: Raised when a rewarded interstitial ad is clicked.
  • event EventHandler<RewardEventArgs> OnUserEarnedReward: Raised when the user earns a reward.

Example:

DroidMTAdmob.Current.OnRewardedInterstitialLoaded += (sender, args) => {
    // Handle rewarded interstitial ad loaded
};

DroidMTAdmob.Current.OnRewardedInterstitialFailedToLoad += (sender, args) => {
    // Handle rewarded interstitial ad failed to load
};

DroidMTAdmob.Current.OnRewardedInterstitialOpened += (sender, args) => {
    // Handle rewarded interstitial ad opened
};

DroidMTAdmob.Current.OnRewardedInterstitialClosed += (sender, args) => {
    // Handle rewarded interstitial ad closed
};

DroidMTAdmob.Current.OnRewardedInterstitialFailedToShow += (sender, args) => {
    // Handle rewarded interstitial ad failed to show
};

DroidMTAdmob.Current.OnRewardedInterstitialImpression += (sender, args) => {
    // Handle rewarded interstitial ad impression
};

DroidMTAdmob.Current.OnRewardedInterstitialClicked += (sender, args) => {
    // Handle rewarded interstitial ad clicked
};

DroidMTAdmob.Current.OnUserEarnedReward += (sender, args) => {
    // Handle user earned reward
    var reward = args.Reward;
    // reward.Type and reward.Amount
};

Getting the Number of Rewarded Interstitial Ads Loaded

To get the number of rewarded interstitial ads loaded, use the GetNumberOfRewardedInterstitialsLoaded method:

int GetNumberOfRewardedInterstitialsLoaded();

Example:

int numberOfRewardedInterstitials = DroidMTAdmob.Current.GetNumberOfRewardedInterstitialsLoaded();

Only the licensed version allows to load multiple rewarded interstitial ads and show them when needed.


Emptying the Rewarded Interstitial Ads List

To empty the rewarded interstitial ads list, use the EmptyRewardedInterstitialAdsList method:

void EmptyRewardedInterstitialAdsList();

Example:

DroidMTAdmob.Current.EmptyRewardedInterstitialAdsList();

Use this method to clear the list of loaded rewarded interstitial ads. Normally you don't need to use it as the library automatically removes loaded ads that are too old (1 hour) as they might be not valid anymore.

App Open Ads

App Open Ads are only available in the licensed version of the plugin.
To enable the App Open Ads in you apps, you can buy the license here.

The plugin provides functionality to load and display App Open ads in an Android and iOS application, while handling ad loading callbacks and error handling.

To initialize the Open Ads in your app, you need to set the corresponding variable enableOpenAds in

DroidMTAdmob.Current.Init(...)

In the same Init, you also need to pass your Open App Id in openAdsId.

To load and show your Open Ads when the app starts or goes into foreground, you need the following code:

Android

protected override void OnResume()
{
base.OnResume();
DroidMTAdmob.Current.OnResume();
}

Methods

None

Events

  • OnAppOpenAdLoaded: Event raised when an app open ad is loaded.
  • OnAppOpenOpened: Event raised when an app open ad is opened.
  • OnAppOpenClosed: Event raised when an app open ad is closed.
  • OnAppOpenFailedToLoad: Event raised when an app open ad fails to load.
  • OnAppOpenFailedToShow: Event raised when an app open ad fails to show.
  • OnAppOpenImpression: Event raised when an app open ad impression occurs.
  • OnAppOpenClicked: Event raised when an app open ad is clicked.

IMTAdmob Native Ads Documentation

This documentation provides an overview of how to use native ads with the DroidMTAdmob.Current interface.

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

  • XML
<Plugin.DroidMTAdmob.Controls.MTNativeAdView></Plugin.DroidMTAdmob.Controls.MTNativeAdView>
  • Code
MTNativeAdView ads = new MTNativeAdView();

Now you can add the control to your layout.

Using a custom layout

Instead of using the default native ad layout, you can use a custom layout. To do this, create a custom layout and load it using:

<Plugin.DroidMTAdmob.Controls.MTNativeAdView app:custom_layout="@layout/custom_nativeadview"/>

Loading a Native Ad

To load a native ad, use the LoadNativeAd method:

void LoadNativeAd();

Example:

DroidMTAdmob.Current.LoadNativeAd();

Loading Multiple Native Ads

To load up to 5 native ads (only on Android), use the LoadNativeAds method:

void LoadNativeAds(int count);

Example:

DroidMTAdmob.Current.LoadNativeAds(5);

Showing a Native Ad

To show a loaded native ad, use the ShowNativeAd method:

void ShowNativeAd();

Example:

myNativeAds.ShowNativeAd();

Handling Native Ad Events

The plugin provides several events to handle native ad lifecycle events:

  • event EventHandler OnNativeAdLoaded: Raised when a native ad is loaded.
  • event EventHandler OnNativeAdOpened: Raised when a native ad is opened.
  • event EventHandler OnNativeAdClosed: Raised when a native ad is closed.
  • event EventHandler<MTEventArgs> OnNativeAdFailedToLoad: Raised when a native ad fails to load.
  • event EventHandler<MTEventArgs> OnNativeAdFailedToShow: Raised when a native ad fails to show.
  • event EventHandler OnNativeAdImpression: Raised when a native ad impression occurs.
  • event EventHandler OnNativeAdClicked: Raised when a native ad is clicked.

Example:

DroidMTAdmob.Current.OnNativeAdLoaded += (sender, args) => {
    // Handle native ad loaded
};

DroidMTAdmob.Current.OnNativeAdOpened += (sender, args) => {
    // Handle native ad opened
};

DroidMTAdmob.Current.OnNativeAdClosed += (sender, args) => {
    // Handle native ad closed
};

DroidMTAdmob.Current.OnNativeAdFailedToLoad += (sender, args) => {
    // Handle native ad failed to load
};

DroidMTAdmob.Current.OnNativeAdFailedToShow += (sender, args) => {
    // Handle native ad failed to show
};

DroidMTAdmob.Current.OnNativeAdImpression += (sender, args) => {
    // Handle native ad impression
};

DroidMTAdmob.Current.OnNativeAdClicked += (sender, args) => {
    // Handle native ad clicked
};

Consent and Ump

Under the Google EU User Consent Policy, you must make certain disclosures to your users in the European Economic Area (EEA) along with the UK and obtain their consent to use cookies or other local storage, where legally required, and to use personal data (such as AdID) to serve ads. The licensed version of the plugin allows you to automatically ask consent to your users that need to provide it (EEA & UK).


To enable this feature and automatically request the consent on your apps, you can buy the license here.

Requesting User Consent

The consent is requested automatically when you init the plugin. If you prefer, you can avoid to show the consent at startup (set the corresponding parameter in the Init method) and show it at a later time.

To request user consent, use the InitialiseAndShowConsentForm method:

void InitialiseAndShowConsentForm();

Example:

DroidMTAdmob.Current.InitialiseAndShowConsentForm();

Checking User Consent Status

To check the current user consent status, use the GetConsentStatus method:

ConsentStatus GetConsentStatus();

Example:

ConsentStatus status = DroidMTAdmob.Current.GetConsentStatus();
if (status == ConsentStatus.Obtained) {
    // User has granted consent
} else {
    // User has not granted consent
}

Handling Consent Events

The plugin provides several events to handle user consent lifecycle events:

  • event EventHandler OnConsentFormLoaded: Raised when the consent form is loaded.
  • event EventHandler<MTEventArgs> OnConsentFormLoadFailed: Raised when the consent form fails to load.
  • event EventHandler OnConsentFormOpened: Raised when the consent form is opened.
  • event EventHandler OnConsentFormClosed: Raised when the consent form is closed.
  • event EventHandler<MTEventArgs> OnConsentFormError: Raised when there is an error with the consent form.

Example:

DroidMTAdmob.Current.OnConsentFormLoaded += (sender, args) => {
    // Handle consent form loaded
};

DroidMTAdmob.Current.OnConsentFormLoadFailed += (sender, args) => {
    // Handle consent form load failed
};

DroidMTAdmob.Current.OnConsentFormOpened += (sender, args) => {
    // Handle consent form opened
};

DroidMTAdmob.Current.OnConsentFormClosed += (sender, args) => {
    // Handle consent form closed
};

DroidMTAdmob.Current.OnConsentFormError += (sender, args) => {
    // Handle consent form error
};

Known issues and fix