How to add Google Tag Manager code in Beans


How can i add GTM code in Head meta footer.


Just add that to you functions.php. Change your ID!

// Add Google Tag Manager after <body>
beans_add_smart_action( 'beans_body_prepend_markup', 'j0e_add_google_tag_manager' );

function j0e_add_google_tag_manager() {

 ?>
  <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-xxxx"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
 '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-xxxx');</script>
 <?php

}

Jochen Gererstorfer Thanks Dear


I was trying to do this as well. There are two sets of code: one goes as high in tag as possible, the other goes right after the tag.

The above works well for the part after . But how would you put the code in the tag?

EDIT: Pardon me, just answered my own question. You just use beans_head_prepend_markup.


Yes thats the new tagmanger code.

That code in the <head is important, if you want to drive A/B tests.

Write a reply

Login or register to write a reply, it's free!