Properly configuring Google Tag Manager Code can improve the way your website collects data. Many developers and marketers struggle to place code in the correct position. This often results in incomplete data collection and missed opportunities for conversion.
Getting GTM right from the start saves time. It also prevents troubleshooting later. Plus, it ensures that your clients have accurate analytics data for their projects.
Quick Summary
- Google Tag Manager requires two code snippets.
- The first snippet goes inside the
<head>tag. - The second snippet goes immediately after the opening
<body>tag. - This placement ensures accurate tracking and reliable data collection.
What is Google Tag Manager, and how does it work?
Google Tag Manager (GTM) is a free tag management system by Google. It allows website owners to manage tracking scripts without editing code repeatedly.
Google Tag Manager makes it easier to manage tracking codes and marketing tags. You don’t need to rely on developers all the time. GTM simplifies things. It uses a single central container. This means you won’t need separate code snippets for Google Analytics, Google Ads, and more.
Google Tag Manager (GTM) is a free tag management system by Google. It works closely with Google Analytics 4 (GA4), Google Ads, and conversion tracking tools. GTM acts as a central control system for all tracking scripts.
Why Does Correct GTM Code Placement Matter?

Incorrect Google Tag Manager placement causes tracking gaps. These gaps lead to missing user actions. Late-loading containers often miss key events.
- Data loss occurs immediately when tags fire before GTM loads completely.
- Cross-domain tracking fails without proper head section placement.
- Enhanced measurements become unreliable on checkout pages and conversion funnels.
- Campaign Manager and Display & Video 360 integrations break down entirely.
I’ve seen marketing teams make budget choices using incomplete data. In most site audits, incorrect GTM placement is the primary reason tracking fails. They frequently place their GTM container snippets in the wrong location. The fix takes minutes, but the impact lasts for months.
Setting Up Your GTM Account
Setting up Google Tag Manager correctly ensures clean tracking from day one.
Creating a GTM account
Go to the Google Tag Manager site and log in using your Google account. Click “Create Account.” Then, enter your account name, usually your company name, and your website URL.
Select “Web” as your target platform since we’re focusing on website implementation. Google will generate your unique Container ID, which appears in the format GTM-XXXXXXX.
Obtaining Your GTM Container Code
After account creation, GTM displays two code snippets immediately. Place the first snippet in your site’s header HTML. Put the second snippet immediately after the opening <body> tag. Many people mix this up, which can lead to issues.
Copy both snippets exactly as shown. The Container Name appears at the top, but focus on the actual JavaScript code below. Do not include IDs or measurement IDs in these snippets.
Installing GTM on Different Platforms
Different website platforms handle code placement differently, so Google Tag Manager installation steps vary based on your CMS or website builder.
Shopify
Shopify allows direct GTM installation through theme files for full-site tracking.
- Access your Shopify admin panel and navigate to Online Store > Themes.
- Click Actions next to your active theme, then select “Edit Code.”
- Open the theme. Liquid file from the Layout folder.
- Insert the initial GTM code immediately after the opening <head> tag.
- Add the second snippet immediately after <body> opens.
Shopify’s theme files receive updates automatically. Always preview changes before publishing. This helps avoid disrupting your online store.
HubSpot
HubSpot offers built-in Google Tag Manager integration through its tracking code settings. Go to Settings > Tracking & Analytics > Tracking Code.
Enter your Container ID in the Google Tag Manager section. HubSpot places code on all your website pages without requiring manual input. This includes landing pages and blog posts.
WordPress
WordPress supports Google Tag Manager through plugins or manual theme edits. Installing GTM on WordPress relies on either using plugins or manually adding code. For manual installation:
- Edit your active theme’s header.php file through Appearance > Theme Editor.
- Place the first snippet after the <head> tag.
- Add the second snippet after the <body> tag opens.
Popular plugins, like “Google Tag Manager for WordPress,” automate this process. They also offer features for managing scripts.
Where exactly should you place the GTM code?
Google Tag Manager requires two code snippets, and each snippet has a specific placement to ensure accurate and complete tracking.
Placing in the Head Tag
The first Google Tag Manager snippet must be placed immediately after the opening <head> tag. Put it as high as possible, right after the opening tag. This positioning ensures GTM loads before any other tracking codes or third-party scripts.
This placement helps integrate the data layer. It also ensures tags fire at the right times. Many conversion measurement tools rely on early loading to track full user journeys.
Placing it in the body tag

The second GTM snippet must be placed immediately after the opening <body> tag. Don’t put it in the footer, as many tutorials do incorrectly. This placement serves as a fallback for users who have JavaScript disabled.
If your setup is wrong, you might miss data from visitors using accessibility tools or privacy browsers. Every data point counts for better campaign optimization. The impact may seem small, but it is important.
What are GTM integration best practices?
Following standard GTM best practices prevents tracking errors and data inconsistencies. Using established GTM standards helps avoid tracking errors. It also ensures reliable data collection on all your website pages.
- Always test in GTM Preview Mode before publishing container changes.
- Maintain uniformity in the naming of tags, triggers, and variables.
- Document your tag configurations for future team members.
- Proper data layer structure for advanced tracking needs.
Regular audits with Google Tag Assistant spot configuration issues early. This helps protect your marketing data. Schedule monthly reviews to catch problems early.
Common GTM Implementation Mistakes

Misplacing the code
The most common mistake is putting both GTM snippets in the website header or footer. This positioning breaks the intended loading sequence and causes tracking delays.
Some developers add GTM code to individual pages instead of the master template. This approach creates inconsistent tracking and makes updates challenging across large websites.
Duplicate Code Insertion
Adding GTM container snippets multiple times creates conflicting data streams.
This results in inflated metrics and duplicate events. Check your website’s source code at regular intervals. Make sure there is only one set of GTM snippets. Many installations can trigger the same events several times, skewing your analytics data.
How do you verify the GTM installation?
You can verify Google Tag Manager installation using Preview Mode and Google Tag Assistant.
Using GTM Preview Mode
Google Tag Manager’s Preview Mode shows exactly which tags fire on each page load. Enable this feature from your GTM workspace before testing your website pages.
The preview panel displays the tag firing order, trigger activations, and error messages. This immediate feedback allows for the quick identification of placement problems right after installation.
Tag Manager Testing Tools
The Google Tag Assistant Legacy extension provides in-depth GTM checks for your website. Install this Chrome extension. Then, visit your key website pages to find any implementation issues.
The tool shows missing tags, wrong settings, and delays in loading. These issues can affect the quality of your data collection.
Integrating GTM with Google Analytics
Google Tag Manager integrates directly with Google Analytics 4 (GA4) for flexible tracking.
Linking to Your Analytics Account
Connect your Google Analytics 4 property through GTM’s built-in templates. Create a new Google Analytics tag and select your Measurement ID from the drop-down menu.
This integration method is more flexible than a direct GA4 installation. It also allows for advanced event tracking setups.
Setting Up Tags for Analytics
Configure page view tracking, enhanced measurements, and custom events through GTM’s interface. Each tag needs certain triggers. These triggers determine when Google Analytics receives data.
Track conversions for your key business goals. This could be newsletter sign-ups, product purchases, or contact form submissions.
Troubleshooting GTM code issues
If the Google Tag Manager Code isn’t working, check the browser’s developer console for JavaScript errors. These messages often state the source of the problem.
Ensure that your Container ID matches in all code snippets and hasn’t been changed by mistake. Even small typos in tag IDs prevent proper data collection.
Clear your website cache. Then, test using an incognito browser window. This helps rule out caching issues. Many GTM problems stem from outdated cached files rather than actual configuration errors.
If error messages keep showing up, contact your local web development team.
Final Thoughts
Correct Google Tag Manager placement ensures accurate analytics and reliable tracking.
Installing both snippets in the right location prevents data loss and reporting errors.
A well-organized GTM setup enables more informed marketing decisions and fosters long-term growth.
FAQ
You should place the Google Tag Manager code in the header.php file or use a trusted plugin.
The first snippet goes inside the <head> tag.
The second snippet goes after the opening <body> tag.
GTM deploys Google Analytics 4 (GA4) across all pages automatically. Platforms and tools such as Wixpa Google Tag Manager handle this setup centrally, preventing duplicate tracking and improving data consistency.
You can verify Google Tag Manager using Preview Mode or Google Tag Assistant.
Preview Mode shows which tags fire on each page.
Google Tag Assistant detects loading issues, duplicate containers, and configuration errors that affect tracking accuracy.
Google Tag Manager must be placed in both the head and body sections.
The head snippet loads GTM early for accurate page views.
The body snippet acts as a fallback and ensures tracking works even with restricted JavaScript environments.
Yes, Google Tag Manager can be installed manually in WordPress without plugins.
Add the first snippet in the <head> tag and the second after <body>.
Manual installation is safe, lightweight, and avoids plugin conflicts when done correctly.