Jump to content
thirty bees forum
  • 0

Customs JS always displaying at the end of page instead of head


Question

Posted

Hi, trying to add GA4 scripts, i put them in head.tpl (niara theme) immediately after <head> tag

<!-- Google Tag Manager -->
{literal}                  
<script async src="https://www.googletagmanager.com/gtag/js?id=G-***"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-***');
</script>
{/literal}
<!-- End Google Tag Manager -->

 

But what i get is that this one display where it should be:

<!-- Google Tag Manager -->

<!-- End Google Tag Manager -->

and all the script goes to very end of the page. How should i fix that. Thanks

3 answers to this question

Recommended Posts

  • 0
Posted

You can turn off:

image.png.725317dcd8b7a2e01e1ef8b7f83c2f2c.png

but I would not do that as it does not affect the performance of GA4.

Also with TB there's no need to manually edit your header.tpl. You can put custom JS and CSS code in BO in Preferences->Custom Code

  • Like 1
  • 0
Posted

As @the.rampage.rado suggested, you can disable moving javascript to the end. I would recommend to do this anyway, as moving javascript to the end can cause a lot weird issues.

You can also add data-keepinline attribute to script tags to instruct core to not try to move it

        <script data-keepinline>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());

            gtag('config', 'G-***');
        </script>

 

  • 0
Posted
11 hours ago, the.rampage.rado said:

You can turn off:

image.png.725317dcd8b7a2e01e1ef8b7f83c2f2c.png

but I would not do that as it does not affect the performance of GA4.

Also with TB there's no need to manually edit your header.tpl. You can put custom JS and CSS code in BO in Preferences->Custom Code

thank you so much, it worked!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...