How to add Google Tag Manager to Magento 2?
- Triggers - Trigger identifies when and where the tags are to be executed.
- Variables - Variables receive and keep information used by tags and triggers.
How to add Magento 2 Google Tag Manager?
You can easily add Google Tag Manager in Magento 2 without third-party extensions. All you need is to add the GTM code to your active theme. The GTM code is divided into two parts: script and noscript.
You need to put the GTM snippet into these two phtml templates for head and body:
<script>..</script> <!-- GTM code -->
<noscript>..</noscript> <!-- GTM code -->
To load the files correspondingly you should use the default .xml file:
<!-- YourTheme/Magento_Theme/layout/default.xml -->
<block class="Magento\Framework\View\Element\Template" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
<block class="Magento\Framework\View\Element\Template" name="gtm.body" before="-" template="Magento_Theme::html/gtm_body.phtml" />
After GTM is added you can set up Google Analytics and other tools for tracking and reporting about website traffic.
If connecting 3rd-party extensions to your Magento 2 isn't really an option right now, check out this Advanced Reports extension: 20+ marketing reports, sales performance reports, real-time reports, create custom reports, customizable data grids.