I was following code shown here in one of my templates (templateA) to show google adsense
In adsense.js
Adsense = {};
Adsense.addTop = function() {
$.getScript("//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", function() {
var ads, adsbygoogle;
ads = '<ins class="adsbygoogle"\
style="display:block"\
data-ad-client="<AD-CLIENT>"\
data-ad-slot="<AD-SLOT>"\
data-ad-format="auto"></ins>'
$('.gadsense-A').html(ads);
return (adsbygoogle = window.adsbygoogle || []).push({});
});
}
Template.TemplateA.onRendered(function() {
Adsense.addTop();
})
and at the html:
<div class="gadsense-A"></div>
This works fine for templateA but when I try to do the same for templateB (changing A everywhere to B and using a different ad) the ad never shows up and i get the dreadful:
adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them.