Search
Clear search
Close search
Google apps
Main menu

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="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    2. <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">

    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>
      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"
Was this article helpful?
How can we improve it?
Sign in to AdSense

Sign in to AdSense to see help for your account

Don't have an AdSense account? Sign Up for AdSense!