Where to Add Google Analytics?
Placing your Google Analytics tracking code on your website is the essential first step to understanding how visitors find and interact with your content. This small piece of code is the engine that collects all the valuable data. This guide will show you exactly where to find your code and how to install it correctly, whether you're using a simple HTML site, WordPress, Shopify, or another popular platform.
Understanding the Google Analytics Tracking Code
Before you add the code, it's helpful to know what you’re working with. The Google Analytics 4 tracking code is a JavaScript snippet that you place on your website. When a user visits a page, this script runs in their browser, collecting anonymous data about the visit - like which page they’re on, what country they’re from, and how they got to your site - and sends it to your Google Analytics account.
There are two key pieces you’ll encounter:
Measurement ID: This is a unique identifier for your web data stream, formatted as
G-XXXXXXXXXX. Many plugins and platform integrations will only ask for this ID.Global Site Tag (gtag.js): This is the full JavaScript snippet. It contains your Measurement ID and is the code you'll need if you’re manually adding Analytics to your site's HTML. The tag needs to be on every single page you want to track.
Placing this code correctly is critical. If it’s missing from a page, any visits to that page will be invisible to Google Analytics, leaving you with incomplete and inaccurate data.
Where to Find Your Google Analytics Tag
First things first, you need to grab your tracking code from your Google Analytics account. If you just created your property, Google likely presented you with the code during setup. If not, here’s how to find it anytime:
Log in to your Google Analytics account.
Click on Admin in the bottom-left corner (the gear icon).
Ensure the correct Account and Property are selected. In the Property column, click on Data Streams.
Click on the specific web data stream for your website.
Your Measurement ID (e.g., G-R7XXXXXX1X) will be visible in the top-right corner. You can copy it directly from here if that's all your plugin or integration needs.
For the full code snippet, look for the View tag instructions button. Under the Install manually tab, you'll find the full Global Site Tag (gtag.js) snippet ready to be copied.
Keep this tab open, as you'll be copying either the ID or the full snippet in the next steps.
Method 1: Add Google Analytics to a Basic HTML Website
If your website is built with plain HTML, you’ll need to add the tracking code manually. The rule of thumb is straightforward: the tracking code should be placed just before the closing </head> tag in your HTML file.
Here’s why: Placing the script in the <head> section ensures it loads as early as possible. This allows Analytics to capture visit data accurately, even if a user clicks away before the page fully loads. If placed at the bottom of the page (before the </body> tag), you risk missing visitors who leave quickly.
Step-by-step instructions:
Copy the entire Global Site Tag (gtag.js) snippet from your GA4 data stream settings.
Open the HTML file for one of your website pages in a text editor.
Paste the code snippet immediately before the closing
</head>tag.
Your code should look something like this:
You must repeat this process for every single page on your website. If you use a templating system or "include" files for your header, you can simply add the code to your universal header template once, and it will automatically appear across your whole site.
Method 2: Use Google Tag Manager (The Recommended Method)
While manual installation works, the modern and more flexible approach is to use Google Tag Manager (GTM). GTM acts as a middleman or a "container" for all your tracking scripts (like Google Analytics, Facebook Pixel, Google Ads conversion tracking, etc.).
The beauty of GTM is that you install its code on your site once. After that, you can add, remove, and manage all of your other tracking tags from the GTM interface without ever touching your website's code again.
Step-by-step instructions:
Set up GTM: Go to the Google Tag Manager website and create a free account and container for your website. GTM will give you two code snippets.
Install GTM on your site: Follow the instructions GTM provides. You'll place the first snippet in the
<head>of your website's HTML and the second snippet immediately after the opening<body>tag. This is the only time you'll need to edit your site code.Create the GA4 Tag:
Inside your GTM container, go to Tags > New.
Give your tag a clear name, like "GA4 - Pageviews".
Click Tag Configuration and choose Google Analytics: GA4 Configuration.
In the Measurement ID field, paste your
G-XXXXXXXXXXMeasurement ID from your GA4 account.
Set the Trigger: Click on Triggering and select the All Pages trigger. This tells GTM to fire the GA4 tag on every page view.
Save and Publish: Save your tag. Click the Submit button in the top-right of your GTM dashboard to publish your changes live.
Now, GTM is handling your GA4 tracking, and you have a powerful system in place to manage future tracking needs.
Method 3: Adding Google Analytics to Popular Platforms
Most modern content management systems (CMS) and ecommerce platforms have simplified the process down to just copying and pasting your Measurement ID into a settings field.
WordPress
You have two primary options for adding Google Analytics to a WordPress site.
Using a Plugin (Easiest Method)
This is the best route for most users. Plugins handle the code placement for you and often come with extra features like dashboard reports inside WordPress. Popular options include MonsterInsights, Site Kit by Google, or GA Google Analytics.
Steps:
From your WordPress dashboard, navigate to Plugins > Add New.
Search for your chosen analytics plugin and click Install Now, followed by Activate.
Follow the plugin's setup instructions. Typically, this involves navigating to the plugin's settings page and pasting your Measurement ID into a designated field.
Editing Theme Files (Advanced)
If you're comfortable editing code and want to avoid adding another plugin, you can add the gtag.js snippet directly to your theme's header.php file. Warning: Always use a child theme when making code changes. Editing the parent theme directly can cause your changes to be overwritten during a theme update.
Steps:
Go to Appearance > Theme File Editor.
From the list of theme files on the right, select
header.php.Paste your copied Global Site Tag (gtag.js) snippet just before the closing
</head>tag.Click Update File.
Shopify
Shopify has a built-in integration that makes adding GA4 simple and ensures ecommerce events are tracked correctly.
Steps:
From your Shopify Admin dashboard, go to Online Store > Preferences.
Scroll down to the Google Analytics section.
Click Manage pixel here.
Click on Connect your Google account and follow the authentication flow to connect the account that has Admin access to your GA4 property.
Shopify will automatically detect and list your G- Measurement ID. Select it and click Connect.
Wix and Squarespace
These platforms also simplify the process with dedicated marketing integrations.
For Wix:Go to your site dashboard, navigate to Marketing & SEO > Marketing Integrations. Find Google Analytics and click Connect. Paste your Measurement ID when prompted.
For Squarespace:Go to Settings > Advanced > Code Injection. Paste your entire Global Site Tag (gtag.js) code snippet into the Header section. This automatically adds it to every page on your site.
How to Verify Your Installation is Working
Don't just assume your code is working. Always verify it to ensure you're collecting data properly. Here are a few ways to check:
1. Use the Realtime Reports
This is the quickest and easiest way.Open your Google Analytics account and navigate to Reports > Realtime. Then, in a separate browser tab, open your own website. Within a minute, you should see your visit appear on the Realtime report map and in the charts. If you see yourself, it's working!
2. Use Google Tag Assistant
More technical but very powerful. Install the Tag Assistant Companion browser extension for Chrome. When you navigate to your site, you can use the extension or GAA's built-in "DebugView" to see exactly which tags are firing and whether any errors are occurring.
3. "View Page Source"
A simple manual check. Right-click on your live webpage and select "View Page Source." Use your browser's find function (Ctrl+F or Cmd+F) to search for gtag.js or your G-XXXXXXXXXX Measurement ID. If you find the snippet in the code, it's been installed.
Final Thoughts
Installing your Google Analytics tracking code is a foundational step, but it's simpler than it sounds. Whether you paste the code manually into your site's header, use a simple plugin on your CMS, or manage it through Google Tag Manager, the key is ensuring that snippet is present on every page to capture a complete picture of your visitor traffic.
Of course, collecting data is just the beginning. The next, often harder, step is turning that raw data into actionable insights. Instead of spending hours digging through reports and trying to connect the dots, we built Graphed to be your AI data analyst. You can connect your Google Analytics account once, and then use plain English to ask for the charts, dashboards, and answers you need, turning complex data into clear actions in seconds.