Integration guide, Android

Show AdMob ads in your html2app app

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.

Start the steps

Requires the html2app Developer plan ($19 a month). iOS builds are not supported yet.

01 Before you start

Three things you need

A Developer plan

The Google Mobile Ads plugin is part of the Developer plan: $19 a month, or $16 a month billed $192 yearly.

An AdMob account

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.

An Android build

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

Enable the plugin and enter your App ID

Do this once per project in the html2app dashboard. The plugin settings sit in an accordion that starts closed.

Your checklist

0 of 7 done

Progress is saved in this browser only.

  1. Open the plugins page of your project

    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.

  2. Click “+ Add New Plugin”

    The dashed “+ Add New Plugin” box opens the list of available plugins.

    The dashed Add New Plugin box on the plugins page
    The Add New Plugin button.
  3. Choose “Google Mobile Ads” and click Add

    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 Add New Plugin dialog with the Google Mobile Ads row highlighted
    The Add New Plugin dialog. The Google Mobile Ads row is the one to add.
  4. Open the plugin accordion

    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.

  5. Enter the Android App ID

    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.

    The Google Mobile Ads plugin card with the accordion open. The App ID (Android) field is on the left and App ID (iOS) on the right.
    The plugin card, accordion open. App ID (Android) is the left field.
  6. Build the Android app

    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

Pick one of four ways to load 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.

terminal
npm install @yandeu/js-bridge@0.0.4
ads.js
import { Ads } from '@yandeu/js-bridge/lib/plugins/ads.js'

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

Set the ad unit IDs once, then show each format

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.

Demo game

Level 1 Coins 0

Simulated preview

Tap the phone

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.

    1. setAdUnitId()
    2. show()
    3. dispose()
    banner.js
    // 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()

    05 Generate your code

    A complete ads module for your install method

    Choose the install method and the ad unit IDs. The code updates as you change them. Copy it into your project.

    Ad unit IDs

    The Android App ID is not part of this code. Set it in the dashboard, as described in step 5.

    ads.js

    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.

    Or give this to your AI assistant

    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

    Test with Google’s demo IDs, then switch to yours

    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.

    1. Build the Android app with the test IDs. Install it on a phone or an emulator.
    2. Check each format. The banner appears, an interstitial opens and closes, and a rewarded ad grants the reward after it closes.
    3. In AdMob, add the Android app and create one ad unit each for banner, interstitial and rewarded. Copy their IDs.
    4. Replace the three test IDs with your own, then build again. Google asks you to replace demo IDs before you publish.

    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

    When something does not work

    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

    The Ads object

    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

    Common questions

    Do I need the Developer plan?

    Yes. The Google Mobile Ads plugin is part of the html2app Developer plan, $19 a month.

    Where does the Android App ID go?

    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.

    Which install method should I use?

    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.

    Do ads work in iOS builds?

    No. iOS builds are not supported yet.

    What happens when I open the page in a desktop browser?

    Nothing breaks. Outside the html2app app, the Ads calls return false or do nothing. Test ads on a device or an emulator.

    Where can I set the banner position?

    The JS API has no position option. Check where the banner appears in a test build.

    How do I give this guide to my AI assistant?

    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.