• Resolved Gerard Blanco

    (@sixaxis)


    Hi there,

    The situation is this one:

    • I have set ‘Load JS Deferred’ to Deferred.
    • I have set ‘JS Minify’ to OFF.
    • I have set ‘JS Combine’ to OFF.
    • I have entered googletagmanager.com in the JS Delayed Includes box.

    The result is that the following inline JS code is not delayed.

    function add_google_tag_manager() {
    ?>
    <!-- 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-XXXXXXXX');</script>
    <!-- End Google Tag Manager -->
    <?php
    }
    add_action('wp_head', 'add_google_tag_manager');
    function add_custom_script_after_body() {
    ?>
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->
    <?php
    }
    add_action('wp_body_open', 'add_custom_script_after_body');

    What am I missing? How can I delay only Google Tag Manager?

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support qtwrk

    (@qtwrk)

    because gtag is default exclude to avoid problem.

    Thread Starter Gerard Blanco

    (@sixaxis)

    @qtwrk Why? Can I override this behaviour?

    Plugin Support qtwrk

    (@qtwrk)

    it’s kind of hard-coded , certain you can override it , but upon next time the plugin upgraded, it will override your change again.

    Thread Starter Gerard Blanco

    (@sixaxis)

    @qtwrk, so how come gtag is not excluded when I set ‘Load JS Deferred’ to?Delayed?

    rudolfl

    (@rudolfl)

    Actually, I see same problem — gtag slows down site. I would like to defer it as well. Yes, i understand the consequences.

    May I suggest adding an option or a filter to override this default exclusion?

    Plugin Support qtwrk

    (@qtwrk)

    because in /wp-content/plugins/litespeed-cache/data , there is a text file with default exclude list , gtag is in the list.

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