You can easily add GTM without third-party extensions. All you need is to add the GTM code to your active theme. The GTM code consist of two parts: script and noscript.
You need to put the GTM snippet into these two phtml templates for head and body:
New File#1
// YourTheme/Magento_Theme/templates/html/gtm_head.phtml
<script>..</script> <!– GTM code –> add the GTM head code
New File#1
// YourTheme/Magento_Theme/templates/html/gtm_body.phtml
<noscript>..</noscript> <!– GTM code –> add the GTM no script code
To load the files correspondingly you should use the default .xml file:
<!– YourTheme/Magento_Theme/layout/default.xml –>
<referenceContainer name=”head.additional”>
<block class=”Magento\Framework\View\Element\Template” name=”gtm.head” before=”-” template=”Magento_Theme::html/gtm_head.phtml” />
</referenceContainer>
<referenceContainer name=”after.body.start”>
<block class=”Magento\Framework\View\Element\Template” name=”gtm.body” before=”-” template=”Magento_Theme::html/gtm_body.phtml” />
</referenceContainer>