How to Get Google Analytics Script
Looking for your Google Analytics tracking script? You're in the right place. This article will show you exactly where to find the script for the latest version, Google Analytics 4, as well as the older Universal Analytics (UA) code if you still need it. We’ll also cover the easiest ways to install it on your website.
First, Which Google Analytics Version Are You Using?
Before you hunt for the code, it’s helpful to know which version of Google Analytics you’re looking for. There are two main types:
- Google Analytics 4: This is the current standard. If you set up Analytics recently, you are using GA4. Its tracking IDs are called "Measurement IDs" and start with "G-". It uses a more modern, event-based tracking model.
- Universal Analytics (UA): This is the previous generation. Google stopped processing data for standard UA properties on July 1, 2023. Its tracking IDs start with "UA-" and look like UA-XXXXXXXX-X. While it's phased out, you might still run a site that has a legacy UA tag or need to find an old ID for reference.
For any new website setup, you should be using Google Analytics 4. We’ll start there.
Finding Your GA4 Tracking Code (The "Google Tag")
In Google Analytics 4, the JavaScript snippet is officially called the "Google tag" (or gtag.js). It's powered by a unique "Measurement ID." Finding this is a straightforward process.
Step 1: Sign in to your Google Analytics Account
Head over to analytics.google.com and log in with the Google account associated with your property.
Step 2: Navigate to the Admin Section
Look for the gear icon labeled 'Admin' in the bottom-left corner of your screen. Click on it to go to the settings area.
Step 3: Select the Right Account and Property
The Admin page is divided into two columns: 'Account' and 'Property'. If you manage several websites, make sure you have the correct account and GA4 property selected from the dropdown menus at the top of these columns. GA4 properties are not labeled with a "UA-" prefix.
Step 4: Go to 'Data Streams'
In the 'Property' column, find and click on 'Data Streams'. This is where you manage the sources of data flowing into your GA4 property, like your website or mobile app.
Step 5: Select Your Web Data Stream
You'll see a list of your data streams. For a website, you should have at least one stream, usually named after your website's URL. Click on your web stream to open its details.
Step 6: Find Your Measurement ID and Script
You've arrived! In the top-right corner, you’ll see the Measurement ID, which starts with "G-". For many plugins and CMS integrations (like WordPress or Shopify), this ID is all you'll need.
To get the full script, look for the 'Google tag' section and click 'View tag instructions'. A new screen will open with an 'Install with a website builder or CMS' tab selected. Click the next tab, 'Install manually'.
Here it is. This is the full global site tag snippet that you need to add to your website. It should look something like this:
<!-- Google tag -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [],
function gtag(){dataLayer.push(arguments),}
gtag('js', new Date()),
gtag('config', 'G-XXXXXXX'),
</script>You can use the copy button next to the script box to grab the entire thing to your clipboard.
How to Install the Google Analytics Script on Your Website
Getting the script is half the battle, here’s how to set it up once it’s in your hands. There are three common ways to do this:
Method 1: Direct Installation to the <head> of Your Website
This method is for people who are comfortable editing the HTML of their site. You just need to place the script you copied just before the closing </head> tag on every page on your site.
For WordPress users, this might be in a file like header.php. In other website builders, it may be in a 'theme layout' file or a central header setting. Always place the script before the </head> tag to ensure it loads on all pages and tracks visitors as soon as they arrive.
Method 2: Using a Content Management System (CMS)
This is often the most popular and recommended option for users of platforms like WordPress, Joomla, or Squarespace.
- WordPress: Plugins like Google's official 'Site Kit' plugin, MonsterInsights, or Analytify make it incredibly easy to install. You install the plugin, and it will ask for your GA4 Measurement ID (starting with "G-"). That's it! The plugin handles adding the script to the right places throughout your site.
- Shopify, Weebly, or Squarespace: These platforms have built-in analytics integrations. Usually, within your online store settings or integration section, there will be an option where you can paste your GA4 Measurement ID. They automatically take care of the rest for you, no additional plugin needed.
Method 3: Using Google Tag Manager (GTM)
For those who are a little more familiar, Google Tag Manager is the best practice. Think of GTM as a central hub for your tags. You only need to add the GTM script to your site once. Then, within the GTM container, you can add and manage various tags, like your Google Analytics tag, Facebook pixel, and more, without ever touching your site’s code again. It’s a bit of a learning curve but well worth it as it is a truly flexible and powerful way to manage your tracking code.
What About Universal Analytics? (Finding Your UA Tracking ID)
Even though Universal Analytics has been deprecated, it's not uncommon to need to find an old UA ID, especially if you're maintaining an older property. Here's how to locate it:
- Step 1: Log into your Google Analytics account and navigate to the 'Admin' section.
- Step 2: In the 'Property' column, select the right Universal Analytics property. You will see a tracking ID starting with "UA-" in its name.
- Step 3: Click on 'Tracking Info' then 'Tracking Code'. A dropdown will appear. Select 'Tracking Code'.
- Step 4: You should now see your UA tracking ID at the top and the full global site tag (
analytics.js) script below. It will look something like this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r,i[r]=i[r]||
function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date(),
a=s.createElement(o),m=s.getElementsByTagName(o)[0],a.async=1,a.src=g,
m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'),
ga('create', 'UA-XXXXXXXX-X', 'auto'),
ga('send', 'pageview'),
</script>Final Thoughts
Installing and setting up the Google Analytics tracking code is crucial for understanding how your website performs, who your visitors are, and how they interact with your content. Whether you’re using the new 'G-' Measurement ID in GA4 or simply maintaining a legacy UA property, implementing the tracking code correctly ensures you get valuable insights through effective analytics processes. Although UA is now in the past, it is an opportunity to expand your analytics expertise and adapt to the path Google Analytics is moving towards.
If your data stream is flowing into Google Analytics, the benefits start to quickly accumulate. Creating customized reports and dashboards can quickly decode activities involving marketing or sales teams. To find the right visualization tools, make sure your data value is as accessible as possible with anyone working in the realm of Google Analytics or integrated sales platforms. Then, systematize the way you can ask questions like, "Show me the traffic from referring Facebook, or predict my revenue," and these tools provide the foundation of conducting insights necessary to turn your analytics into actionable intelligence.
You can try tools like Graphed to streamline your analytics needs and integrate them seamlessly into your workflow.
Related Articles
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.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.