# AdMob

This article explains how to display ads in your app using AdMob in Monaca. AdMob is a Google advertising service that can be easily integrated with a Google account. By reading this article, you will be able to integrate AdMob and display ads in your app.

The sample code for explanation is available at the following URL:&#x20;

<https://github.com/monaca-samples/admob-plus>

## Applying for AdMob&#x20;

First, access [the AdMob website](https://admob.google.com/home/) and apply for advertising.&#x20;

During this application process, an app ID will be issued, so be sure to copy it. (Example ID: ca-app-pub-3089782807744052\~xxxxxxxx)&#x20;

Once the application is approved, an ad ID will be issued, which will be used when displaying the ads, so make sure to also keep it on record.&#x20;

Note that approval is required before ads can be displayed, so during development, it is recommended to use the test ads provided by Google.

## Installing the Plugin&#x20;

Please install the following plugin:

admob-plus-cordova (URL: <https://github.com/admob-plus/admob-plus>)&#x20;

After installing the plugin, set "APP\_ID\_ANDROID" in the plugin's configuration screen. This value should specify the App ID obtained from AdMob. This is for Android settings. Additionally, for iOS settings, you need to set the value of "APP\_ID\_IOS".

## Displaying Ads on App Launch&#x20;

The following code executes an ad that is displayed when the app is launched.&#x20;

The ad is displayed when show() is executed.

```javascript
// Display ad shown on app launch
const ad = new admob.AppOpenAd({
  adUnitId: 'ca-app-pub-3940256099942544/5575463023',
})
await ad.load()
await ad.show()
```

![](/files/6JakdsFMAjrBWFmzKkgI)

## Displaying Banner Ads

To display a banner ad at the bottom of the app, create an object of "admob.BannerAd" as shown in the following code. The ad is displayed using show().

```javascript
// Display banner ad
const banner = new admob.BannerAd({
　　adUnitId: 'ca-app-pub-3940256099942544/6300978111',
　　position: 'bottom',
})
await banner.show()
```

![](/files/w8FXqCGj6vwZEHzlIIDb)

## Test Ads for Development

After applying to AdMob or during development, banners may not be displayed. In such cases, you can use the test ad ID provided by AdMob.

* [Demo ad unit ID (iOS)](https://developers.google.com/admob/ios/test-ads#demo_ad_units)
* [Demo ad unit ID (Android)](https://developers.google.com/admob/android/test-ads#demo_ad_units)

<table><thead><tr><th width="274">Ad format</th><th>Demo ad unit ID (iOS)</th><th>Demo ad unit ID (Android)</th></tr></thead><tbody><tr><td>App Open</td><td>ca-app-pub-3940256099942544/5575463023</td><td>ca-app-pub-3940256099942544/9257395921</td></tr><tr><td>Adaptive Banner</td><td>ca-app-pub-3940256099942544/2435281174</td><td>ca-app-pub-3940256099942544/9214589741</td></tr><tr><td>Fixed Size Banner</td><td>ca-app-pub-3940256099942544/2934735716</td><td>ca-app-pub-3940256099942544/6300978111</td></tr><tr><td>Interstitial</td><td>ca-app-pub-3940256099942544/4411468910</td><td>ca-app-pub-3940256099942544/1033173712</td></tr><tr><td>Rewarded Ads</td><td>ca-app-pub-3940256099942544/1712485313</td><td>ca-app-pub-3940256099942544/5224354917</td></tr><tr><td>Rewarded Interstitial</td><td>ca-app-pub-3940256099942544/6978759866</td><td>ca-app-pub-3940256099942544/5354046379</td></tr><tr><td>Native</td><td>ca-app-pub-3940256099942544/3986624511</td><td>ca-app-pub-3940256099942544/2247696110</td></tr><tr><td>Native Video</td><td>ca-app-pub-3940256099942544/2521693316</td><td>ca-app-pub-3940256099942544/1044960115</td></tr></tbody></table>

{% hint style="info" %}
As of December 15, 2023, we have confirmed that the following error occurs on Android devices when using the test ID and the banner is not displayed.
{% endhint %}

```javascript
Uncaught (in promise) {
  "Code": 3,
  "Message": "No fill.",
  "Domain": "com.google.android.gms.ads",
  "Cause": "null",
  "Response Info": {
    "Response ID": "null",
    "Mediation Adapter Class Name": "",
    "Adapter Responses": []
  }
}
```

## Conclusion:

You have now successfully integrated AdMob into your mobile application using Monaca. This will enable you to monetize your app with targeted ads from the AdMob platform. With Monaca's powerful tools and the AdMob service, you can create a profitable mobile application that provides value to both users and advertisers.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://en.docs.monaca.io/sampleapp/samples/admob.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
