Integrate the WebView API for Ads

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 Google 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.


  • Google Mobile Ads SDK version 20.6.0 or higher.
  • Android API level 21 or higher.

  • Add the following <meta-data> tag in your AndroidManifest.xml file to bypass the check for the APPLICATION_ID. If you miss this step and don't provide the <meta-data> tag, the Google Mobile Ads SDK throws an IllegalStateException on app start.

    <!-- Bypass APPLICATION_ID check for web view APIs for ads -->

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.


import android.webkit.CookieManager;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {
  private WebView webView;

  protected void onCreate(Bundle savedInstanceState) {
    webView = findViewById(;

    // Let the web view accept third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    // Let the web view use JavaScript.
    // Let the web view access local storage.
    // Let HTML videos play automatically.

    // Register the web view.


import android.webkit.CookieManager
import android.webkit.WebView

class MainActivity : AppCompatActivity() {
  lateinit var webView: WebView

  override fun onCreate(savedInstanceState: Bundle?) {
    webView = findViewById(

    // Enable third-party cookies.
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
    // Enable JavaScript in the WebView.
    webView.settings.javaScriptEnabled = true
    // Enable DOM storage in the WebView.
    webView.settings.domStorageEnabled = true
    // Enable videos to play automatically.
    webView.settings.mediaPlaybackRequiresUserGesture = false

    // Register the web view.

Test your integration

Before using your own URL, we recommend that you load the following URL to test the integration:

The test URL shows green status bars for a successful integration if the following conditions apply:

  • WebView connected to the Google 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.