• Hi,

    Is it possible to target the plugin or GTM to delay or Defer it? Has it’s seriously hindered our performance (expected with GTM).

    I tried this but it was not successful:

    // Define a function to modify the GTM container code and add delay
    function custom_modify_gtm_tag( $gtm_tag ) {
        // Check if the input contains the noscript tag, which indicates the <noscript> part of the container code
        if ( strpos( $gtm_tag, '<noscript>' ) !== false ) {
            // If the noscript tag is present, return the original GTM container code as it's not suitable for delay
            return $gtm_tag;
        } else {
            // If the noscript tag is not present, modify the GTM container code to include delay
            $gtm_tag = '<script>
                            setTimeout(function() {
                                ' . $gtm_tag . '
                            }, 2000); // Delay in milliseconds
                        </script>';
    
            // Return the modified GTM container code
            return $gtm_tag;
        }
    }
    
    // Hook the function to the gtm4wp_get_the_gtm_tag filter
    add_filter( 'gtm4wp_get_the_gtm_tag', 'custom_modify_gtm_tag' );

    Thanks!

    Adam

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello ! ??

    I have the same perf issue here.

    Everything works fine but when a user click on a product (in a grid of products) to go to Single product page, GTM4WP is causing a huge delay from the user’s click to the page loading. 

    When a user clicks on the product, the browser start loading after 2-3 secondes. 

    As you can see in this screenrecord : https://share.cleanshot.com/ZrV9TGZH

    When I click on the product right after that. 0:15 But the browser doesn’t even start loading anything. It starts loading at 0:17 (you can see the loader starts in the tab name) https://share.cleanshot.com/YY7LQzvG

    And you can see in this last screenshot on Network Dev Tools Tab that GTM4WP script is triggered and loaded (but after 2-3 secondes (from ~0:15 to ~0:17).

    I discussed with Kinsta support (where my website is hosted) and they pointed me that GTM4WP is the culprit. So I tried to disable GTM4WP in a Staging Environment and voila ! The product page start loading right after user clicks.

    Please can you help me with this issue ? Delay or differ GTM4WP trigger ?

    Did you guys find a solution?

    I use https://perfmatters.io/ plugin. Theres is an option to delay all JS o just selected one:

    /gtm.js /gtag/js gtag( /gtm- /gtm.

    Best solution: https://perfmatters.io/docs/delay-javascript/

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