yireo/Yireo_GoogleTagManager2

Does loading via text/x-magento-init have any negative impact

Closed this issue · 6 comments

amenk commented

Google recommends to load the tag manager as soon as possible after the <body> tag and to include also some code in the head tag. This does not seem to be the case in this module.

Is this intentional?

I can't dive into the specifics of how Magento works internally, so I assume you are a frontend developer that understands the Magento JavaScript system inside out and therefore I can jump to the technical conclusion right away. First of all, text/x-magento-init is not rendered as JavaScript because it is not identified as a JavaScript script. What Google thinks of this is not something that applies to our extension, but to Magento 2 in general, so therefore I will refer to the Magento forums for this. This extension complies 100% with the Magento standards, so this definitely justifies the approach.

amenk commented

I see this is following mage2 standards which is great. I am just wondering if the GTM is executed later then it should and of this would limit the used tag's abilities.

Closing because of lack of reply. Feel free to re-open if needed

amenk commented

Years later we have a practical impact of what a I was fearing: We inject a Facebook Tracking Pixel Code by GTM and it looks like, due to the asynchronous loading of GTM, this is executed too late, leading to the Facebook tracking pixel to be inserted way to late in the DOM.

So I think we should at least have an option here in this plugin to include the tag according to GTM recommendations. And the other option to use Magento standards. Or no option at all and use the first approach?

@jissereitsma Please reopen

@amenk I think this way it is done now is more user friendly (async 3rd party data).
Of course there is a chance some things won't load before user will leave the success page etc.

In Magento 2.3 EE they have GTM module and it also work similar way.

I see two options

  • implement facebook pixel manually (not via GTM) that will be loaded as soon as possible and provide data this pixel need
  • build own custom GTM implementation that will inject GTM code in the head via server side (vs client side) or use other module (Weltpixel (free/paid) / Magepal (paid as free version doesnt have a lot of things). However I don't remember if they inject GTM trough JS script or via server side.

Should this be an option here? I guess for many people helpful. However someone need to find time and create PR here as I guess Jisse already did a lot and I think for him it's not so crucial feature.

I'm closing this issue, because it was accurate ages ago, but since then, the module has undergone numerous changes. The issue is still that x-magento-init is being used. However, because this module relies upon customerData I would say the performance issue is more a Magento issue than an issue of this extension specifically.