nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
166 stars 71 forks source link

When Google Tag Manager and Google gtag.js are both enabled, an extra script opening tag gets injected into the body #1538

Closed mei-lu closed 1 day ago

mei-lu commented 1 day ago

Describe the bug

When Google Tag Manager and Google gtag.js are both enabled, an extra script opening tag gets injected. When Google Tag Manager is disabled however, the issue goes away.

To reproduce

Steps to reproduce the behaviour:

  1. Go to Tracking Scripts
  2. Enable Google Tag Manager and Google gtag.js
  3. On web page, parts of the script get injected into the beginning of <body> and an extra <script> tag is inserted that remains unclosed. image image image

Expected behaviour

There should be no portion of the script injected into the <body>

Versions


khalwat commented 1 day ago

I just tried to replicate this, but am unable to. I end up with this:

<script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'WOOF', {'send_page_view': true,'anonymize_ip': false,'link_attribution': false,'allow_display_features': false});
</script>
<script>dataLayer = [];
(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','BARK');
</script>

...with no extra unclosed <script> tags. Are you sure they might not be coming from somewhere else in your code?

mei-lu commented 16 hours ago

@khalwat I could only replicate it locally when I set my environment to production ("live"). Global search in our code for anything GA related comes up blank. Sorry I forgot to mention that in the original description.

khalwat commented 15 hours ago

Right, that's what I did as well testing things... I set the SEOmatic environment to "live" so that the tracking scripts would render.

Are you sure there aren't any stray <script> tags anywhere in your templates?

I ask just because in a bare bones install, turning on both of those scripts did not result in what you reported initially.

mei-lu commented 15 hours ago

@khalwat Thanks for looking into that. I think our script template got messed up. Adjusting that fixes it, appreciate you looking into this!