How to Get Google Analytics 4 Code
Finding your Google Analytics 4 tracking code is a quick task, but navigating the new interface can be confusing if you don't know exactly where to click. This guide will show you exactly how to locate both your GA4 Measurement ID and the full global site tag script (gtag.js). We’ll cover how to find the code in an existing property and what to do if you need to create a new one first.
First, Understand Your GA4 "Code"
Before you start digging through menus, it's helpful to know what you're looking for. With Google Analytics 4, you'll encounter two primary identifiers, often used interchangeably but serving different purposes.
1. Your Measurement ID
The Measurement ID is a unique identifier for your data stream (e.g., your website). It follows the format G-XXXXXXXXXX. This ID is what you'll typically use when setting up GA4 through a platform integration or a tool like Google Tag Manager. It tells Google which data stream to send the collected data to.
2. The Global Site Tag (gtag.js)
The Global Site Tag is the full JavaScript code snippet that you install directly on your website. It contains your Measurement ID and is the engine that collects data and sends it to Google Analytics. You only need this full script if you plan on adding the GA4 tracking code directly into your website's HTML.
Here’s an example of what it looks like:
<!-- 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>Most of the time, especially when using plugins or services like Shopify or Squarespace, you will only need your Measurement ID.
How to Find Your GA4 Code in an Existing Property
If you've already set up a GA4 property, finding your code is just a matter of a few clicks. Follow these steps to locate your Measurement ID and the global site tag.
Step 1: Go to the Admin Section
Log in to your Google Analytics account. Once in, look for the gear icon in the bottom-left corner of the screen and click on Admin.
Step 2: Select Your Property and Data Stream
The Admin page is divided into two columns: Account and Property. Make sure the correct Account and GA4 Property are selected in the dropdown menus.
In the Property column, look for the Data Streams option and click on it. A data stream is simply a source of data, like your website or mobile app.
Step 3: Open Your Web Stream Details
On the Data Streams screen, you'll see a list of the data streams you've created. Most businesses will only have one for their website. Click on the web stream you need the code for.
Step 4: Locate Your Measurement ID and Tag Instructions
This is it! On the Web stream details page, your Measurement ID (G-XXXXXXXXXX) is prominently displayed in the top-right corner. You can click the copy icon next to it to easily grab it.
To find the full Global Site Tag (gtag.js), look for the heading Tagging instructions at the bottom of the page and click on View tag instructions.
A new panel will open. Under the Install manually tab, you'll find the complete JavaScript snippet. You can copy this entire block of code to paste into your website's HTML.
What If You Don't Have a GA4 Property?
If you're completely new to GA4 or are migrating from the old Universal Analytics, you'll need to create a property and a data stream first. Here's how to do that quickly.
Creating a New GA4 Property
- Go to the Admin section of Google Analytics.
- In the Property column, click the blue + Create Property button.
- Enter a name for your property (e.g., "My Business Website"), select your reporting time zone and currency, then click Next.
- Answer the optional business information questions and click Create.
Creating a New Data Stream
Immediately after creating a property, Google will prompt you to "Choose a platform" to start collecting data. This is where you create your data stream.
- Select Web as your platform.
- Enter your website's URL (e.g., www.mybusiness.com) and give the stream a name (e.g., "My Business Website Stream").
- Ensure "Enhanced measurement" is turned on. This automatically tracks common user interactions like page views, scrolls, and outbound clicks.
- Click the Create stream button.
Once you click "Create stream," you will be taken directly to the Web stream details page described in the previous section, where you can find your Measurement ID and Global Site Tag.
Where Do You Put the GA4 Code?
Now that you have your GA4 code, the final step is to add it to your website. There are three common ways to do this, depending on your technical comfort level and how your website is built.
Method 1: Manually Paste the Code into HTML (Direct Method)
This involves editing your website's source code. You'll need the full Global Site Tag (gtag.js) snippet for this.
- How it works: Copy the entire JavaScript snippet. You need to paste this code immediately after the opening
<head>tag on every single page of your website. - Who is it for? This is a good option for simple, static websites or for developers who have direct access to theme files. If your site uses a template or "include" file for the header, you only need to add it there once.
- Pros: Quick and straightforward for simple sites.
- Cons: Can be difficult for beginners, requires editing code, and can be overwritten if you update your website's theme.
Method 2: Use Google Tag Manager (Recommended)
Google Tag Manager (GTM) is a free tool that acts as a container for all your marketing and analytics tags. It's the most flexible and robust method.
- How it works: Instead of adding the GA4 code to your site, you add the GTM code. Then, within the GTM interface, you create a new tag. You'll choose the "Google Analytics: GA4 Configuration" tag type and simply paste your Measurement ID (G-XXXXXXXXXX) into the field.
- Who is it for? Everyone. It's the industry-standard way to manage tags because it prevents you from ever having to edit your website's code to add new tracking scripts in the future.
- Pros: Highly flexible, powerful, easier to manage multiple tags (e.g., Meta Pixel, Google Ads), keeps a history of changes.
- Cons: Has a slight learning curve at the very beginning.
Method 3: Use a CMS Plugin or Integration
Most modern content management systems (CMS) and e-commerce platforms have a built-in field or recommended plugin for adding your tracking ID.
- How it works: Find the analytics integration section within your platform's settings. It will typically have a field labeled "Google Analytics ID" or similar. All you have to do is paste your Measurement ID into that field and save.
- Who is it for? Users of platforms like Shopify, Squarespace, Wix, or WordPress. For WordPress, popular plugins like Site Kit by Google or MonsterInsights make this incredibly easy.
- Pros: Easiest method, no code to worry about.
- Cons: Less flexible than GTM, might not support advanced tracking without additional configuration.
How to Verify Your GA4 Installation
After you've added the code, you'll want to make sure it's working. Don't worry, you don't have to wait 24 hours to see if data is coming in.
The best way to check is with the Realtime report in GA4.
- In your GA4 Property, navigate to Reports > Realtime.
- Open your website in a new browser tab or on your phone.
- Within a minute or two, you should see yourself as a user in the Realtime report map.
If you see activity, congratulations! You have successfully installed your GA4 tracking code and are now collecting data.
Final Thoughts
Getting your GA4 code is a matter of knowing where to look in the Admin panel. Once you navigate to your data stream, you'll have instant access to both the Measurement ID for integrations and the full gtag.js snippet for manual installation.
Once you're collecting data, the next challenge is making sense of it. GA4's reporting interface can be complex and intimidating. Instead of spending hours trying to build custom reports, we created Graphed to do the heavy lifting for you. We connect directly to your Google Analytics account, allowing you to ask questions in plain English like "Show me my top traffic sources by conversions this month" and get live dashboards and charts in seconds. It's like having a data analyst on your team, minus the weeks-long learning curve of traditional BI tools.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.