Google adsense not showing

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.
1 Like

I think the error message is very clear, isn’t it?

There is already another ad on the same element you want to add it to.

Change clases and it will work. I you want to generate it dynamically you can use Random.id(4) for classes name.

Yes I agree the error is clear but the result is not…
gadsense-A is unique there is no other element in any other page with that class.
I even gave it it’s own unique id and still I get the same result.