Hi all..
I've read a number of articles about adding Google Tags to the head and body of magento 2 code and I understand the method of doing so.
My question is when I add the default.xml file to my custom theme, do I just add the extra Google tag code below or should I be copying the full code from the vendor/magento/module-theme/view/frontend/layout/default.xml file and add the extra Google Tag code below and save to my custom theme?
Will the two files merge if I only add the Google Tag code to my custom theme?
Many Thanks In advance for your help.
Andy
<referenceBlock name="head.additional"> <block class="Magento\Framework\View\Element\Template" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" /> </referenceBlock> <referenceContainer name="after.body.start"> <block class="Magento\Framework\View\Element\Template" name="gtm.body" before="-" template="Magento_Theme::html/gtm_body.phtml" /> </referenceContainer>
Solved! Go to Solution.
Thank you for clarifying that Nishu
I will try the solution later today and if it works, will mark your reply as 'Accepted as Solution'.
Thank you again
Andy
Hi @Andy_Acute ,
just add your google tag manager code in the default.XML file in custom theme.
clear cache to see the changes on front end.
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Hi Nishu
Thank you for responding to my question.
When you say 'just add your google tag manager code in the default.XML file in custom theme', do you mean copy the full code from vendor/magento/module-theme/view/frontend/layout/default.xml file, paste into my custom theme default.xml file and then add the Google Tag Manager Code and Save??
Or do you mean just add the Google Tag manager Code to my custom theme default.xml file?
Thank you
Andy
Hi @Andy_Acute ,
No need to copy the entire default.XML code. Just create the file in your theme and add google tag manager code. It will work.
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!