How to force GTM to add tag in the <head>?

混江龙づ霸主 提交于 2019-12-14 03:05:44

问题


I've followed below steps for adding AdSense script inside of my website:

  1. Now that you have the code head over to GTM.
  2. Create a new tag.
  3. Provide a name.
  4. Select custom HTML as the tag template.
  5. Copy and paste the code into the text field.
  6. Set the trigger to fire on All pages or the pages you want to serve ads on.
  7. Click Save and Submit to push the code live.

I did it and all fine. Here is my full code: (define as a tag in google tag manager)

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

The problem is:

Script above will be added to the dom separately. I mean, this part:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

appends to the <head> section, and this part:

<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-<token>",
    enable_page_level_ads: true
  });
</script>

appends to the <body> senction. So google AdSanse says:

The code is missing or incomplete

Any idea how can I make GTM force to add both scripts right after each other inside <head> section?

来源:https://stackoverflow.com/questions/57134297/how-to-force-gtm-to-add-tag-in-the-head

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!