I am trying to load adsense JS code into the header. But it's not showing. I'm using:

googleads:
  header: true
  js:
    https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxx: { type: external, attributes: { async: true; crossorigin: anonymous } }

Another one however shows properly:

fonts:
  header: true
  js:
    https://use.fontawesome.com/8eb20c4bb1.js: { type: external, minified: true }

I have checked the space indents. Those all seem fine. What could I be doing wrong?

Comments

subir_ghosh’s picture

So, I solved this. :D Here it is (just in case it helps anyone else):-

This needs to be first defined in the themename.info.yml file

libraries:
  - themename/googleads

And the JS library declaration had to be modified in themename.libraries.yml a bit:

googleads:
  header: true
  js:
    https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxx:
      type: external
      attributes:
        async: true
        crossorigin: anonymous

-----------------------------
Subir Ghosh
www.subirghosh.in