Add Google Tag Manager scripts

  • How do I add these Google Tag Manager scripts to GeneratePress?

    There are two scripts.

    1. Paste this code as high in the <head> of the page as possible:

    <!– Google Tag Manager –>
    <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=
    https://www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,’script’,’dataLayer’,’GTM-5Z3VV7MK’);</script>
    <!– End Google Tag Manager –>

  • Hi there,

    You can use a Hooks Element to add it.

    Go to Appearance > Elements and create a new Hook Element.

    Paste the script into the content area. Then, under the Settings panel, configure the following:

    Hook: wp_head
    Priority: 1

    Under Display Rules, set the location to Entire Site.

  • Thanks for this information.

    There’s a 2nd script that didn’t go through in my first post.

    2. Paste this code immediately after the opening <body> tag:
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-5Z3VV7MK&#8221;
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>

  • The second script needs to use a different hook.

    Create a separate Hook Element for it, and set the hook to wp_body_open instead.

  • Thanks! GeneratePress Elements are great!

  • You’re welcome!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.