Para analizar nuestros productos y proporcionar comentarios sobre ellos, únete al canal oficial de Ad Manager en Discord, en el servidor Google Advertising and Measurement Community.
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Si tu app utiliza WebView para mostrar contenido web, te recomendamos que la configures de modo que el contenido se pueda monetizar de forma óptima con anuncios.
En esta guía, se muestra cómo proporcionar información sobre la configuración de un objeto WebView.
Habilita las cookies de terceros
Para mejorar la experiencia del usuario con los anuncios y cumplir con la política de cookies de Chrome, habilita las cookies de terceros en tu instancia de WebView.
La configuración predeterminada de WebView no está optimizada para los anuncios. Usa las APIs de WebSettings para configurar tu WebView para lo siguiente:
JavaScript
Acceso al almacenamiento local
Reproducción automática de videos
Java
importandroid.webkit.CookieManager;importandroid.webkit.WebView;publicclassMainActivityextendsAppCompatActivity{privateWebViewwebView;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){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);}}
Kotlin
importandroid.webkit.CookieManagerimportandroid.webkit.WebViewclassMainActivity:AppCompatActivity(){lateinitvarwebView:WebViewoverridefunonCreate(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}}
Carga contenido de la vista web
Las cookies y las URLs de las páginas son importantes para la monetización de la vista web y solo funcionan según lo previsto cuando se usa loadUrl() con una URL basada en la red. Para optimizar el rendimiento de WebView, carga el contenido web directamente desde URLs basadas en la red. Evita usar WebViewAssetLoader, cargar recursos desde el dispositivo o generar contenido web de forma dinámica.
Java
importandroid.webkit.CookieManager;importandroid.webkit.WebView;publicclassMainActivityextendsAppCompatActivity{privateWebViewwebView;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){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);// Load the URL for optimized web view performance.webView.loadUrl("https://google.github.io/webview-ads/test/");}}
Kotlin
importandroid.webkit.CookieManagerimportandroid.webkit.WebViewclassMainActivity:AppCompatActivity(){lateinitvarwebView:WebViewoverridefunonCreate(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// Load the URL for optimized web view performance.webView.loadUrl("https://google.github.io/webview-ads/test/")}}
Prueba la vista web
Durante el desarrollo de la app, te recomendamos que cargues esta URL de prueba:
para verificar que esta configuración tenga el efecto deseado en los anuncios. La URL de prueba tiene criterios de éxito para una integración completa si se observan los siguientes elementos:
Configuración de la vista web
Funcionamiento de las cookies de terceros
Funcionamiento de las cookies propias
JavaScript habilitado
Almacenamiento DOM habilitado
Anuncio de video
El anuncio de video se reproduce de forma intercalada y no se abre en el reproductor integrado de pantalla completa.
El anuncio de video se reproduce automáticamente sin que se haga clic en el botón de reproducción.
El anuncio de video se puede volver a reproducir
Una vez que se completen las pruebas, sustituye la URL de prueba por la URL que la vista web pretende cargar.
[null,null,["Última actualización: 2025-08-31 (UTC)"],[[["\u003cp\u003eConfigure Android \u003ccode\u003eWebView\u003c/code\u003e to optimize ad monetization by enabling features like third-party cookies, JavaScript, and local storage access.\u003c/p\u003e\n"],["\u003cp\u003eEnsure web content is loaded directly from network-based URLs for optimal performance and ad functionality.\u003c/p\u003e\n"],["\u003cp\u003eUtilize provided code snippets in Java or Kotlin to implement the recommended \u003ccode\u003eWebView\u003c/code\u003e configurations.\u003c/p\u003e\n"],["\u003cp\u003eEmploy the test URL to validate the integration and ensure proper ad behavior during app development.\u003c/p\u003e\n"],["\u003cp\u003eFor alternative content loading methods, consider transmitting the PPID and relevant page URL to mitigate monetization loss.\u003c/p\u003e\n"]]],[],null,["If your app utilizes `\n`[`WebView`](//developer.android.com/reference/android/webkit/WebView) to display web content, it's\nrecommended to configure it so that content can be optimally monetized with ads.\n\nThis guide shows you how to provide information about how to configure a\n`WebView` object.\n| **Important:** To properly set up and optimize `WebView`, apply all of the following recommendations to each `WebView` instance in your app. To help identify each web view, toggle the [\"highlight-all-webviews\"](//chromium.googlesource.com/chromium/src/+/main/android_webview/docs/developer-ui.md#flag-ui) flag in WebView DevTools to highlight the web views in your app with a yellow tint.\n\nEnable third-party cookies\n\nTo improve your user's ad experience and be consistent with Chrome's\n[cookie policy](//policies.google.com/technologies/cookies), enable third-party\ncookies on your `WebView` instance. \n\nJava \n\n CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);\n\nKotlin \n\n CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)\n\nWeb settings\n\nDefault `WebView` settings are not optimized for ads. Use the\n[`WebSettings`](//developer.android.com/reference/android/webkit/WebSettings)\nAPIs to configure your `WebView` for:\n\n- JavaScript\n- Access to local storage\n- Automatic video play\n\nJava \n\n import android.webkit.CookieManager;\n import android.webkit.WebView;\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 }\n\nKotlin \n\n import android.webkit.CookieManager\n import android.webkit.WebView\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 }\n\nLoad web view content\n\nCookies and page URLs are important for web view monetization and only function\nas expected when\n[`loadUrl()`](//developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String,%20java.util.Map%3Cjava.lang.String,java.lang.String%3E)) is used with a network-based URL. For optimized\n`WebView` performance, load web content\ndirectly from network-based URLs. Avoid using [`WebViewAssetLoader`](//developer.android.com/reference/androidx/webkit/WebViewAssetLoader), loading\nassets from the device, or generating web content dynamically.\n\n\nJava \n\n import android.webkit.CookieManager;\n import android.webkit.WebView;\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 // Load the URL for optimized web view performance.\n webView.loadUrl(\"https://google.github.io/webview-ads/test/\");\n }\n }\n\nKotlin \n\n import android.webkit.CookieManager\n import android.webkit.WebView\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 // Load the URL for optimized web view performance.\n webView.loadUrl(\"https://google.github.io/webview-ads/test/\")\n }\n }\n\n| **Tip:** If you need to load web view content from others means, such as HTML, you can mitigate the negative impact on monetization by transmitting the [Publisher Provided Identifier](//support.google.com/admanager/answer/2880055#setting_the_identifier) (PPID) and the relevant page URL ([GPT](/publisher-tag/guides/passback-tags#specify_page_url) \\| [AdSense](/adsense/management/reference/rest/v2/Dimension)) along with your web view request. These changes mitigate the monetization loss compared to loading web content from a network-based URL.\n\nTest the web view\n\nDuring app development, we recommend that you load this test URL: \n\n https://google.github.io/webview-ads/test/\n\nto verify these settings have the intended effect on ads. The test URL has\nsuccess criteria for a complete integration if the following are observed:\n\nWeb view settings\n\n- Third-party cookies work\n\n\u003c!-- --\u003e\n\n- First-party cookies work\n- JavaScript enabled\n\n\u003c!-- --\u003e\n\n- DOM storage enabled\n\nVideo ad\n\n- The video ad plays inline and does not open in the full screen built-in player\n- The video ad plays automatically without clicking the play button\n- The video ad is replayable\n\nAfter testing is complete, substitute the test URL with the URL the web view\nintends to load."]]