Reputation: 889
I'm trying to add 2 adsense codes to one page. When I do it only one (the first defined) is shown and the page seems to be in endless loading.
Here is the code with example slots and client IDs.
<body>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxx";
google_ad_slot = 111111111;
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
google_ad_slot = 222222222;
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</body>
If I remove one of these adSense codes than it works. How can I make it work with both codes?
Upvotes: 3
Views: 4822
Reputation: 889
Finally after almost 2 hours of googling I figured it out. Only thing I had to do is to add quotes to google_ad_slot variable (Oh my...). So the working code looks like this:
<body>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxx";
google_ad_slot = "111111111"; // see the quotes
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
google_ad_slot = "222222222";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
If there is just one adSense code, the slot as an integer works fine. If you add another, you must define all slots as strings.
Cheers!
Upvotes: 7
Reputation: 982
First of all there is no need to require the show-ad.js file twice. Secondly it seems that show-ad.js looks at some set global variables
google_ad_client = "ca-pub-xxxxxxxxx";
google_ad_slot = 111111111;
google_ad_width = 160;
google_ad_height = 600;
When you define them a second time the first values are dicarted, and the first one is only shown because loading the script a second time interferes with the first.
Upvotes: 1