Unable to manually delay Google Tag Manager
-
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.
- I have set ‘Load JS Deferred’ to
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.