Como adicionar o código do Google Auto Ads em </head>

I wanted to add adsense auto ads code to </head> of my every topic.

I have tried to add the following auto ads code in themes head section

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
</script> 
<script>
 (adsbygoogle = window.adsbygoogle || []).push({
      google_ad_client: "ca-pub-87837185XXXXXXXX",
      enable_page_level_ads: true
 });
</script>

But no success.

Hi @Vikas_Dangi

  1. Go to admin panel, Customize.
  2. Edit the theme.
  3. Then </head> section.
  4. Add that code.
  5. Save.
  6. Enjoy :wink:

Note that you still have to whitelist the external domain for CSP if this is a new install of Discourse, as CSP is mandatory on all new installs. CSP will be mandatory on all installs once 2.3 is released as well.

I have tried it but only the first script of code is showing in the source not the second.

I don’t know how to do this. So please tell me how can I whitelist CSP in my install, to make work this code.my discourse version is 2.3

Try searching for it here.

I mentioned this on another similar post also – wanted to xpost it here to make sure people finding this one in search are also aware.

I was having similar issues, and upon viewing the source of the page served, found that Discourse was stripping out the inline Javascript entirely.

This post mentions it:

but I don’t see a solution there.

I don’t either. I haven’t found a solution at the moment.

It’s a great solution, but not customizable. Every user on every page of the forum will face the code.

I want it to work like Discourse Advertisement Plugin, where you can choose user groups who can see ads and where. I prefers users below trust level 2 and only on topics where the content is enough to serve ads.

@codinghorror It will be great if this auto ads also added to Discourse Ads Plugin.

I’m not convinced that auto ads can work with Discourse. I can’t find any documentation about this, so maybe it’s possible. If you can point us to documentation about how to implement it with single page apps/infinite scroll, then we can try it.

The ad plugin handles AdSense and Ad Manager by using their APIs to request ads be rendered and updated, but I don’t see how that’s done with Auto Ads.

@neil, não há como forçar apenas uma atualização do JavaScript dos anúncios automáticos a cada carregamento de “página”?

Acho que ele teria dificuldades para gerenciar os anúncios ao rolar mais respostas, mas, além disso, parece uma solução interessante. Será que pode ser usado em combinação com os posicionamentos tradicionais do AdSense?

Não estou claro sobre o status dos Anúncios Automáticos, pois sua documentação é vaga… Mas pode ser que “simplesmente funcione” agora, de acordo com este post: