A Developer plan
The Google Mobile Ads plugin is part of the Developer plan: $19 a month, or $16 a month billed $192 yearly.
Integration guide, Android
Banner, interstitial and rewarded ads, called from your web code through the JS Bridge. This guide is written for people and for AI coding assistants. Give its URL to your assistant, and it has the setup steps, the API and the install options.
Requires the html2app Developer plan ($19 a month). iOS builds are not supported yet.
01 Before you start
The Google Mobile Ads plugin is part of the Developer plan: $19 a month, or $16 a month billed $192 yearly.
Free to create. You need it for your Android App ID and your own ad unit IDs. Google’s test IDs work without an account.
Ads run only inside the app that html2app builds. A desktop browser shows the page, but the ad calls do nothing there.
02 Dashboard setup
Do this once per project in the html2app dashboard. The plugin settings sit in an accordion that starts closed.
Progress is saved in this browser only.
Go to your dashboard at app.html2app.dev, select the project you want to add the AdMob plugin to, then click Plugins in the side menu.
The dashed “+ Add New Plugin” box opens the list of available plugins.
The list shows each plugin with a short description. Find the row “Google Mobile Ads, Monetize with Google AdMob ads.” and click its Add button.
The new plugin card starts closed. Open its accordion to show the Configuration fields. Keep the switch in the card header turned on. A switched-off plugin does not run.
In App ID (Android), enter your AdMob app ID. It starts with ca-app-pub-, then 16 digits,
a tilde ~ and 10 digits. For a first test, use Google’s sample app ID
ca-app-pub-3940256099942544~3347511713.
Leave App ID (iOS) empty. iOS builds are not supported yet.
Start an Android build in html2app. Build again after you change the App ID, because the App ID is part of the built app.
03 Install the JS Bridge
Ads
The Ads object comes from the @yandeu/js-bridge package. Use version 0.0.4,
or a later version if one is already on npm. Use the same version in every import.
Use npm when your project has a bundler, such as Vite, esbuild or webpack. The package ships its own type definitions.
npm install @yandeu/js-bridge@0.0.4
import { Ads } from '@yandeu/js-bridge/lib/plugins/ads.js'
Use ESM via esm.sh when the project has no build step. The browser loads the module from esm.sh, so nothing needs to be installed.
<script type="module">
import { Ads } from 'https://esm.sh/@yandeu/js-bridge@0.0.4/lib/plugins/ads.js'
Ads.banner.setAdUnitId('ca-app-pub-3940256099942544/6300978111')
Ads.banner.show()
</script>
Use the UMD bundle for a plain script tag. It sets a global named JsBridge, which holds Ads. unpkg and jsDelivr serve the same file, so use either one.
<script src="https://unpkg.com/@yandeu/js-bridge@0.0.4/bundles/umd/js-bridge.umd.min.js"></script>
<script>
const { Ads } = JsBridge
Ads.banner.setAdUnitId('ca-app-pub-3940256099942544/6300978111')
Ads.banner.show()
</script>
<script src="https://cdn.jsdelivr.net/npm/@yandeu/js-bridge@0.0.4/bundles/umd/js-bridge.umd.min.js"></script>
Use the ESM bundle when you want an ES module without npm. The bundle exports Ads and WebView. Each CDN has its own module endpoint: jsDelivr uses /+esm at the end of the URL, and unpkg uses ?module.
<script type="module">
import { Ads } from 'https://cdn.jsdelivr.net/npm/@yandeu/js-bridge@0.0.4/bundles/esm/js-bridge.esm.min.js/+esm'
Ads.banner.setAdUnitId('ca-app-pub-3940256099942544/6300978111')
Ads.banner.show()
</script>
<script type="module">
import { Ads } from 'https://unpkg.com/@yandeu/js-bridge@0.0.4/bundles/esm/js-bridge.esm.min.js?module'
Ads.banner.setAdUnitId('ca-app-pub-3940256099942544/6300978111')
Ads.banner.show()
</script>
Module scripts need http or https. Opening the HTML file from disk does not load ES modules. The built html2app app serves your files over local http, so they load there.
TypeScript types. The UMD bundle has no type file. Use the types from bundles/esm/js-bridge.esm.min.d.ts for both bundles.
Offline use. A script loaded from a CDN needs a connection when the page loads. Offline, the script does not load and the ads code does not run. Save the files and load them from your project instead.
npm: the bundler puts the code into your app, so it works offline. No extra step.
ESM bundle: save bundles/esm/js-bridge.esm.min.js from the package next to your JavaScript, then import { Ads } from './js-bridge.esm.min.js'. Serve the page over http or https, as the built app does.
UMD bundle: open https://unpkg.com/@yandeu/js-bridge@0.0.4/bundles/umd/js-bridge.umd.min.js in a browser, right-click the page, and save it as js-bridge.umd.min.js next to your HTML. Load it with <script src="js-bridge.umd.min.js"></script>.
esm.sh: needs a connection, because esm.sh serves the module from its own URL. For offline builds, use npm, the ESM bundle or the UMD bundle.
04 Show ads
Each format follows the same order: set the ad unit ID, load the ad, then show it. The examples use Google’s test
IDs and assume Ads is loaded as described in the install step.
Simulated preview
Each button runs the same calls as the code below. The log lists each call and its result. The preview shows how the formats behave, but it does not load real ads. Real ads appear only in the built Android app.
The interstitial close button appears after a short countdown. In the rewarded video, close it before the end and no reward is granted.
A banner stays in the app until you remove it with dispose(). The JS API has no option for the banner position, so check where it appears on a device.
// Call once at app start
Ads.banner.setAdUnitId('ca-app-pub-3940256099942544/6300978111') // Google test banner
// Show the banner
Ads.banner.show()
// Remove it when the screen no longer needs it
Ads.banner.dispose()
A full-screen ad for a natural break, such as the end of a level. show() resolves after the user closes the ad, and it resolves to true only when the ad was shown and dismissed.
// Call once at app start
Ads.interstitial.setAdUnitId('ca-app-pub-3940256099942544/1033173712') // Google test interstitial
async function showInterstitial() {
const loaded = await Ads.interstitial.load()
if (!loaded) return false // no ad ready, skip this break
return Ads.interstitial.show() // resolves after the ad is dismissed
}
An ad the user chooses to watch for a reward. Grant the reward only when ok is true.
// Call once at app start
Ads.rewarded.setAdUnitId('ca-app-pub-3940256099942544/5224354917') // Google test rewarded
// Returns the reward amount, or 0 when the user did not earn it
async function showRewardedAd() {
const loaded = await Ads.rewarded.load()
if (!loaded) return 0
const result = await Ads.rewarded.show() // resolves when the ad is closed
return result.ok ? result.amount : 0
}
05 Generate your code
Choose the install method and the ad unit IDs. The code updates as you change them. Copy it into your project.
The Android App ID is not part of this code. Set it in the dashboard, as described in step 5.
Module methods (npm, esm.sh): save as ads.js. With npm, import it from your app code. With esm.sh, load
it with <script type="module" src="ads.js">. UMD methods: paste the whole block into
index.html.
The prompt below links to this guide and asks the assistant to choose the install method that fits your project. Paste it into your coding assistant.
06 Test and publish
| Format | Google test ID (Android) |
|---|---|
| Banner (fixed size) | ca-app-pub-3940256099942544/6300978111 |
| Interstitial | ca-app-pub-3940256099942544/1033173712 |
| Rewarded | ca-app-pub-3940256099942544/5224354917 |
| Sample App ID (Android) | ca-app-pub-3940256099942544~3347511713 |
These are Google’s demo IDs from the Google Mobile Ads test ads guide. They show test creatives and do not count as your traffic.
Do not click your own live ads. Google warns that clicks on real ads outside test mode can get an AdMob account flagged for invalid activity. Test with the demo IDs or with test devices.
07 Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The app crashes with “Missing application ID” | The Android App ID is empty or missing from the plugin card. | Open the plugin card, enter the App ID (Android) in the format ca-app-pub-…~…, then build again. |
| No ad appears | The ad unit ID was not set before load or show. | Call the setAdUnitId() function first. |
load() returns false |
No ad was ready, or the request failed. | Try again later. Check that the ad unit ID is correct and that the test or live ID matches your setup. |
| Nothing happens in a desktop browser | Expected. Ads run only inside the built app. | Test on a device or an emulator. |
| Ads do not appear on iOS | iOS builds are not supported yet. | Build for Android. |
| The plugin does nothing | The switch in the plugin card header is off. | Turn the switch on, then build again. |
08 API reference
This list covers the members used in this guide. The full type reference is in the Ads API docs, and the bridge overview is in the JS Bridge docs.
| Member | Returns | Notes |
|---|---|---|
Ads.banner.setAdUnitId(adUnitId) |
void | Stores the banner ad unit ID. Call it before show(). |
Ads.banner.show() |
void | Shows the banner. |
Ads.banner.dispose() |
void | Removes the banner. |
Ads.interstitial.setAdUnitId(adUnitId) |
void | Stores the interstitial ad unit ID. Call it before load(). |
Ads.interstitial.load() |
Promise<boolean> | true when the ad is ready. |
Ads.interstitial.show() |
Promise<boolean> | Resolves when the ad is dismissed. true only if it was shown and dismissed. |
Ads.rewarded.setAdUnitId(adUnitId) |
void | Stores the rewarded ad unit ID. Call it before load(). |
Ads.rewarded.load() |
Promise<boolean> | true when the ad is ready. |
Ads.rewarded.show() |
Promise<{ ok, amount }> | Resolves when the ad is closed. ok is true and amount is the reward when the user earned it. |
Ads.isPrivacyOptionsRequired() |
Promise<boolean> | Use it to decide whether to show a “Privacy settings” button. |
Ads.presentPrivacyOptionsForm() |
void | Opens the privacy options form. Call it from the settings button. |
Ads.resetConsent() |
void | Resets the stored consent. Useful when you test the consent flow. |
09 FAQ
Yes. The Google Mobile Ads plugin is part of the html2app Developer plan, $19 a month.
In the Google Mobile Ads plugin card in the html2app dashboard, in the App ID (Android) field. Do not put it in the web code.
Use npm if your project has a build step. Use ESM from esm.sh or the ESM bundle on jsDelivr or unpkg for a module without a build step. Use the UMD bundle from unpkg or jsDelivr for a plain script tag.
No. iOS builds are not supported yet.
Nothing breaks. Outside the html2app app, the Ads calls return false or do nothing. Test ads on a device or an emulator.
The JS API has no position option. Check where the banner appears in a test build.
Copy the prompt in the generator section, paste it into your assistant, and include the guide URL. The assistant needs your ad unit IDs, or it uses Google’s test IDs.