Reputation: 865
Uncaught TagError: adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them.
I am getting the error with this code:
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" type="text/javascript"></script>
<!-- -->
<ins class="ad-div adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-XXXXXXXXXX"
data-ad-slot="XXXXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Thing is this code works in Joomla, but it is not working with the Ohanah component. It is just one Ad, not many. There shouldn't be any PHP delays either. But it is not working
Upvotes: 1
Views: 14632
Reputation: 516
Try creating a function like this in JS file
function createAndAppendAdsElement(id, adUnitID) {
var parent = document.getElementById(id);
var ele = document.createElement('ins');
ele.style.display = 'block';
ele.className = 'adsbygoogle';
ele.setAttribute('data-ad-client', 'ca-pub-XXXXXXXX');
ele.setAttribute('data-ad-slot', adUnitID);
ele.setAttribute('data-ad-format', 'auto');
ele.setAttribute('data-full-width-responsive', 'true');
parent.appendChild(ele);
(adsbygoogle = window.adsbygoogle || []).push({});
}
This method finds a div with provided ID and then create a INS element and append it to that div.
Call this method on window load as below:
window.onload = function () {
createAndAppendAdsElement('elementOne', 'your_ad_unit_number');
createAndAppendAdsElement('elementTwo', 'your_ad_unit_number');
createAndAppendAdsElement('elementThree', 'your_ad_unit_number');
createAndAppendAdsElement('elementFour', 'your_ad_unit_number');
createAndAppendAdsElement('elementFive', 'your_ad_unit_number');
};
Upvotes: 2
Reputation: 1
The unique name must consist only of English letters (A-Z), numbers and underscores, and the first character must be an English letter.
no = < ins class="ad-div adsbygoogle" yes = < ins class="ad_div adsbygoogle"
https://support.google.com/adsense/answer/6307124?hl=tr
Upvotes: 0
Reputation: 49
This block of code is common, but this in web page tag and remove this code from rest of page, this should work
This if your web page has multiple ads.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Upvotes: 0
Reputation: 865
In my case, it seems the component takes these two scripts:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
And puts them on top of the page, so ins class... etc is dozens of lines below.
Upvotes: 0
Reputation: 865
Here is the thing,
When I put adsbygoogle = window.adsbygoogle || []).push({}); again at the end of the template, the ad works. But I still get the error message. But it works after the second adsbygoogle = window.adsbygoogle || []).push({}); executes.
Upvotes: 0
Reputation: 2176
As far I know "All ins elements in the DOM with class=adsbygoogle already have ads in them" means you have more (adsbygoogle = window.adsbygoogle || []).push({})
calls on your page than <ins class="adsbygoogle" ...></ins>
tags.
That usually happens when you experiment with various positions and (at least once) you forget to remove the whole snippet, but in this case it might be the component you are using is stripping ins
tag from AdSense code.
Press CTRL+U to view source and then F3 to search for adsbygoogle
, and you should be able to find the problem.
Upvotes: 8