Google Tag Manager is a free tag management system from Google. It can be used to manage JavaScript and HTML tags that are needed for tracking and analyzing websites. Code snippets, such as the Facebook pixel, can be integrated on the website with the help of Google Tag Manager without having to edit the source code directly. This also makes it easy to set up Google Analytics.
Integrate Google Tag Manager correctly
The code of the Google Tag Manager must be integrated with the appropriate container ID (GTM-XXXXXX) in the source code of your website as follows.
Add this code as high as possible in the <head> section of your page:
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXX');</script> <!-- End Google Tag Manager -->
Also, add this code directly after the opening <body>-tag:
<!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->