AdSense ad code support for SSL

We’ve updated the AdSense ad code so that it now supports secure ad serving through Secure Sockets Layer (SSL) on Hypertext Transfer Protocol Secure (HTTPS) web pages. This means that publishers with secure sites, i.e., sites that are served over the HTTPS protocol, can now use AdSense ad code to serve SSL-compliant ads. Examples of secure websites include many financial services sites, e-commerce sites, and social networking sites.

Some important things to know about the SSL-compatible ad code:

  • The SSL-compatible ad code is designed for publishers who already have existing HTTPS-enabled sites. We don’t recommend that publishers with HTTP sites convert their sites to HTTPS unless they have a strong reason to do so. Unless you're a publisher who needs to protect important user information like credit card details, passwords, or medical records etc., you probably don't need change your site to HTTPS.

  • HTTPS-enabled sites require that all content on the page, including the ads, be SSL-compliant. As such, AdSense will remove all non-SSL compliant ads from competing in the auction on these pages. If you do decide to convert your HTTP site to HTTPS, please be aware that because we remove non-SSL compliant ads from the auction, thereby reducing auction pressure, ads on your HTTPS pages might earn less than those on your HTTP pages.

  • The SSL-compatible code also works on HTTP sites and doesn’t change how ads are served on these sites.
Older versions of the AdSense ad code don’t work with secure content. If you try to run HTTP ads on an HTTPS site, on most older browsers your visitors will get a mixed content warning, while on some modern browsers your visitors might not see any ads at all. If you want to place ads on secure pages, you’ll need to use the new SSL-compatible ad code.

How to use the SSL-compatible ad code

To use the new ad code on your HTTPS-enabled pages, use either of the options outlined here:

Option 1: Create new ad code

Generate your ad code, and then copy and paste the ad code into the HTML source code of your page where you'd like the ad to appear.

Option 2: Modify your existing ad code

To do this you'll need to make the following code change:

  • Synchronous ad code
    <script>
      google_ad_client=“ca-pub-xxxxxxxxxxxxxx”;
      google_ad_slot=“yyyyyyyyyyy”;
      google_ad_width=300;
      google_ad_height=250;
    </script>
    <script src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>

  • Asynchronous ad code
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
      style="display:inline-block;width:300px;height:250px"
      data-ad-client="ca-pub-xxxxxxxxxxxxxx"
      data-ad-slot="yyyyyyyyyyy">
    </ins>
    <script>
      (adsbygoogle=window.adsbygoogle || []).push({});
    </script>
In the examples above, “http” has been removed from both script sources. The source URLs now begin with two forward slashes, like this:
  • Synchronous ad code: "//pagead2.googlesyndication.com/pagead/show_ads.js"
  • Asynchronous ad code: "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"