Google Tag Manager | How do I install the GTM container on my website?
Introduction & Purpose
Google Tag Manager container snippets are small pieces of JavaScript and non-JavaScript code that you paste into the HTML of any page you wish to track. These code snippets enable Tag Manager to fire tags by inserting gtm.js into the page (or through the use of an iframe when JavaScript isn't available).
The purpose of this article is to demonstrate the correct way to place GTM snippets for tracking user interactions with a web page.
Difficulty:
Developer required to update HTML.
Prerequisite Requirements
- GTM Container Created and Published
- Ability to edit the HTML of the page you wish to track<
Implementation
- Open your GTM container and click the Admin tab
- Under the 'CONTAINER' column, click 'Install Google Tag Manager'
- Copy and paste the provided snippets where instructed (<head> or <body>), for every page you wish to track.
Validation
After updating HTML with code snippets from GTM, open the browser to the page and right-click > inspect the page to reveal HTML.
<head>
Search the HTML for your container ID (GTM-XXXXXXX). One of the results should be the <head> code snippet provided by Google Tag Manager in the previous steps.
Ensure that the snippet provide by GTM is unmodified and entirely under the <head> tag, not the <body>.
Incorrect placement example -
<body>
Search the HTML for your container ID (GTM-XXXXXXX). One of the results should be the <body> code snippet provided by Google Tag Manager in the previous steps.
Ensure that the snippet provide by GTM is unmodified and entirely under the <body> tag, not the <head>.
Network Validation
- Open the network tab from any page you wish to validate: right-click > Network tab
- Input into the search: "gtm.js"
- Ensure that the network request is logged and the Status is 200 (Success).
This validates that the page has been tagged correctly and is sending data to Google Analytics.