Reputation: 423
I have some DFP (googletagId) ads and 4 adsense ads based on the async adsbygoogle.js script. - Out of the 4 google adsense ads, the 1st adsense ad is visible randomly.
I have followed the following strategy for the google adsense:
<head>
....
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>
<body>
<div id="ad1">
<!-- Adsense #1 -->
<ins class="adsbygoogle"
style="display:inline-block;min-width:320px;max-width:1200px;width:100%;height:110px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
....
<div id="ad2">
<!-- Adsense #2 -->
<ins class="adsbygoogle"
style="display:inline-block;height:250px; width:300px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
....
<div id="ad3">
<!-- Adsense #3 -->
<ins class="adsbygoogle"
style="display:inline-block;height:250px; width:300px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
....
<div id="ad4">
<!-- Adsense #4 -->
<ins class="adsbygoogle"
style="display:inline-block;min-width:320px;max-width:1200px;width:100%;height:325px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
Adsense #1 is displayed randomly. i.e. sometimes it displays, sometimes not. As you can see in the image.
All other ads DFP and AdSense display properly, but the first AdSense Ad displays randomly.
Any help is appreciated!
Note: I have posted this on AdSense Help Forum but it seems like Google Engineers don't want to help.
Upvotes: 1
Views: 974
Reputation: 512
Try to modify your adsense script to be something like this
<script>
var myVar = setInterval(myAdsense ,3000);
function myAdsense() {
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>
It might be not the best answer but it tricks the reload session so the adsense will keep appear.
EDIT
To display the remaining ads and keep your website perfomance up you can duplicate the function and stop the function when the ads is displayed. How? do something like this:
<head>
....
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>
<body>
<div id="ad1">
<!-- Adsense #1 -->
<ins class="adsbygoogle"
style="display:inline-block;min-width:320px;max-width:1200px;width:100%;height:110px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
var myVar = setInterval(myAdsense1 ,3000);
function myAdsense1() {
(adsbygoogle = window.adsbygoogle || []).push({});
}
if (adsbygoogle == "[object Object]") clearInterval(myAdsense1);
</script>
</div>
....
<div id="ad2">
<!-- Adsense #2 -->
<ins class="adsbygoogle"
style="display:inline-block;height:250px; width:300px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
var myVar = setInterval(myAdsense2 ,3000);
function myAdsense2() {
(adsbygoogle1 = window.adsbygoogle || []).push({});
}
if (adsbygoogle1 == "[object Object]") clearInterval(myAdsense2);
</script>
</div>
....
<div id="ad3">
<!-- Adsense #3 -->
<ins class="adsbygoogle"
style="display:inline-block;height:250px; width:300px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
var myVar = setInterval(myAdsense3 ,3000);
function myAdsense3() {
(adsbygoogle2 = window.adsbygoogle || []).push({});
}
if (adsbygoogle2 == "[object Object]") clearInterval(myAdsense3);
</script>
</div>
....
<div id="ad4">
<!-- Adsense #4 -->
<ins class="adsbygoogle"
style="display:inline-block;min-width:320px;max-width:1200px;width:100%;height:325px;"
data-ad-client="XXX"
data-ad-slot="XXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({}); //so on
</script>
</div>
Upvotes: 1