Prepare Your GTM Code
You should receive two GTM code snippets from Google:
- One for the <head> section
- One for immediately after the opening <body> tag
Example GTM Code:
Note:
- If you use a child theme, make edits there to prevent overwriting during theme updates.
Paste this code as high in the <head> of the page as possible:
<!-- 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-NRLSB6Z');</script>
<!-- End Google Tag Manager -->
The <head> tag would be found in the header.php file.
Paste this code immediately after the opening <body> tag:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NRLSB6Z"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
The <body> tag can also be found in the header.php file.
Sometimes, if the theme is heavily customized, the opening tag could be inside specific templates like:
- page.php (for pages)
- single.php (for posts)
- archive.php (for archive pages)
Verify the connection is working
- Push you changes
- Open your website in a new tab
- Use the Tag Assistant to verify the GTM tag is firing correctly
