Integrate the WebView API for Ads
Stay organized with collections
Save and categorize content based on your preferences.
The web view APIs for ads makes app signals available to the tags in your
WebView
, helping to improve monetization for the
publishers that provided the content and protect advertisers from spam.
These app signals, such as app ID and app version, help activate Reporting
and Target in-app browser inventory
use cases that are otherwise only available on app traffic.

How it works
Communication with the Next Gen Mobile Ads SDK only happens in response to ad
events triggered by any of the following:
The SDK adds message handlers to the registered WebView
to listen for
these ad events. For a better sense of how this works, view the
source code of the
test page.
Prerequisites
Pass the application ID to the SDK
If you already have an Ad Manager application ID,
initialize the Next Gen Mobile Ads SDK with
your existing application ID.
If you don't have an Ad Manager application ID, pass in
InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID
as the application ID
when you initialize the Next Gen Mobile Ads SDK.
Kotlin
MobileAds.initialize(
this@MainActivity,
// Use this application ID to initialize the Next Gen Mobile Ads SDK if
// you don't have an Ad Manager application ID.
InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)
.build(),
) {
// Adapter initialization complete.
}
Java
MobileAds.initialize(
this,
// Use this application ID to initialize the Next Gen Mobile Ads SDK if
// you don't have an Ad Manager application ID.
new InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)
.build(),
initializationStatus -> {
// Adapter initialization is complete.
});
Register the web view
Call
registerWebView()
on the main thread to establish a connection with the JavaScript handlers in the
AdSense code or Google Publisher Tag within each WebView
instance. This
should be done as early as possible, such as in the
onCreate()
method of your MainActivity
.
Kotlin
import android.webkit.CookieManager
import android.webkit.WebView
import com.google.android.libraries.ads.mobile.sdk.MobileAds
class MainActivity : AppCompatActivity() {
lateinit var webView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
webView = findViewById(R.id.webview)
// Let the web view accept third-party cookies.
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
// Let the web view use JavaScript.
webView.settings.javaScriptEnabled = true
// Let the web view access local storage.
webView.settings.domStorageEnabled = true
// Let HTML videos play automatically.
webView.settings.mediaPlaybackRequiresUserGesture = false
// Register the web view.
MobileAds.registerWebView(webView)
}
}
Java
import android.webkit.CookieManager;
import android.webkit.WebView;
import com.google.android.libraries.ads.mobile.sdk.MobileAds;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webview);
// Let the web view accept third-party cookies.
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
// Let the web view use JavaScript.
webView.getSettings().setJavaScriptEnabled(true);
// Let the web view access local storage.
webView.getSettings().setDomStorageEnabled(true);
// Let HTML videos play automatically.
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
// Register the web view.
MobileAds.registerWebView(webView);
}
}
Test your integration
Before using your own URL, we recommend that you load the following URL to test
the integration:
https://google.github.io/webview-ads/test/#api-for-ads-tests
The test URL shows green status bars for a successful integration if the
following conditions apply:
WebView
connected to the Next Gen Mobile Ads SDK
Next steps
- Gather consent in
WebView
. The Web view APIs for Ads doesn't
propagate consent collected in the mobile app context using IAB TCF v2.0 or IAB CCPA
compliance frameworks to the tags in your web views. If you're interested in
implementing a single consent flow as the owner of both the WebView
and its corresponding web content being monetized, work with your consent
management platform to gather consent in the WebView
context.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-09 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[[["\u003cp\u003eWeb view APIs for ads enable app signals to be shared with tags in your \u003ccode\u003eWebView\u003c/code\u003e, enhancing monetization for publishers and protecting advertisers from spam.\u003c/p\u003e\n"],["\u003cp\u003eApp signals, including app ID and version, allow for reporting and targeting within in-app browser inventory, similar to regular app traffic.\u003c/p\u003e\n"],["\u003cp\u003eCommunication with the Google Mobile Ads SDK occurs through ad events triggered by AdSense code, Google Publisher Tag, or IMA for HTML5.\u003c/p\u003e\n"],["\u003cp\u003eTo use this functionality, the Google Mobile Ads SDK must be initialized with either an existing Ad Manager application ID or \u003ccode\u003eInitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID\u003c/code\u003e if you don't have an Ad Manager application ID.\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eWebView\u003c/code\u003e instance needs to be registered by calling \u003ccode\u003eregisterWebView()\u003c/code\u003e on the main thread, preferably during the \u003ccode\u003eonCreate()\u003c/code\u003e method of your \u003ccode\u003eMainActivity\u003c/code\u003e, to connect with the JavaScript handlers.\u003c/p\u003e\n"]]],["The Web View APIs for ads share app signals like app ID and version with tags in `WebView`, enhancing publisher monetization and advertiser protection. This is triggered by ad events from AdSense, Google Publisher Tag, or IMA for HTML5. Developers must initialize the Google Mobile Ads SDK with an application ID, or `InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID`, and then call `registerWebView()` on the main thread to connect to JavaScript handlers. Using the test URL is recommended to verify proper integration.\n"],null,["The web view APIs for ads makes app signals available to the tags in your\n\n[`WebView`](//developer.android.com/reference/android/webkit/WebView), helping to improve monetization for the\npublishers that provided the content and protect advertisers from spam.\n\nThese app signals, such as app ID and app version, help activate [Reporting](//support.google.com/admanager/answer/14137220#report-on-in-app-webview-traffic)\nand [Target in-app browser inventory](//support.google.com/admanager/answer/14137220#target-in-app-webview-inventory)\nuse cases that are otherwise only available on app traffic.\n\n\nHow it works\n\nCommunication with the Next Gen Mobile Ads SDK only happens in response to ad\nevents triggered by any of the following:\n\n- [AdSense code](//support.google.com/adsense/answer/9274634)\n- [Google Publisher Tag](//support.google.com/admanager/answer/181073)\n- [IMA for HTML5](//support.google.com/adsense/answer/6391192)\n\nThe SDK adds message handlers to the registered `WebView` to listen for\nthese ad events. For a better sense of how this works, view the\n[source code](//github.com/google/webview-ads/blob/main/test/index.html) of the\ntest page.\n\nPrerequisites\n\n- [Next Gen Mobile Ads SDK](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/quick-start#import_the_mobile_ads_sdk) version 0.6.0-alpha01 or higher.\n\nPass the application ID to the SDK\n\nIf you already have an Ad Manager application ID,\n[initialize the Next Gen Mobile Ads SDK](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/quick-start#initialize_the_mobile_ads_sdk) with\nyour existing application ID.\n\nIf you don't have an Ad Manager application ID, pass in\n`InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID` as the application ID\nwhen you [initialize the Next Gen Mobile Ads SDK](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/quick-start#initialize_the_mobile_ads_sdk). \n\nKotlin \n\n MobileAds.initialize(\n this@MainActivity,\n // Use this application ID to initialize the Next Gen Mobile Ads SDK if\n // you don't have an Ad Manager application ID.\n InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)\n .build(),\n ) {\n // Adapter initialization complete.\n }\n\nJava \n\n MobileAds.initialize(\n this,\n // Use this application ID to initialize the Next Gen Mobile Ads SDK if\n // you don't have an Ad Manager application ID.\n new InitializationConfig.Builder(InitializationConfig.WEBVIEW_APIS_FOR_ADS_APPLICATION_ID)\n .build(),\n initializationStatus -\u003e {\n // Adapter initialization is complete.\n });\n\nRegister the web view\n\nCall\n\n[`registerWebView()`](/ad-manager/mobile-ads-sdk/android/early-access/nextgen/reference/com/google/android/libraries/ads/mobile/sdk/MobileAds#registerWebView(android.webkit.WebView))\n\non the main thread to establish a connection with the JavaScript handlers in the\nAdSense code or Google Publisher Tag within each `WebView` instance. This\nshould be done as early as possible, such as in the\n\n`onCreate()` method of your `MainActivity`.\n\n\nKotlin \n\n import android.webkit.CookieManager\n import android.webkit.WebView\n import com.google.android.libraries.ads.mobile.sdk.MobileAds\n\n class MainActivity : AppCompatActivity() {\n lateinit var webView: WebView\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_main)\n webView = findViewById(R.id.webview)\n\n // Let the web view accept third-party cookies.\n CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)\n // Let the web view use JavaScript.\n webView.settings.javaScriptEnabled = true\n // Let the web view access local storage.\n webView.settings.domStorageEnabled = true\n // Let HTML videos play automatically.\n webView.settings.mediaPlaybackRequiresUserGesture = false\n\n // Register the web view.\n MobileAds.registerWebView(webView)\n }\n }\n\nJava \n\n import android.webkit.CookieManager;\n import android.webkit.WebView;\n import com.google.android.libraries.ads.mobile.sdk.MobileAds;\n\n public class MainActivity extends AppCompatActivity {\n private WebView webView;\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n webView = findViewById(R.id.webview);\n\n // Let the web view accept third-party cookies.\n CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);\n // Let the web view use JavaScript.\n webView.getSettings().setJavaScriptEnabled(true);\n // Let the web view access local storage.\n webView.getSettings().setDomStorageEnabled(true);\n // Let HTML videos play automatically.\n webView.getSettings().setMediaPlaybackRequiresUserGesture(false);\n\n // Register the web view.\n MobileAds.registerWebView(webView);\n }\n }\n\nTest your integration\n\nBefore using your own URL, we recommend that you load the following URL to test\nthe integration: \n\n https://google.github.io/webview-ads/test#api-for-ads-tests\n\nThe test URL shows green status bars for a successful integration if the\nfollowing conditions apply:\n\n- `WebView` connected to the Next Gen Mobile Ads SDK\n\nNext steps\n\n- Gather consent in `WebView`. The Web view APIs for Ads doesn't propagate consent collected in the mobile app context using [IAB TCF v2.0](//iabeurope.eu/tcf-2-0/) or [IAB CCPA](//iabtechlab.com/wp-content/uploads/2019/11/Technical-Specifications-FAQ-US-Privacy-IAB-Tech-Lab.pdf) compliance frameworks to the tags in your web views. If you're interested in implementing a single consent flow as the owner of both the `WebView` and its corresponding web content being monetized, work with your consent management platform to gather consent in the `WebView` context."]]