Where Does Google Analytics Tag Go?
Placing your Google Analytics tag is one of the first and most critical steps in understanding your website's traffic, but it can be confusing knowing exactly where it's supposed to live. The short answer is: the Google Analytics tag goes inside the <head> section of your website’s HTML, as high up as possible. This article will walk you through exactly how to find your tag, why it goes there, and the best ways to install it on popular platforms like WordPress and Shopify.
What is the Google Analytics Tag (and Why Does Location Matter)?
The Google Analytics tag is a small snippet of JavaScript code. Its job is to activate tracking on your website. When a visitor lands on one of your pages, this script executes in their browser, collects anonymous information about their session (like which page they're on, what device they're using, and how they got there), and sends it over to your Google Analytics account.
The placement of this tag is important for one reason: speed. By placing the code within the <head>, section, you ensure it’s one of the first things to load when an internet browser renders your page. If you placed it at the bottom of the page (in the footer), a visitor might click a link and leave your site before the script has a chance to run. That would result in a missed session, leading to inaccurate data.
Today, Google Analytics 4 uses a single, consolidated script known as the Google tag (gtag.js). This streamlined approach makes it easier to manage tracking for Google’s entire suite of products, including Google Ads, from one central piece of code.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step 1: Find Your GA4 Google Tag Snippet
Before you can install the tag, you need to find it. This code is unique to your specific "data stream" - the source of data for your GA4 property (in this case, your website).
Here’s how to locate your snippet:
- Log into your Google Analytics account.
- Click the Admin icon (the gear in the bottom-left corner).
- In the Property column, make sure your desired GA4 property is selected.
- Click on Data Streams.
- Select the Web stream that corresponds to your website. If you don't have one, you'll need to create one first.
- At the bottom, under "View tag instructions," click Install manually.
You’ll now see a screen with your JavaScript code snippet. It will look something like this, with your unique "G-" Measurement ID:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [],
function gtag(){dataLayer.push(arguments),}
gtag('js', new Date()),
gtag('config', 'G-XXXXXXXXXX'),
</script>This is the code you will be adding to your website. Simply click the icon to copy it to your clipboard.
Step 2: Install the Google Analytics Tag on Your Website
The method you use to install the code depends entirely on the platform your website is built on. Let's cover the most common scenarios.
Method 1: For a Simple HTML Website (Manual Installation)
If you have a static website built with plain HTML files and have direct access to the code, this method is for you.
- Using an FTP client or your hosting provider's file manager, access your website’s files.
- Open the HTML file for one of your pages (e.g.,
index.html) in a text editor. - Find the closing
</head>tag. It's usually near the top of the file. - Paste your copied Google tag snippet on the line just before the
</head>tag. - Save the file and upload the new version to your server.
Important: You must repeat this process for every single page on your website. To make this easier, most developers use a single "header" or "include" file that gets called on every page. If your site is set up like this, you only need to paste the code once into that central header file.
Method 2: For a WordPress Website
WordPress is the world's most popular content management system, and it offers several easy ways to add the tracking tag without manually editing your theme files every time it updates.
Option 1: The Easy Way (Using a Plugin)
For most WordPress users, a plugin is the safest and simplest method. It protects you from making mistakes in the code and handles placing the script correctly for you.
- Site Kit by Google: This is Google’s official plugin for WordPress. It not only installs your Analytics tag but also connects Search Console, AdSense, and PageSpeed Insights, displaying a handy dashboard right inside WordPress. After installing the plugin, just follow the on-screen prompts to connect your Google account, and it handles the rest.
- WPCode - Insert Headers and Footers: A very popular plugin that creates a dedicated spot to paste code snippets into your header, body, or footer. Install the plugin, navigate to Code Snippets > Header & Footer, and paste your entire Google Tag snippet into the "Header" box. Save your changes, and you're done.
Option 2: The Advanced Way (Editing Your Theme)
If you prefer not to use a plugin, you can add the code directly to your theme's header.php file. Be careful: making a mistake here can break your site. It is also a good idea to use a child theme, as any changes made directly to your parent theme's files will be erased when the theme is updated.
- In your WordPress dashboard, go to Appearance > Theme File Editor.
- On the right side, find and click on the file named Theme Header (
header.php). - Inside the editor, find the closing
</head>tag. - Paste your GA4 tracking code right before it.
- Click Update File.
Method 3: For a Shopify Store
Shopify makes this process incredibly easy with a built-in integration.
- From your Shopify admin, go to Online Store > Preferences.
- Scroll down to the "Google Analytics" section.
- Check the box that says "Use Google Analytics 4."
- All you need is your Measurement ID, not the whole script. In a separate tab, go back to your GA4 Data Stream and copy just the ID that starts with "G-..."
- Paste just the Measurement ID (e.g., G-XXXXXXXXXX) into the box in Shopify.
- Click Save. Shopify will now automatically add the necessary
gtag.jstracking code to all of your store's pages, including the checkout pages.
Method 4: For Other Website Builders (Squarespace, Wix, etc.)
Most modern website builders have a designated area for adding tracking scripts and custom code.
- Squarespace: Go to Settings > Advanced > Code Injection. Paste your full Google Analytics snippet into the box labeled "Header".
- Wix: Navigate to Marketing & SEO > Marketing Integrations. Select Google Analytics and click "Connect." Follow the prompts to add your Measurement ID.
If you use a different platform, look for settings related to "Custom Code," "Integrations," "Tracking Tools," or "Header Scripts" in your website’s admin panel.
Step 3: Verify Your Tag is Working Correctly
Once you’ve added the tag, you need to confirm it’s firing. Here are a few simple ways to check:
1. Use the Realtime Report
This is the most direct method. Open your GA4 property and go to Reports > Realtime. In a separate browser tab, open your website and click around a few pages. Within a minute, you should see yourself appear as a user on the Realtime report map and in the "Users in Last 30 Minutes" count.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
2. View Page Source
This is a quick sanity check. Go to your live homepage, right-click anywhere, and select "View Page Source." Use your browser's find function (Ctrl+F or Cmd+F) to search for gtag.js or your G- Measurement ID. If it appears in the code, you know the script is physically on the page.
3. Use Google's Tag Assistant
For a more advanced check, use the Tag Assistant. This web tool helps you debug and verify your Google tags. Navigate to the website, enter your site's URL, and it will open your site in a new tab in debug mode. As you click around, the Tag Assistant window will show you exactly which tags have fired successfully.
Common Installation Mistakes to Avoid
- Installing Twice: This is a frequent mistake. For instance, a user might add the code via Shopify's native integration and also paste the script into their theme's liquid files. This causes every pageview to be counted twice, artificially inflating your traffic data. Pick one method and stick with it.
- Incorrect Placement: Don't place the script in the
<body>tag or the footer unless you have a very specific technical reason. The head section is the most reliable place for accurate data collection. - Typographical Errors: If you install the code manually, be careful not to accidentally delete a comma, quote, or bracket. Any small change can break the entire script. Always copy and paste the code exactly as provided by Google.
Final Thoughts
Getting your Google Analytics tag in the right spot - just before the closing </head> tag on every page - is the foundation of any good data analysis strategy. Whether you're pasting it directly into your HTML, using a WordPress plugin, or leveraging a built-in Shopify integration, taking a few minutes to do it correctly will save you headaches and guarantee your reports start with accurate data from day one.
Of course, collecting data is just the beginning. The real goal is to turn those numbers into actionable insights without spending all day building reports. At Graphed, we make this simple. Once you connect your Google Analytics account - a process that takes just a few clicks - you can ask for entire dashboards and reports in plain English. Instead of manually constructing reports, try asking, "Show me a comparison of organic vs. social media traffic and conversions over the last quarter." We instantly build the visuals for you, pulling live data so you can focus on analysis, not setup.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.