How to Get Google Analytics 4 Tracking Code
Getting your Google Analytics 4 tracking code installed correctly is the first step toward understanding your website's traffic. While it might sound technical, finding and adding the code is a straightforward process. This guide will walk you through exactly where to find your GA4 Measurement ID and the full tracking snippet, and then show you the best ways to add it to your site.
What Exactly is the GA4 Tracking Code?
In the older version of Google Analytics (Universal Analytics), you were given a "Tracking ID" that started with "UA-" and a chunk of JavaScript code called analytics.js. With Google Analytics 4, things are a bit different and more streamlined. You'll primarily deal with two key components:
- Measurement ID: This is your unique identifier for a specific set of data, called a "data stream" (like your website or app). It starts with "G-" followed by a string of characters (e.g., G-123XYZ456). In most cases, this is the only piece of information you'll need, especially when using a third-party plugin or integration on platforms like WordPress or Shopify.
- Google Tag (gtag.js): This is the actual JavaScript library that sends data from your website to Google Analytics. It's a snippet of code that you install on your site. The Google Tag is now the recommended way to handle tracking not just for GA4 but also for Google Ads, centralizing all your Google tracking in one place. Your Measurement ID tells this code snippet where to send the data.
Think of it like this: the Google Tag (gtag.js) is the mail truck, and your Measurement ID is the unique address of the post office (your GA4 property) where the mail truck needs to deliver the parcels of data.
How to Find Your GA4 Tracking Code (Step-by-Step)
If you have an existing GA4 property, finding your Measurement ID and tag snippet takes less than a minute. Here’s exactly how to do it.
Step 1: Log in to Google Analytics
First, head over to analytics.google.com and sign in with the Google account associated with your property.
Step 2: Navigate to the Admin Section
Once you're logged in, look for the gear icon labeled "Admin" in the bottom-left corner of your screen. Click on it to go to the administration settings.
Step 3: Select the Right Account and Property
The Admin page has two main columns: "Account" and "Property." Make sure you have the correct account and property selected. If you manage multiple websites, it’s easy to get them mixed up, so double-check that the name under the "Property" column matches the website you want to track.
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 4: Click on 'Data Streams'
In the "Property" column, look for the "Data collection and modification" section and click on "Data Streams." A data stream is simply a source of data flowing into your GA4 property, like your website or a mobile app.
Step 5: Select Your Web Data Stream
You'll see a list of your data streams. For a website, you will have one or more web streams listed. Click on the one that corresponds to your website's URL.
Step 6: Copy Your Measurement ID
This is it! The next page shows the details of your web stream. On the top right, you'll see your "Measurement ID," which, as mentioned, begins with "G-". Click the copy icon next to it to copy it to your clipboard. This is the ID you'll use for most simple installations.
For finding the full code snippet, continue to the next part.
Finding the Full Google Tag (gtag.js) Snippet
If you need to install the code manually on a custom website, you'll need the full gtag.js script. From the same "Web stream details" page where you found your Measurement ID:
- Scroll down and find the section titled "Google tag". Click on "View tag instructions".
- A new tab or window might open showing the installation instructions for your Google Tag. If no existing tag is on your site, you’ll be prompted to install a new one. Click the "Install manually" tab.
- Here, you will find the complete JavaScript code snippet. This is what you need to copy and paste into your website's code.
It will look something like this:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-123XYZ456"></script>
<script>
window.dataLayer = window.dataLayer || [],
function gtag(){dataLayer.push(arguments),}
gtag('js', new Date()),
gtag('config', 'G-123XYZ456'),
</script>Just click the copy icon and you're ready to add it to your site.
3 Ways to Add the GA4 Tracking Code to Your Website
Now that you have your Measurement ID and/or the full Google Tag snippet, it's time to put it on your website. Where you add it depends on your website platform and your comfort level with code. Here are the three most common methods.
Method 1: Use a Plugin or Built-in Integration (The Easiest Way)
Most popular website builders and Content Management Systems (CMS) make this process incredibly simple. You won't even need to touch any code - you just need your "G-" Measurement ID that you copied earlier.
- WordPress: The easiest way is to use a plugin. The official Google Site Kit plugin connects your WordPress site to Analytics, Search Console, and other Google services with a few clicks. Alternatively, many SEO and performance plugins like Yoast SEO or Rank Math, as well as "Header and Footer" plugins, have a dedicated field for your Google Analytics ID. You simply paste your "G-" ID and save.
- Shopify: Go to your Shopify admin, navigate to Online Store > Preferences. You'll find a section for "Google Analytics." Paste your "G-" Measurement ID into the box and click save. Shopify takes care of the rest.
- Wix: In your Site's Dashboard, go to Marketing & SEO > Marketing Integrations. Under Google Analytics, click "Connect," and follow the prompts to paste your "G-" Measurement ID.
- Squarespace: Go to your dashboard and navigate to Settings > Advanced > External API Keys. In the "Google Analytics" field, paste your "G-" Measurement ID.
Method 2: Use Google Tag Manager (The Best Practice for Marketers)
If you plan on doing more advanced tracking in the future - like tracking button clicks, form submissions, or video views - using Google Tag Manager (GTM) from the start is highly recommended. It acts as a container for all your tracking scripts, keeping your website’s code clean and allowing you to manage everything from one dashboard.
Here’s the high-level workflow:
- Create a Google Tag Manager account and container. If you don't already have one, go to tagmanager.google.com to create an account for your business and a container for your website.
- Install the GTM snippet on your site. GTM will give you two small pieces of code. These need to be placed high in the
<head>of your site's HTML and immediately after the opening<body>tag. If you're on WordPress, plugins like "GTM4WP" make this easy. - Create the GA4 Configuration Tag in GTM. Inside your GTM container, create a new tag. Choose the "Google Analytics: GA4 Configuration" tag type.
- Enter your Measurement ID. In the tag configuration, there will be a field for "Measurement ID." Paste the "G-" ID you copied from GA4 here.
- Set the Trigger. For the tag to fire, you need to add a trigger. Choose the default "All Pages" trigger to make the GA4 tag load on every page of your website.
- Preview, Test, and Publish. Use GTM’s Preview mode to test that the tag is firing correctly on your live site. Once confirmed, click "Submit" to publish your container and push the changes live.
This method seems like more work initially, but it saves immense time and effort down the line.
Method 3: Install the Code Manually in HTML (For Custom Sites)
This method involves directly editing your website's source code. It's best suited for custom-built websites or situations where a plugin or GTM isn't an option.
- Copy the entire Google Tag (gtag.js) snippet we found earlier.
- Access your website's HTML files. You need to find a file that controls the header section of your entire website. In a classic WordPress theme, this might be
header.php. In other systems, it could be a "layout" or "template" file. - Paste the copied code snippet immediately after the opening
<head>tag. By placing it high in the head, you ensure it loads as quickly as possible for accurate tracking. - Save the file and upload it to your server.
Warning: Be careful when editing theme files directly. A stray character can break your website. It's always best practice to create a backup or use a child theme before making direct code edits.
How to Verify Your GA4 Installation is Working
Don't just assume the tracking is working. Always verify! There's nothing worse than launching a marketing campaign and realizing a week later that none of your data was recorded. Here are three simple ways to check:
1. Use the Realtime Report in GA4
This is the quickest and easiest way. In your Google Analytics property, navigate to Reports > Realtime. Then, open your website in a new tab or on your phone. Within a minute or two, you should see yourself as an active user recorded in the "Users in Last 30 Minutes" section of the Realtime report.
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. Use the Google Tag Assistant Chrome Extension
The Tag Assistant Companion by Google is a browser extension that shows you which Google tags (including Analytics, GTM, and Google Ads) are firing on a page. Install the extension, navigate to your website, enable it, and reload the page. It will show you if your GA4 tag has been found and if it fired successfully.
3. Use Browser Developer Tools
For a more technical check, you can use your browser's built-in developer tools. Right-click on your webpage, select "Inspect," and go to the "Network" tab. In the filter box, type collect. Now refresh your page. You should see a request being sent to google-analytics.com. If you see this row appear with a "200" or "204" status code, it means your browser has successfully sent tracking information to Google's servers.
Final Thoughts
And that's it! Finding your GA4 Measurement ID and full GA4 tracking code is a simple matter of navigating to the Admin settings and finding your data stream. Once you have it, you can choose the best installation method for your website, whether it’s a quick plugin setup, a robust Google Tag Manager implementation, or a manual code placement.
Once your tracking is set up and data is beginning to flow into Google Analytics, the next challenge is turning that raw data into meaningful insights without getting lost in GA4’s complex interface. We built Graphed to solve exactly this problem. You can connect your Google Analytics account in seconds and start asking questions in plain English - like "Which landing pages get the most traffic?" or "Show me a comparison of last month's revenue by channel" - and get instant dashboards and answers, freeing you up to act on your data instead of just searching for it.
Related Articles
Facebook Ads for Wedding Planners: The Complete 2026 Strategy Guide
Learn how to use Facebook ads to book more wedding planning clients in 2026. Complete guide covering targeting, budgets, retargeting, and conversion strategies.
Facebook Ads for Bands: The Complete 2026 Strategy Guide
Learn how to use Facebook Ads to promote your band in 2026. This comprehensive guide covers audience targeting, budget strategies, creative tips, and measurement techniques specifically for musicians.
YouTube Ads for Small Businesses: The Complete Guide for 2026
Learn how small businesses can leverage YouTube ads to reach their ideal customers, build brand awareness, and drive conversions in 2026. This comprehensive guide covers setup, targeting, budgeting, and optimization strategies.