Gary Davis' Blog

DotNET/PayPal Development and other Techie Stuff
posts - 45, comments - 112, trackbacks - 0

How to Suppress Google AdSense (Syndication) for SSL Https Pages

Google AdSense is not supported for https (see here). If you attempt to use it on an SSL page, you will see this warning in IE8.Image1 The user would have to click No to allow the request (for a .js file in this case) to complete. Answering Yes will block it (the wording seems backwards from what you’d expect).

Some postings I saw said to change the .js url in the script to use https://pagead2.googleadservices.com/pagead/show_ads.js but while this will work for this one .js file, the script then attempts to pull in other .js files using http so you still get the warning popup.

The best solution is to not let the warning pop up on your secure pages.

This is the standard AdSense code:

<script type="text/javascript">
    if ("http:" == document.location.protocol) {
     google_ad_client = "pub-1234567890123456";
     google_ad_slot = "1234567890";
     google_ad_width = 728;
     google_ad_height = 90;
     google_ad_format = "728x90_as";
    }
</script>

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

This is the new version that will suppress the AdSense code and prevent the popup on your SSL pages. Simply insert the document.write statement and remove the second script.

<script type="text/javascript">
    if ("http:" == document.location.protocol) {
     google_ad_client = "pub-1234567890123456";
     google_ad_slot = "1234567890";
     google_ad_width = 728;
     google_ad_height = 90;
     google_ad_format = "728x90_as";
     document.write(unescape(
        "%3Cscript src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript' %3E%3C/script%3E"));
    }
</script>

This fix uses the existing conditional block for non-SSL pages that initializes some google_ad variables to also emit a <script> element to pull in the necessary show_ads.js file. For SSL pages, the variables will not be initialized and the script will not be emitted for the page.

Print | posted on Friday, September 03, 2010 1:03 PM |

Feedback

Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Thanks for the tip. I was also suffering from same problem.
9/7/2010 11:26 AM | mohit
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Gary,

Thank you for this awesome post... it is just what I needed to get around the https pop up. You can see it in action on one of our e-commerce sites powered by 3dcart.. http://riluk.com. Notice how the ads appear on non-secure but not on SSL pages. Fantastic because IE is a pain in the arse.
10/30/2010 6:23 PM | Luke Thomas
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

I think this is the major problem for most of the Adsense publishers,thanks for the tip.
11/29/2010 7:43 AM | Web Design USA
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Thanks for this useful information! I was ready to scrap the whole idea tell Google ads supported SSL !!
2/17/2011 4:42 PM | Swiksys
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

great post and much needed. my google ads have a slightly different format and ive tried the fix several ways and it wont work properly. any chance i could get a little help?

my code:
<script type="text/javascript"><!--
google_ad_client = "pub-123456789012345";
/* 120x600, PSL - left side */
google_ad_slot = "1234567890";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

thanks for any help you can offer.

2/25/2011 2:28 PM | chris
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Perfect! Thanks! I really do not understand why Google just doesn't offer this??
8/23/2011 3:00 AM | Ian
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Chris,

I also have the newer AdSense code that does not, directly, work with this fix. However, I simply decided to use this fix code, rather than the newer AdSense code, and it works fine. Google is apparently providing legacy support this older-style code -- that includes the IF statement -- which the newer-style AdSense code does not have (such that you illustrated).

So, this older code will work to suppress AdSense on all https pages, at least for the time being...
10/4/2011 8:13 PM | Jim
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Awesome. Thanks!
10/9/2011 2:53 PM | Sean
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

It's a joke to google who have money can not afford to purchase an SSL connection to the ads that's so sick that it is not true, have stopped using google adsense Due to the nature of them do not have SSL support:)
11/26/2011 8:19 AM | Mikael Jakobsson
Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

I'm not able to get the ad to display using that code above, but im also using the new adsense ad format. Going to play with the code a bit more. Anyone else seeing this?
12/23/2011 12:23 AM | JuggaloBook

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 6 and 3 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET