Where to add Google tag manager script code for magento2 file path?Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?Where to add google analytics script code in magento2 file path?Magento2: GA e-commerce moduleAdd JavaScript Tag on severals pages via a Magento custom module + Back Officemagento2: how to add store managerPath of file for Catalog, Manage Products, Add Product - In that Save buttonHow to add the drop-down box in Expired products admin grid in Magento1?Magento2 : Cron script readiness check failedHow to import related products through programmatically in magento2?Where to add google analytics script code in magento2 file path?How to add bing script code for adding bing search engine to my magento2 website then where to add that script code in Magento2?How to add third-party script code into our magento2 for Website trackingMagento 2 -Google Tag Manager Enhanced E-commerce Tracking?

How (un)safe is it to ride barefoot?

Is fission/fusion to iron the most efficient way to convert mass to energy?

Is there a frequency comparator device?

Why did Robert pick unworthy men for the White Cloaks?

Why did the Death Eaters wait to reopen the Chamber of Secrets?

Why didn't all the iron and heavier elements find their way to the center of the accretion disc in the early solar system?

Am I being scammed by a sugar daddy?

Why would a home insurer offer a discount based on credit score?

Why is the concept of the Null hypothesis associated with the student's t distribution?

The best in flight meal option for those suffering from reflux

My mom's return ticket is 3 days after I-94 expires

Why didn't the people of King's Landing riot when the Great Sept of Baelor was destroyed?

Is plausible to have subspecies with & without separate sexes?

Can you open the door or die? v2

What do you call the action of "describing events as they happen" like sports anchors do?

Which are the methodologies for interpreting Vedas?

What do I need to do, tax-wise, for a sudden windfall?

Is it possible to have battery technology that can't be duplicated?

Do Veracrypt encrypted volumes have any kind of brute force protection?

Changing the PK column of a data extension without completely recreating it

What publication claimed that Michael Jackson died in a nuclear holocaust?

Can I attach a DC blower to intake manifold of my 150CC Yamaha FZS FI engine?

A team managed by my peer is close to melting down

Print "N NE E SE S SW W NW"



Where to add Google tag manager script code for magento2 file path?


Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?Where to add google analytics script code in magento2 file path?Magento2: GA e-commerce moduleAdd JavaScript Tag on severals pages via a Magento custom module + Back Officemagento2: how to add store managerPath of file for Catalog, Manage Products, Add Product - In that Save buttonHow to add the drop-down box in Expired products admin grid in Magento1?Magento2 : Cron script readiness check failedHow to import related products through programmatically in magento2?Where to add google analytics script code in magento2 file path?How to add bing script code for adding bing search engine to my magento2 website then where to add that script code in Magento2?How to add third-party script code into our magento2 for Website trackingMagento 2 -Google Tag Manager Enhanced E-commerce Tracking?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















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?










share|improve this question






















  • check this stack, it will help you magento.stackexchange.com/questions/242278/…

    – Korbin
    Sep 24 '18 at 6:27











  • You can install this module github.com/magepal/magento2-google-tag-manager

    – Ansar Husain
    Sep 24 '18 at 6:49

















2















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?










share|improve this question






















  • check this stack, it will help you magento.stackexchange.com/questions/242278/…

    – Korbin
    Sep 24 '18 at 6:27











  • You can install this module github.com/magepal/magento2-google-tag-manager

    – Ansar Husain
    Sep 24 '18 at 6:49













2












2








2








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?










share|improve this 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?







admin magento2.2.4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 24 '18 at 5:29









Dileep KumarDileep Kumar

1238




1238












  • check this stack, it will help you magento.stackexchange.com/questions/242278/…

    – Korbin
    Sep 24 '18 at 6:27











  • You can install this module github.com/magepal/magento2-google-tag-manager

    – Ansar Husain
    Sep 24 '18 at 6:49

















  • check this stack, it will help you magento.stackexchange.com/questions/242278/…

    – Korbin
    Sep 24 '18 at 6:27











  • You can install this module github.com/magepal/magento2-google-tag-manager

    – Ansar Husain
    Sep 24 '18 at 6:49
















check this stack, it will help you magento.stackexchange.com/questions/242278/…

– Korbin
Sep 24 '18 at 6:27





check this stack, it will help you magento.stackexchange.com/questions/242278/…

– Korbin
Sep 24 '18 at 6:27













You can install this module github.com/magepal/magento2-google-tag-manager

– Ansar Husain
Sep 24 '18 at 6:49





You can install this module github.com/magepal/magento2-google-tag-manager

– Ansar Husain
Sep 24 '18 at 6:49










2 Answers
2






active

oldest

votes


















3














Out of the box functionality of GTM in Magento 2 is very limited. You can do basic installation with GTM but GTM is all about data layers because without them there is very little you can do. Strongly recommend to have read through the following links -:



Full overview of data layers required to implement Enhanced Ecommerce Tracking via GTM -:



https://developers.google.com/tag-manager/enhanced-ecommerce



Read through this article which give you more in-depth details about data layers -:



Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?



Implementing basic GTM functionality, create a simple module -:



Block Class -:



/**
* Google Tag Manager block
*/
namespace CustomGoogleTagManagerBlock;

class Gtm extends MagentoFrameworkViewElementTemplate


/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
array $data = []
)
parent::__construct($context, $data);




Layout xml -:



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="CustomGoogleTagManagerBlockGtm" name="google_tag_manager" as="google_tag_manager" template="gtm.phtml"/>
</referenceContainer>
<referenceContainer name="head.additional">
<block class="CustomGoogleTagManagerBlockGtm" name="google_tag_manager_ns" as="google_tag_manager_ns" template="gtmns.phtml"/>
</referenceContainer>
</body>
</page>


template files -:



gtm.phtml



<!-- Google Tag Manager Start -->
<script>(function(w,d,s,l,i)w[l]=w[l])(window,document,'script','dataLayer','GTM-QWAXXX');</script>
<!-- Google Tag Manager End-->


gtmns.phtml



<!-- Google Tag Manager Start-->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-QWAXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- Google Tag Manager End -->


You could also use M1 or M2 GTM extensions which will have everything you need in terms of data layer and can implement all sort of tracking (FB, GA, Dynamic Remarketing, Twitter, Pinterest and many more)



M2 GTM Pro Extension



M1 GTM Pro Extension



Hope you have all the ammunition to fight with your GTM problem. Best of luck!






share|improve this answer
































    2














    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="MagentoFrameworkViewElementTemplate" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
    </referenceContainer>
    <referenceContainer name="after.body.start">
    <block class="MagentoFrameworkViewElementTemplate" 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.






    share|improve this answer

























    • Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

      – Dileep Kumar
      Sep 24 '18 at 6:07











    • @ Dileep Kumar are you using porto theme?

      – Chintan Kaneriya
      Sep 24 '18 at 6:15











    • You can create new files in the mentioned path

      – Evince Development
      Sep 24 '18 at 6:20











    • Hi @ Evince Development, Could you please help me?

      – Dileep Kumar
      Sep 24 '18 at 6:26











    • Hi @ Chintan Kaneriya, I am using Porto theme.

      – Dileep Kumar
      Sep 24 '18 at 6:29











    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243417%2fwhere-to-add-google-tag-manager-script-code-for-magento2-file-path%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Out of the box functionality of GTM in Magento 2 is very limited. You can do basic installation with GTM but GTM is all about data layers because without them there is very little you can do. Strongly recommend to have read through the following links -:



    Full overview of data layers required to implement Enhanced Ecommerce Tracking via GTM -:



    https://developers.google.com/tag-manager/enhanced-ecommerce



    Read through this article which give you more in-depth details about data layers -:



    Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?



    Implementing basic GTM functionality, create a simple module -:



    Block Class -:



    /**
    * Google Tag Manager block
    */
    namespace CustomGoogleTagManagerBlock;

    class Gtm extends MagentoFrameworkViewElementTemplate


    /**
    * @param MagentoFrameworkViewElementTemplateContext $context
    * @param array $data
    */
    public function __construct(
    MagentoFrameworkViewElementTemplateContext $context,
    array $data = []
    )
    parent::__construct($context, $data);




    Layout xml -:



    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="CustomGoogleTagManagerBlockGtm" name="google_tag_manager" as="google_tag_manager" template="gtm.phtml"/>
    </referenceContainer>
    <referenceContainer name="head.additional">
    <block class="CustomGoogleTagManagerBlockGtm" name="google_tag_manager_ns" as="google_tag_manager_ns" template="gtmns.phtml"/>
    </referenceContainer>
    </body>
    </page>


    template files -:



    gtm.phtml



    <!-- Google Tag Manager Start -->
    <script>(function(w,d,s,l,i)w[l]=w[l])(window,document,'script','dataLayer','GTM-QWAXXX');</script>
    <!-- Google Tag Manager End-->


    gtmns.phtml



    <!-- Google Tag Manager Start-->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-QWAXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- Google Tag Manager End -->


    You could also use M1 or M2 GTM extensions which will have everything you need in terms of data layer and can implement all sort of tracking (FB, GA, Dynamic Remarketing, Twitter, Pinterest and many more)



    M2 GTM Pro Extension



    M1 GTM Pro Extension



    Hope you have all the ammunition to fight with your GTM problem. Best of luck!






    share|improve this answer





























      3














      Out of the box functionality of GTM in Magento 2 is very limited. You can do basic installation with GTM but GTM is all about data layers because without them there is very little you can do. Strongly recommend to have read through the following links -:



      Full overview of data layers required to implement Enhanced Ecommerce Tracking via GTM -:



      https://developers.google.com/tag-manager/enhanced-ecommerce



      Read through this article which give you more in-depth details about data layers -:



      Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?



      Implementing basic GTM functionality, create a simple module -:



      Block Class -:



      /**
      * Google Tag Manager block
      */
      namespace CustomGoogleTagManagerBlock;

      class Gtm extends MagentoFrameworkViewElementTemplate


      /**
      * @param MagentoFrameworkViewElementTemplateContext $context
      * @param array $data
      */
      public function __construct(
      MagentoFrameworkViewElementTemplateContext $context,
      array $data = []
      )
      parent::__construct($context, $data);




      Layout xml -:



      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="CustomGoogleTagManagerBlockGtm" name="google_tag_manager" as="google_tag_manager" template="gtm.phtml"/>
      </referenceContainer>
      <referenceContainer name="head.additional">
      <block class="CustomGoogleTagManagerBlockGtm" name="google_tag_manager_ns" as="google_tag_manager_ns" template="gtmns.phtml"/>
      </referenceContainer>
      </body>
      </page>


      template files -:



      gtm.phtml



      <!-- Google Tag Manager Start -->
      <script>(function(w,d,s,l,i)w[l]=w[l])(window,document,'script','dataLayer','GTM-QWAXXX');</script>
      <!-- Google Tag Manager End-->


      gtmns.phtml



      <!-- Google Tag Manager Start-->
      <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-QWAXXX"
      height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
      <!-- Google Tag Manager End -->


      You could also use M1 or M2 GTM extensions which will have everything you need in terms of data layer and can implement all sort of tracking (FB, GA, Dynamic Remarketing, Twitter, Pinterest and many more)



      M2 GTM Pro Extension



      M1 GTM Pro Extension



      Hope you have all the ammunition to fight with your GTM problem. Best of luck!






      share|improve this answer



























        3












        3








        3







        Out of the box functionality of GTM in Magento 2 is very limited. You can do basic installation with GTM but GTM is all about data layers because without them there is very little you can do. Strongly recommend to have read through the following links -:



        Full overview of data layers required to implement Enhanced Ecommerce Tracking via GTM -:



        https://developers.google.com/tag-manager/enhanced-ecommerce



        Read through this article which give you more in-depth details about data layers -:



        Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?



        Implementing basic GTM functionality, create a simple module -:



        Block Class -:



        /**
        * Google Tag Manager block
        */
        namespace CustomGoogleTagManagerBlock;

        class Gtm extends MagentoFrameworkViewElementTemplate


        /**
        * @param MagentoFrameworkViewElementTemplateContext $context
        * @param array $data
        */
        public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        array $data = []
        )
        parent::__construct($context, $data);




        Layout xml -:



        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="CustomGoogleTagManagerBlockGtm" name="google_tag_manager" as="google_tag_manager" template="gtm.phtml"/>
        </referenceContainer>
        <referenceContainer name="head.additional">
        <block class="CustomGoogleTagManagerBlockGtm" name="google_tag_manager_ns" as="google_tag_manager_ns" template="gtmns.phtml"/>
        </referenceContainer>
        </body>
        </page>


        template files -:



        gtm.phtml



        <!-- Google Tag Manager Start -->
        <script>(function(w,d,s,l,i)w[l]=w[l])(window,document,'script','dataLayer','GTM-QWAXXX');</script>
        <!-- Google Tag Manager End-->


        gtmns.phtml



        <!-- Google Tag Manager Start-->
        <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-QWAXXX"
        height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
        <!-- Google Tag Manager End -->


        You could also use M1 or M2 GTM extensions which will have everything you need in terms of data layer and can implement all sort of tracking (FB, GA, Dynamic Remarketing, Twitter, Pinterest and many more)



        M2 GTM Pro Extension



        M1 GTM Pro Extension



        Hope you have all the ammunition to fight with your GTM problem. Best of luck!






        share|improve this answer















        Out of the box functionality of GTM in Magento 2 is very limited. You can do basic installation with GTM but GTM is all about data layers because without them there is very little you can do. Strongly recommend to have read through the following links -:



        Full overview of data layers required to implement Enhanced Ecommerce Tracking via GTM -:



        https://developers.google.com/tag-manager/enhanced-ecommerce



        Read through this article which give you more in-depth details about data layers -:



        Magento 2 -Google Tag Manager Enhanced E-commerce Tracking?



        Implementing basic GTM functionality, create a simple module -:



        Block Class -:



        /**
        * Google Tag Manager block
        */
        namespace CustomGoogleTagManagerBlock;

        class Gtm extends MagentoFrameworkViewElementTemplate


        /**
        * @param MagentoFrameworkViewElementTemplateContext $context
        * @param array $data
        */
        public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        array $data = []
        )
        parent::__construct($context, $data);




        Layout xml -:



        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="CustomGoogleTagManagerBlockGtm" name="google_tag_manager" as="google_tag_manager" template="gtm.phtml"/>
        </referenceContainer>
        <referenceContainer name="head.additional">
        <block class="CustomGoogleTagManagerBlockGtm" name="google_tag_manager_ns" as="google_tag_manager_ns" template="gtmns.phtml"/>
        </referenceContainer>
        </body>
        </page>


        template files -:



        gtm.phtml



        <!-- Google Tag Manager Start -->
        <script>(function(w,d,s,l,i)w[l]=w[l])(window,document,'script','dataLayer','GTM-QWAXXX');</script>
        <!-- Google Tag Manager End-->


        gtmns.phtml



        <!-- Google Tag Manager Start-->
        <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-QWAXXX"
        height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
        <!-- Google Tag Manager End -->


        You could also use M1 or M2 GTM extensions which will have everything you need in terms of data layer and can implement all sort of tracking (FB, GA, Dynamic Remarketing, Twitter, Pinterest and many more)



        M2 GTM Pro Extension



        M1 GTM Pro Extension



        Hope you have all the ammunition to fight with your GTM problem. Best of luck!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered Jun 6 at 4:36









        user2804user2804

        40127




        40127























            2














            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="MagentoFrameworkViewElementTemplate" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
            </referenceContainer>
            <referenceContainer name="after.body.start">
            <block class="MagentoFrameworkViewElementTemplate" 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.






            share|improve this answer

























            • Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:07











            • @ Dileep Kumar are you using porto theme?

              – Chintan Kaneriya
              Sep 24 '18 at 6:15











            • You can create new files in the mentioned path

              – Evince Development
              Sep 24 '18 at 6:20











            • Hi @ Evince Development, Could you please help me?

              – Dileep Kumar
              Sep 24 '18 at 6:26











            • Hi @ Chintan Kaneriya, I am using Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:29















            2














            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="MagentoFrameworkViewElementTemplate" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
            </referenceContainer>
            <referenceContainer name="after.body.start">
            <block class="MagentoFrameworkViewElementTemplate" 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.






            share|improve this answer

























            • Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:07











            • @ Dileep Kumar are you using porto theme?

              – Chintan Kaneriya
              Sep 24 '18 at 6:15











            • You can create new files in the mentioned path

              – Evince Development
              Sep 24 '18 at 6:20











            • Hi @ Evince Development, Could you please help me?

              – Dileep Kumar
              Sep 24 '18 at 6:26











            • Hi @ Chintan Kaneriya, I am using Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:29













            2












            2








            2







            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="MagentoFrameworkViewElementTemplate" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
            </referenceContainer>
            <referenceContainer name="after.body.start">
            <block class="MagentoFrameworkViewElementTemplate" 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.






            share|improve this 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="MagentoFrameworkViewElementTemplate" name="gtm.head" before="-" template="Magento_Theme::html/gtm_head.phtml" />
            </referenceContainer>
            <referenceContainer name="after.body.start">
            <block class="MagentoFrameworkViewElementTemplate" 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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 24 '18 at 6:06

























            answered Sep 24 '18 at 5:56









            Evince DevelopmentEvince Development

            1,137419




            1,137419












            • Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:07











            • @ Dileep Kumar are you using porto theme?

              – Chintan Kaneriya
              Sep 24 '18 at 6:15











            • You can create new files in the mentioned path

              – Evince Development
              Sep 24 '18 at 6:20











            • Hi @ Evince Development, Could you please help me?

              – Dileep Kumar
              Sep 24 '18 at 6:26











            • Hi @ Chintan Kaneriya, I am using Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:29

















            • Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:07











            • @ Dileep Kumar are you using porto theme?

              – Chintan Kaneriya
              Sep 24 '18 at 6:15











            • You can create new files in the mentioned path

              – Evince Development
              Sep 24 '18 at 6:20











            • Hi @ Evince Development, Could you please help me?

              – Dileep Kumar
              Sep 24 '18 at 6:26











            • Hi @ Chintan Kaneriya, I am using Porto theme.

              – Dileep Kumar
              Sep 24 '18 at 6:29
















            Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

            – Dileep Kumar
            Sep 24 '18 at 6:07





            Hi @ Evince Development, I don't have the gtm_head.phtml file in Porto theme.

            – Dileep Kumar
            Sep 24 '18 at 6:07













            @ Dileep Kumar are you using porto theme?

            – Chintan Kaneriya
            Sep 24 '18 at 6:15





            @ Dileep Kumar are you using porto theme?

            – Chintan Kaneriya
            Sep 24 '18 at 6:15













            You can create new files in the mentioned path

            – Evince Development
            Sep 24 '18 at 6:20





            You can create new files in the mentioned path

            – Evince Development
            Sep 24 '18 at 6:20













            Hi @ Evince Development, Could you please help me?

            – Dileep Kumar
            Sep 24 '18 at 6:26





            Hi @ Evince Development, Could you please help me?

            – Dileep Kumar
            Sep 24 '18 at 6:26













            Hi @ Chintan Kaneriya, I am using Porto theme.

            – Dileep Kumar
            Sep 24 '18 at 6:29





            Hi @ Chintan Kaneriya, I am using Porto theme.

            – Dileep Kumar
            Sep 24 '18 at 6:29

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243417%2fwhere-to-add-google-tag-manager-script-code-for-magento2-file-path%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림