Installation
- Bundle
- CDN
How it works
The Despia runtime registers the WebView with the Google Mobile Ads SDK at app startup. On Android it callsMobileAds.registerWebView(webView), and on iOS it calls MobileAds.shared.register(webView). Once registered, any AdSense, GPT, or IMA tag that loads inside the WebView can communicate with the SDK and pass app-level signals (device ID, audience data) into the ad request, improving CPMs and fill rates.
There is no JavaScript activation call. The bridge is always on inside the Despia runtime.
AdMob and Despia setup
Configure AdMob and your ad inventory source, then connect everything to Despia. The steps go in order, each one feeds the next.Create a Google AdMob account
Add your iOS app to AdMob
ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY.Add your Android app to AdMob
Set up your ad inventory source
- AdSense (most common): sign up at adsense.google.com, get your publisher ID
ca-pub-XXXXXXXXXXXXXXXX, then in AdMob go to Apps > [your app] > App settings > Linked accounts and link the AdSense account so payments share a single profile. - Google Ad Manager (GPT): configure inventory at admanager.google.com, note your network code, then create ad units to reference in your tags.
- IMA video ads: prepare your VAST or VMAP ad tag URL from your video ad provider.
Configure GDPR and CCPA consent
Enable AdMob in the Despia Editor
- iOS App ID (with
~) - Android App ID (with
~)
Rebuild your app
What Despia configures automatically
When you rebuild with Inline Ads enabled, Despia adds the manifest entries, plist keys, and WebView initialization code on both platforms. You do not write any of this yourself, but it is shown here for transparency.- Android
- iOS
AndroidManifest.xml:onCreate():Ad tag options
The bridge works with three Google ad systems. Pick the one that matches your monetization stack.AdSense
The simplest option. Add the loader script once in<head> and place <ins> units anywhere in the body.
onMounted), Svelte (onMount), Angular (ngAfterViewInit), and any other framework. The rule is to push to window.adsbygoogle after the container is in the DOM.
See the AdSense setup guide for full configuration.
Google Publisher Tag
Use GPT for Ad Manager reservation and auction inventory. The bridge activates as soon as the WebView is registered.IMA for HTML5
Use IMA with Video.js for pre-roll, mid-roll, and post-roll video ads. Load dependencies in this exact order:playsinline attribute is required for iOS, and Despia configures the WebView so autoplay works without a user gesture on both platforms.
Safe area handling
Any banner positioned at the top or bottom of the viewport must account for the status bar, notch, and home indicator on modern phones. Despia injects--safe-area-top and --safe-area-bottom into every WebView, and the canonical pattern pairs the runtime variable with the native env() value as a fallback, then combines both with your base padding inside calc().
var() half is the source of truth inside the Despia runtime. The env() half is the native WebKit value used during web preview or before the runtime injects its variables. The 0px fallback inside env() keeps the calc() valid when neither lookup resolves. Apply the inset to the wrapping container, never to the <ins> element directly.
Sticky banner under the navigation bar
In a typical WebView app, the native chrome sits outside the WebView, so placing an ad between your nav bar and your content normally requires a native overlay. With Inline Ads the banner is just a flex child rendered as a DOM element directly beneath your web nav bar.- React
- HTML
data-full-width-responsive="true" so the banner fills the device width like a native banner unit.
Sticky banner pinned to the bottom
The classic mobile placement, a persistent leaderboard anchored to the bottom of the viewport. In a pure WebView app this normally requires a native view rendered outside the WebView. Here it is justposition: sticky plus the safe area inset.
- React
- HTML
In-feed banner between content cards
Ads interspersed between list items, the pattern used by Instagram, Twitter, and most news apps. Replace every nth card with a fluid in-article unit so the ad sizes itself to match surrounding content.- React
- HTML
data-ad-format="fluid" with data-ad-layout="in-article" produces a unit that auto-sizes to blend between content items.
Interstitial-style overlay
A full-screen ad rendered as a fixed-position overlay inside the WebView, triggered by JavaScript at a natural break point. A countdown runs before the close button appears.- React
- HTML
In-article banner
A unit that sits naturally between paragraphs of long-form content, the format used by major publishers. It scrolls with the article body.- React
- HTML
Pre-roll video ad
A video ad that plays before your main content video, the YouTube model. Video.js handles the player and the IMA plugin handles the ad request. The user can skip after 5 seconds (if your tag allows it) and the content video starts automatically.- React
- HTML
mediaPlaybackRequiresUserGesture = false on Android and mediaTypesRequiringUserActionForPlayback = [] on iOS, so video ads autoplay without requiring a tap.Rewarded “unlock content” ad
Show an ad in exchange for unlocking gated content (a premium article, extra lives, a download). The user opts in, watches the ad, and your UI programmatically reveals the locked content.- React
- HTML
Sidebar rail ad
On tablet-sized screens or landscape layouts, render a persistent unit in a side rail next to your content, the format common on desktop web but rare in mobile apps. With Inline Ads it is just a flex column.- React
- HTML
@media (max-width: 599px) { .sidebar-ad { display: none; } } so the rail only appears on tablets and landscape phones, with a banner ad as the portrait fallback.
Testing your integration
The Google WebView Ads test page verifies that your WebView is correctly registered with the Mobile Ads SDK. The test must run inside your app’s WebView context, so opening the URL in a desktop browser will always show a failed connection. The recommended approach is to drop a hidden link onto an existing page (profile, settings, debug menu) and tap it from your built app. Despia allows the Google test URL to load inside the WebView specifically for this purpose.- React
- HTML
Privacy and consent
Inline Ads does not automatically propagate consent signals collected in the native app context (IAB TCF v2.0 or IAB CCPA) to the tags running inside the WebView. If you need a unified consent flow, work with your Consent Management Platform to gather consent directly in the WebView, or implement a JavaScript bridge that passes the TCF or CCPA strings from your native app into the WebView before ads load.Frequently asked questions
Do I need a separate AdMob App ID for iOS and Android?
Do I need a separate AdMob App ID for iOS and Android?
Can I use Ad Manager (GAM) instead of AdSense?
Can I use Ad Manager (GAM) instead of AdSense?
Will ads slow down my WebView?
Will ads slow down my WebView?
Can I show rewarded or interstitial AdMob ads from inside the WebView?
Can I show rewarded or interstitial AdMob ads from inside the WebView?
Why do I need to rebuild after toggling the setting?
Why do I need to rebuild after toggling the setting?