Ad code implementation

AdSense ad code support for SSL

AdSense ad code supports secure ad serving through Secure Sockets Layer (SSL) on all pages, including Hypertext Transfer Protocol Secure (HTTPS) pages. This means that publishers with secure sites, i.e., sites that are served over the HTTPS protocol, can use AdSense ad code to serve SSL-compliant ads. All sites should be secured with HTTPS — HTTPS provides critical security and data integrity both for your sites and for the people who entrust your sites with their personal information.

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

  • HTTPS-enabled sites require that all content on the page, including the ads, be SSL-compliant. For most users, AdSense ad requests are always SSL-compliant and always served over HTTPS, even when the surrounding site is HTTP. The same ads compete in the auction, so switching your site to HTTPS will have no effect on the ads most users see, or on auction pressure. The only exception is for users located in countries that block or otherwise degrade HTTPS traffic.

  • If your site can be accessed over HTTPS, then you may need to update older versions of AdSense ad code to avoid the AdSense script being blocked as mixed content. If your AdSense ad code has a script starting with "http://", then you should update it to "https://" instead:

    1. <script src="">
    2. <script async src="">

    The HTTPS version of the ad code is also safe for HTTP pages; you don't need to serve two different versions.

  • The SSL-compatible ad code also works on HTTP sites and doesn’t change how ads are served on these sites.

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 src="//"></script>
  • Asynchronous ad code
    <script async src="//"></script>
    <ins class="adsbygoogle"
      (adsbygoogle=window.adsbygoogle || []).push({});
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: "//"
  • Asynchronous ad code: "//"
Was this helpful?
How can we improve it?