Notification

Nezapomeňte navštívit stránku Vaše AdSense. Najdete na ní personalizované informace o svém účtu, které vám pomohou službu AdSense lépe využívat.

Požadovaná stránka aktuálně není k dispozici ve vašem jazyce. V dolní části stránky však můžete vybrat jiný jazyk, případně pomocí funkce překladu integrované v prohlížeči Google Chrome jakoukoli stránku okamžitě přeložit do vybraného jazyka.

Průvodce implementací kódu

Integrate the AdSense ad code with a Content Security Policy (CSP)

This article describes Content Security Policy (CSP) and how to integrate it with your AdSense ad code. Note that publishers are not required to use CSP. If you do want to use CSP, follow the steps below to ensure your AdSense code works correctly when you enable CSP.

What is CSP

Content Security Policy (CSP) is a means of securing your web page by limiting what resources and scripts are allowed to load and execute. You can enable CSP by setting a Content-Security-Policy header in HTTP responses from your web server.

There are two standard ways to configure CSP:

  1. Specify an allowlist of domains that can inject their resources on the page.
  2. Specify a random nonce, with which resources on the page must be marked in order to load. This approach is known as strict CSP.

Because the domains that the AdSense ad code uses change over time, we only support strict CSP (option 2). This approach removes the need to maintain a rolling list of domains that might become outdated and break your site.

Setting up strict CSP with the AdSense ad code

To enable CSP on your web server, follow the steps outlined in Adopt a strict CSP which explains how to set up the CSP header and apply the nonce to every script tag on your page, including the AdSense code. The AdSense code specifically supports the following CSP directives:

Content-Security-Policy:
  object-src 'none';
  script-src 'nonce-{random}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
  base-uri 'none';
  report-uri https://your-report-collector.example.com/

You can choose a more permissive policy if it fits your use case. More restrictive policies may break without notice.

Code example

Here's an example of the AdSense code with strict CSP:

<script nonce="${nonce}" async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=i-gno/re-d1234&host=ca-host-pub-5678" crossorigin="anonymous">
</script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="i-gno/re-d1234"
     data-ad-host="ca-host-pub-5678">
</ins>
<script nonce="${nonce}">
   (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Testing

We recommend that you test your policies first by setting the Content-Security-Policy-Report-Only header instead of Content-Security-Policy. The header reports violations but still allows them on the page.

Pomohly vám tyto informace?

Jak bychom článek mohli vylepšit?
Search
Clear search
Close search
Main menu
3172630205996643090
true
Prohledat Centrum nápovědy
true
true
true
true
true
157
false
false
false
false