Question: I add to google tag manager script code but where to add file path I don't know. Can you please tell me the file path in magento2?

Answer: 
To add Google Tag Manager code follow below code snippet

You need 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:

> 
> YourTheme/Magento\_Theme/templates/html/gtm\_head.phtml
> 
> 
> 
> ```
> <script>..</script> <!-- GTM code -->
> 
> ```
> 
> YourTheme/Magento\_Theme/templates/html/gtm\_body.phtml
> 
> 
> 
> ```
> <noscript>..</noscript> <!-- GTM 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>

```

Then create two files gtm\_head.phtml and gtm\_body.phtml in Vendor/Theme/Magento\_Theme/templates/html directory and add GTM code as mentioned above.
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:
> 
> 
> 

**YourTheme/Magento\_Theme/templates/html/gtm\_head.phtml**

```
<script>..</script> <!-- GTM code -->

```

**YourTheme/Magento\_Theme/templates/html/gtm\_body.phtml**

```
<noscript>..</noscript> <!-- GTM code -->

```

To load the files correspondingly you should use the default .xml file:

**YourTheme/Magento\_Theme/layout/default.xml**

```
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <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>
    </body>
</page>

```

***NOTE: You must run the deploy command after adding the above files***