• Hello,

    I just want to make sure if this kind of behavior is normal, or if I should try to figure out why it happens:

    I put the code:
    <?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?>
    right after <body> in header.php

    When inspecting the DOM I can see that there are 2 blocks of code inserted by the plugin, one of them is all in the header (NO.#1), the other one spans across the <head> and <body> – it starts before </head> and ends after <body> (NO.#2).

    Here’s an excerpt for (NO.#1):

    <!-- Google Tag Manager for WordPress by DuracellTomi - http://duracelltomi.com -->
    
    <em>a facebook scrips..
    tawk.to script..</em>
    
    <script type="text/javascript">
    	var gtm4wp_datalayer_name = "dataLayer";
    	var dataLayer = dataLayer || []
    </script>
    <!-- End Google Tag Manager for WordPress by DuracellTomi -->

    Here’s an excerpt for (NO.#2):

    ... some <head> code here...
    <em><!-- Google Tag Manager for WordPress by DuracellTomi --></em>
    <script type="text/javascript">
    	dataLayer.push({"pagePostType":"page","pagePostType2":"single-page","pagePostAuthor":"MyWebsite"});
    </script>
        <strong></head></strong>
        <strong><body></strong>
    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MyID"
    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-MyID');</script>
    <em><!-- End Google Tag Manager --></em>
    ... some <body> code here...

    I have 3 questions:

    1) Is it OK that I have any code related to the plugin in the <head> where I only called the pulgin’s function after body?

    2) Is it OK that I have this kind of code like shown in (NO.#2) where part of the block (according to your comments) is in the <head> and the rest is in the <body>?

    3) Is it natural that the comment block of code the plugin inserts surrounds other elements/scripts loaded in the page? (NO.#1)?

    Thank you!!

    https://ww.wp.xz.cn/plugins/duracelltomi-google-tag-manager/

Viewing 1 replies (of 1 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    1) yes, that is normal, in the <head> section I define the so called data layer variables that needs to be accessible while your tags firing on “All pages” trigger.

    2) Yes, the code at the beginning of the <body> loads your published GTM container and starts to fire your tags on “All pages”

    3) No, that is an odd behavior and it might be caused by some cache plugins

    Thomas

Viewing 1 replies (of 1 total)

The topic ‘General technical question’ is closed to new replies.